Skip to content

Instantly share code, notes, and snippets.

@ranaroussi
Last active March 5, 2023 11:10
Show Gist options
  • Save ranaroussi/d28f20cedfe01109d10863e11b52eec0 to your computer and use it in GitHub Desktop.
Save ranaroussi/d28f20cedfe01109d10863e11b52eec0 to your computer and use it in GitHub Desktop.
order EUR.USD using ezIBpy
#!/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