Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Re: execId format documentation
Yes it does have a well defined structure, and it look pretty stable and guess-able in part, |
Re: Impossible to reconnect after TWS restart, please help!
Also read and consider method #2 with a |
Re: Retrieving status of a specific orderID through orderStatus or openOrder
How did you set profit_order_ID? ?
So I can only speculate that what happen is that orderStatus call back never came with the value orderId that you did set in? profit_order_ID , and this could be pretty normal in many regards, like you never set properly the global profit_order_ID? or that your profit leg is not triggered for various reasons. be careful with globals, I can only speculate also on reason you use it, but this design pattern is typically unsafe if you manage more than one order at time. |
Re: E-MINI reqTickByTick data parameters
¿ªÔÆÌåÓýlocalSymbol should be ¡°ESZ3¡±. What you¡¯ve got, ¡°ESZ2¡±, is for December 2022. ? ? From: [email protected] <[email protected]> On Behalf Of fran
Sent: Monday, November 20, 2023 8:51 PM To: [email protected] Subject: [TWS API] E-MINI reqTickByTick data parameters ? Hi everyone, I am having trouble getting the E-MINI ticker tick-by-tick data (specifically E-mini S&P 500; ESdec15'23(50) CME). I am trying to run this line of code:
|
Re: Impossible to reconnect after TWS restart, please help!
WOW! You sir are a true detective.?
Yes, you are correct in saying that it has never worked, I have been working on this for the past 2 months or maybe even more and now I am stuck on this issue, and I mean stuck because I am ready to deploy my strategy but the fact that TWS needs to restart every 24 hours has me dealing with this issue therefore I feel I cannot move forward.? I say I have been working on this for 2 months but in reality I have been doing this since the beginning of this year, I don't know if you are familiar with Harvard's CS50p course, it a python programing course I took with the sole intention of making a trading algorithm and I'm almost there, so when I say please help! I really mean it lol :)? Could you point me in the right direction of how I could "manually stop" the thread when TWS restarts or looses connection ? I would be happy to share with you any code you need. Right now what is happening is that when I manually restart TWS error message 502 arrives, the program calls for: self.conn.disconnect() and self.stopdatas() and the it attempts to proceed to reconnect() and that is where it gets stuck forever and ever.? What code could I add or what could I do in order to kill and refresh the Ereader thread as you mention ? ? ? def disconnect(self):
? ? ? ? self.lock.acquire()
? ? ? ? try:
? ? ? ? ? ? if self.socket is not None:
? ? ? ? ? ? ? ? logger.debug("disconnecting")
? ? ? ? ? ? ? ? self.socket.close()
? ? ? ? ? ? ? ? self.socket = None
? ? ? ? ? ? ? ? logger.debug("disconnected")
? ? ? ? ? ? ? ? if self.wrapper:
? ? ? ? ? ? ? ? ? ? self.wrapper.connectionClosed()
? ? ? ? finally:
? ? ? ? ? ? self.lock.release()
? ? def stopdatas(self):
? ? ? ? # stop subs and force datas out of the loop (in LIFO order)
? ? ? ? logger.debug(f"Stopping datas")
? ? ? ? qs = list(self.qs.values())
? ? ? ? ts = list()
? ? ? ? for data in self.datas:
? ? ? ? ? ? t = threading.Thread(target=data.canceldata)
? ? ? ? ? ? t.start()
? ? ? ? ? ? ts.append(t)
? ? ? ? for t in ts:
? ? ? ? ? ? t.join()
? ? ? ? for q in reversed(qs): ?# datamaster the last one to get a None
? ? ? ? ? ? q.put(None)
?def reconnect(self, fromstart=False, resub=False):
? ? ? ? # This method must be an invariant in that it can be called several
? ? ? ? # times from the same source and must be consistent. An exampler would
? ? ? ? # be 5 datas which are being received simultaneously and all request a
? ? ? ? # reconnect
? ? ? ? # Policy:
? ? ? ? # ?- if dontreconnect has been set, no option to connect is possible
? ? ? ? # ?- check connection and use the absence of isConnected as signal of
? ? ? ? # ? ?first ever connection (add 1 to retries too)
? ? ? ? # ?- Calculate the retries (forever or not)
? ? ? ? # ?- Try to connct
? ? ? ? # ?- If achieved and fromstart is false, the datas will be
? ? ? ? # ? ?re-kickstarted to recreate the subscription
? ? ? ? firstconnect = False
? ? ? ? try:
? ? ? ? ? ? if self.conn.isConnected():
? ? ? ? ? ? ? ? print("\nibstore.py - Linea: 818")
? ? ? ? ? ? ? ? if resub:
? ? ? ? ? ? ? ? ? ? self.startdatas()
? ? ? ? ? ? ? ? return True ?# nothing to do
? ? ? ? except AttributeError:
? ? ? ? ? ? # Not connected, several __getattr__ indirections to
? ? ? ? ? ? # self.conn.sender.client.isConnected
? ? ? ? ? ? firstconnect = True
? ? ? ? if self.dontreconnect:
? ? ? ? ? ? return False
? ? ? ? # This is only invoked from the main thread by datas and therefore no
? ? ? ? # lock is needed to control synchronicity to it
? ? ? ? retries = self.p.reconnect
? ? ? ? if retries >= 0:
? ? ? ? ? ? retries += firstconnect
? ? ? ? while retries < 0 or retries:
? ? ? ? ? ? logger.debug(f"Retries: {retries}")
? ? ? ? ? ? print("\nibstore.py - Linea: 837")
? ? ? ? ? ? if not firstconnect:
? ? ? ? ? ? ? ? logger.debug(f"Reconnect in {self.p.timeout} secs")
? ? ? ? ? ? ? ? time.sleep(self.p.timeout)
? ? ? ? ? ? firstconnect = False
? ? ? ? ? ? try:
? ? ? ? ? ? ? ? logger.debug(f"Connect (host={self.p.host}, port={self.p.port}, clientId={self.clientId})")
? ? ? ? ? ? ? ? print("\nibstore.py - Linea: 847")
? ? ? ? ? ? ? ? if self.conn.connect(self.p.host, self.p.port, self.clientId):
? ? ? ? ? ? ? ? ? ? if not fromstart or resub:
? ? ? ? ? ? ? ? ? ? ? ? print("\nibstore.py - Linea: 850")
? ? ? ? ? ? ? ? ? ? ? ? self.startdatas()
? ? ? ? ? ? ? ? ? ? return True ?# connection successful
? ? ? ? ? ? except Exception as e:
? ? ? ? ? ? ? ? print("\nibstore.py - Linea: 850")
? ? ? ? ? ? ? ? logger.exception(f"Failed to Connect {e}")
? ? ? ? ? ? ? ? return False
? ? ? ? ? ? if retries > 0:
? ? ? ? ? ? ? ? retries -= 1
? ? ? ? self.dontreconnect = True
? ? ? ? return False ?# connection/reconnection failed
|
E-MINI reqTickByTick data parameters
fran
Hi everyone, I am having trouble getting the E-MINI ticker tick-by-tick data (specifically E-mini S&P 500; ESdec15'23(50) CME). I am trying to run this line of code:
Where the contract is described like this in another file: Contract ContractSamples::EMINI(){ ??? Contract contract; ?? ?contract.symbol = "ES"; ?? ?contract.secType = "FUT"; ?? ?contract.exchange = "CME"; ?? ?contract.currency = "USD"; ??? contract.localSymbol = "ESZ2"; ?? ?contract.lastTradeDateOrContractMonth = "202315"; ?? ?return contract; } I keep getting an error related to a non-existing ticker. I would appreciate any help/insight to solve this. |
Retrieving status of a specific orderID through orderStatus or openOrder
Hi Everyone,?
I would like to extract information about the status of an order for which the order ID is known and use that information (for example to export to a .csv file).? I have included orderStatus in my wrapper and added some lines to print out information when the order status changes.? The first lines (order ID',orderId,' has been filled at price ', lastFillPrice ,'.') correctly trigger when my buy order is filled.? But the second set of lines ('PRINTING OUT THE AT PROFIT ORDER ID') do not trigger, even though orderStatus has printed the updated information to screen and profit_order_ID is known.? Why is the second set of lines not triggering?? Below is my code snippet.? Thanks!? ? ?? ? ? def orderStatus(self, orderId, status, filled, remaining, avgFullPrice, permId, parentId, lastFillPrice, clientId, whyHeld, mktCapPrice): ? ? ? ? print('orderStatus - orderid:', orderId, 'status:', status, 'filled', filled, 'remaining', remaining, 'lastFillPrice', lastFillPrice) ? ? ? ? global current_fill_price ? ? ? ? global current_orderID ? ? ? ? global current_fill_status ? ? ? ? if status == 'Filled': ? ? ? ? ? ? print('order ID',orderId,' has been filled at price ', lastFillPrice ,'.') ? ? ? ? ? ? current_fill_status = 'Filled' ? ? ? ? ? ? current_fill_price = lastFillPrice ? ? ? ? ? ? current_orderID = orderId ? ? ? ? ? global profit_order_ID ? ? ? ? if orderId == profit_order_ID: ? ? ? ? ? ? print('PRINTING OUT THE AT PROFIT ORDER ID') |
Re: Concept of Data Lines
¿ªÔÆÌåÓýWith reqMktData you get updates a few times per second (more frequent for Forex than stocks and futures). What is sent to you is only what has changed since the last update. So the data rate is strictly limited. If there are actually 100 separate trades in a single second, you¡¯ll still only get a handful reported to you. That helps IB because it means the maximum amount of bandwidth they need to provide timely data to their thousands of customers is relatively predictable and constant. But of course the downside is that the customers don¡¯t get anything like every tick. ? For reqTickByTick data you (in theory at least) get every top of book quote and every trade, which can be dozens of time higher in busy periods. These make it far more difficult for IB to predict the needed bandwidth. If every client could use any number of reqTickByTick¡¯s concurrently, they¡¯d need to make much larger provisions of bandwidth and compute, with greatly increased costs to them (and thus to us). ? Restricting reqTickByTick to a small number per customer means they can keep things under control, since the bandwidth used for that is probably a smallish fraction of the total. ? Richard ? |
Re: Concept of Data Lines
Limitations?¨C Additional symbol request can be purchased through a quote booster pack, each quote booster pack provides a 100 market data lines. There is a limit of 10 quote booster packs per account and rest of the market data lines are allocated using equity and commissions.Yes, I got that, just not sure I understand the logic. Both reqMktData and reqTickByTickData are top of the book quotes, why exactly one is 100 times more 'expensive' than the other remains a mystery for me. As Gordon mentioned, 250ms is the potential difference in time. |
Re: Concept of Data Lines
According to [url=https://ibkrcampus.com/ibkr-quant-news/ibkr-market-data-from-real-time-bars-to-ticks/]this page[/url],
Limitations ¨C Additional symbol request can be purchased through a quote booster pack, each quote booster pack provides a 100 market data lines. There is a limit of 10 quote booster packs per account and rest of the market data lines are allocated using equity and commissions. [img]https://ibkrcampus.com/wp-content/uploads/2022/08/image-89.png[/img] |
Re: Concept of Data Lines
I can only share my understanding, not sure it is accurate, they are murky about that. |
Concept of Data Lines
Hello:
I have trouble grasping the concept of data lines as defined by IB. With my current data subscriptions, I never experience any limitations using reqMktData, but when using reqTickByTickData I have pretty random results, for example for a few days I have had a limit of six concurrent requests, anything over raising an error, then it became five for no apparent reason, now it's four. I can't see any logical connection to my testing environment as nothing really changed in between trials. Can anyone enlighten me on how does it really work? |
Re: Impossible to reconnect after TWS restart, please help!
I assume that you are not completely locked up, you are not in life/death situation hence the "please helps" is not for an emergency, right ? What I understand (please precise it) is that you want to automatically reconnect to a restarted TWS WITHOUT stopping your code. right ? |
Impossible to reconnect after TWS restart, please help!
I have been trying to solve this issue for the past week and still have not been able to.
The problem is that when TWS restarts I get error message 502 so I proceed to disconnect() then stopdatas() then reconnect() but I get stuck I believe its something to do with the socket timeout error, here is my debug file: 2023-11-17 12:58:24.791 - DEBUG ? - MainThread - client.py:140 [connect] - Connecting to 127.0.0.1:7497 w/ id:51
2023-11-17 12:58:24.791 - DEBUG ? - MainThread - client.py:73 [setConnState] - 2136017324432 connState: 2 -> 1
2023-11-17 12:58:24.791 - DEBUG ? - MainThread - client.py:157 [connect] - msg b'\x00\x00\x00\tv100..176'
2023-11-17 12:58:24.791 - DEBUG ? - MainThread - client.py:159 [connect] - REQUEST b'API\x00\x00\x00\x00\tv100..176'
2023-11-17 12:58:24.791 - DEBUG ? - MainThread - connection.py:69 [sendMsg] - acquiring lock
2023-11-17 12:58:24.791 - DEBUG ? - MainThread - connection.py:71 [sendMsg] - acquired lock
2023-11-17 12:58:24.791 - DEBUG ? - MainThread - connection.py:82 [sendMsg] - releasing lock
2023-11-17 12:58:24.791 - DEBUG ? - MainThread - connection.py:84 [sendMsg] - release lock
2023-11-17 12:58:24.791 - DEBUG ? - MainThread - connection.py:86 [sendMsg] - sendMsg: sent: 17
2023-11-17 12:58:24.792 - DEBUG ? - MainThread - decoder.py:1370 [interpret] - no fields
2023-11-17 12:58:24.794 - DEBUG ? - MainThread - connection.py:122 [_recvAllMsg] - len 30 raw:b'\x00\x00\x00\x1a176\x0020231117 12:58:23 MST\x00'|
2023-11-17 12:58:24.794 - DEBUG ? - MainThread - client.py:175 [connect] - ANSWER b'\x00\x00\x00\x1a176\x0020231117 12:58:23 MST\x00'
2023-11-17 12:58:24.794 - DEBUG ? - MainThread - comm.py:67 [read_msg] - read_msg: size: 26
2023-11-17 12:58:24.794 - DEBUG ? - MainThread - client.py:178 [connect] - size:26 msg:b'176\x0020231117 12:58:23 MST\x00' rest:b''|
2023-11-17 12:58:24.794 - DEBUG ? - MainThread - client.py:180 [connect] - fields (b'176', b'20231117 12:58:23 MST')
2023-11-17 12:58:24.794 - DEBUG ? - MainThread - client.py:186 [connect] - ANSWER Version:176 time:b'20231117 12:58:23 MST'
2023-11-17 12:58:24.794 - DEBUG ? - MainThread - client.py:73 [setConnState] - 2136017324432 connState: 1 -> 2
2023-11-17 12:58:24.794 - DEBUG ? - Thread-16 - reader.py:31 [run] - EReader thread started
2023-11-17 12:58:24.794 - INFO ? ?- MainThread - client.py:195 [connect] - sent startApi
2023-11-17 12:58:24.795 - INFO ? ?- MainThread - client.py:89 [logRequest] - REQUEST startApi {}
2023-11-17 12:58:24.795 - DEBUG ? - MainThread - client.py:222 [isConnected] - 2136017324432 isConn: 2, connConnected: True
2023-11-17 12:58:24.795 - INFO ? ?- MainThread - client.py:78 [sendMsg] - SENDING startApi b'\x00\x00\x00\t71\x002\x0051\x00\x00'
2023-11-17 12:58:24.795 - DEBUG ? - MainThread - connection.py:69 [sendMsg] - acquiring lock
2023-11-17 12:58:24.795 - DEBUG ? - MainThread - connection.py:71 [sendMsg] - acquired lock
2023-11-17 12:58:24.795 - DEBUG ? - MainThread - connection.py:82 [sendMsg] - releasing lock
2023-11-17 12:58:24.795 - DEBUG ? - MainThread - connection.py:84 [sendMsg] - release lock
2023-11-17 12:58:24.795 - DEBUG ? - MainThread - connection.py:86 [sendMsg] - sendMsg: sent: 13
2023-11-17 12:58:25.295 - DEBUG ? - Thread-16 - connection.py:122 [_recvAllMsg] - len 0 raw:b''|
2023-11-17 12:58:25.295 - DEBUG ? - Thread-16 - connection.py:99 [recvMsg] - socket either closed or broken, disconnecting
2023-11-17 12:58:25.295 - DEBUG ? - Thread-16 - connection.py:56 [disconnect] - disconnecting
2023-11-17 12:58:25.295 - DEBUG ? - Thread-16 - connection.py:59 [disconnect] - disconnected
2023-11-17 12:58:25.295 - DEBUG ? - Thread-16 - reader.py:36 [run] - reader loop, recvd size 0
2023-11-17 12:58:25.295 - DEBUG ? - Thread-16 - reader.py:51 [run] - EReader thread finished
2023-11-17 12:58:25.348 - DEBUG ? - Thread-7 - connection.py:102 [recvMsg] - socket timeout from recvMsg (<class 'TimeoutError'>, TimeoutError('timed out'), <traceback object at 0x000001F154A223C0>)
2023-11-17 12:58:25.348 - DEBUG ? - Thread-7 - reader.py:36 [run] - reader loop, recvd size 0
2023-11-17 12:58:26.357 - DEBUG ? - Thread-7 - connection.py:102 [recvMsg] - socket timeout from recvMsg (<class 'TimeoutError'>, TimeoutError('timed out'), <traceback object at 0x000001F154A239C0>)
2023-11-17 12:58:26.357 - DEBUG ? - Thread-7 - reader.py:36 [run] - reader loop, recvd size 0
2023-11-17 12:58:27.361 - DEBUG ? - Thread-7 - connection.py:102 [recvMsg] - socket timeout from recvMsg (<class 'TimeoutError'>, TimeoutError('timed out'), <traceback object at 0x000001F154A21200>)
2023-11-17 12:58:27.361 - DEBUG ? - Thread-7 - reader.py:36 [run] - reader loop, recvd size 0
2023-11-17 12:58:28.367 - DEBUG ? - Thread-7 - connection.py:102 [recvMsg] - socket timeout from recvMsg (<class 'TimeoutError'>, TimeoutError('timed out'), <traceback object at 0x000001F154A223C0>)
2023-11-17 12:58:28.367 - DEBUG ? - Thread-7 - reader.py:36 [run] - reader loop, recvd size 0
|
Re: C++ ReqHistoricalData() Request to Response Time Data
Maybe that will help. On Fri, Nov 17, 2023 at 10:57?AM Brendan Lydon <blydon12@...> wrote: Nevermind. I assume its m_pClient->cancelHistoricalData(reqId)... I really have to rethink what qualifies as a question on here. |