Last active
March 5, 2023 11:10
-
-
Save ranaroussi/d28f20cedfe01109d10863e11b52eec0 to your computer and use it in GitHub Desktop.
order EUR.USD using ezIBpy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: UTF-8 -*- | |
import ezibpy | |
import time | |
# initialize ezIBpy | |
ibConn = ezibpy.ezIBpy() | |
ibConn.connect(clientId=1234, host="localhost", port=7497) | |
# subscribe to position and account changes | |
ibConn.requestPositionUpdates(subscribe=True) | |
ibConn.requestAccountUpdates(subscribe=True) | |
# create EUR.USD contract | |
contract = ibConn.createCashContract("EUR", currency="USD") | |
# you can also use the generic method | |
# contract = ibConn.createContract( ("EUR", "CASH", "IDEALPRO", "USD", "", 0.0, "") ) | |
# create an order | |
order = ibConn.createOrder(quantity=100) | |
# submit an order (returns order id) | |
orderId = ibConn.placeOrder(contract, order) | |
# let order fill | |
time.sleep(1) | |
# see the positions | |
print("Positions") | |
print(ibConn.positions) | |
# disconnect | |
ibConn.disconnect() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment