Category : ib-api

While using the interactive brokers api python library, I try to return a dict object from specific functions in my program that supported by the ibapi module itself. from ibapi.client import EClient from ibapi.wrapper import EWrapper from ibapi.contract import Contract from ibapi.ticktype import TickTypeEnum from threading import Timer from threading import * import csv import ..

Read more

from ib_insync import Order, IB, util, Forex from datetime import timedelta, datetime my_ib = IB() my_ib.connect(‘127.0.0.1’, 7497, clientId=3) contract = Forex(‘EURUSD’) my_ib.qualifyContracts(contract) def my_order(): o = Order() o.orderId = my_ib.client.getReqId() o.action = ‘BUY’ o.orderType = "MKT" o.tif = ‘GTC’ o.totalQuantity = 50 dt = datetime.now() + timedelta(hours = 1) # some time in the future ..

Read more

Just starting to learn a bit of python as I would like to automate some part of my stock trading on IB TWS. Below is a code I have written in PyCharm (mainly by copying and modifying snippets of codes I have found here and there. I am not that proficient in Python, especially with ..

Read more

from ibapi.client import EClient from ibapi.wrapper import EWrapper from ibapi.contract import Contract from ibapi.order import * import threading import time class IBapi(EWrapper, EClient): def __init__(self): EClient.__init__(self, self) def openOrder(self, orderId, contract, order, orderState): print(‘openOrder id:’, orderId, contract.symbol, contract.secType, ‘@’, contract.exchange, ‘:’, order.action, order.orderType, order.totalQuantity, orderState.status) def run_loop(): app.run() app = IBapi() app.connect(‘127.0.0.1’, 7497, 123) # ..

Read more

I have a basic script for the IB API. It runs in a thread and handles the tickPrice callback. This runs and generates the expected messages in the terminal. Connected serverVersion:151 connectionTime:b’20210707 22:28:33 EST’ ERROR -1 2104 Market data farm connection is OK:usfarm.nj ERROR -1 2104 Market data farm connection is OK:cashfarm ERROR -1 2104 ..

Read more