Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Timestamp is missing milliseconds in tickByTickAllLast
I am trying to request real-time tick by tick data, but data arrives with timestamp missing milliseconds. Here is my code:
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.ticktype import TickTypeEnum
import time
from datetime import datetime
import threading
?
?
class TestApp(EWrapper, EClient):
? ? def __init__(self):
? ? ? ? EClient.__init__(self, self)
? ? ? ? self.last_price_list = []
?
? ? def error(self, reqId, errorCode, errorString):
? ? ? ? print("Error: ", reqId, " ", errorCode, " ", errorString)
?
? ? def tickByTickAllLast(self, reqId, tickType, time, price, size, tickAtrribLast, exchange, specialConditions):
? ? ? ? print("Tick Price. Ticker Id:", reqId, "tickType:", TickTypeEnum.to_str(tickType),?
? ? ? ? ? ? ? "Price:", price, "\n",
? ? ? ? ? ? ? "market_time_unix:", time, "\n",
? ? ? ? ? ? ? "market_time:", datetime.fromtimestamp(time).strftime("%Y-%m-%d %H:%M:%S.%f'"), "\n",
? ? ? ? ? ? ? "serve_time :", datetime.now())
? ? ? ? print("_______________________")
? ??
?
? ? app = TestApp()
?
app.connect("127.0.0.1", 4002, 0)
? ??
? ? # allow time to connect to server
time.sleep(1)
? ??
contract = Contract()
contract.symbol = "SPY"
contract.secType = "STK"
contract.exchange = "SMART"
contract.currency = "USD"
contract.primaryExchange = "ARCA"
?
#app.reqMarketDataType(4)? # switch to delayed-frozen data if live is not available
app.reqTickByTickData(1 ,contract, "Last", 0, True)
#app.reqMktData(1, contract, "", False, False, [])
?
api_thread = threading.Thread(target=app.run)
api_thread.start()
Here is output: Error:? -1? ?2104? ?Market data farm connection is OK:usfarm
Error:? -1? ?2106? ?HMDS data farm connection is OK:ushmds
Error:? -1? ?2158? ?Sec-def data farm connection is OK:secdefil
Tick Price. Ticker Id: 1 tickType: BID Price: 414.37?
?market_time_unix: 1659545243?
?market_time: 2022-08-03 16:47:23.000000'?
?server_time : 2022-08-03 16:47:23.880814
_______________________
Tick Price. Ticker Id: 1 tickType: BID Price: 414.37?
?market_time_unix: 1659545243?
?market_time: 2022-08-03 16:47:23.000000'?
?server_time : 2022-08-03 16:47:23.881391
_______________________
Tick Price. Ticker Id: 1 tickType: BID Price: 414.37?
?market_time_unix: 1659545243?
?market_time: 2022-08-03 16:47:23.000000'?
?server_time : 2022-08-03 16:47:23.881610
Is there way to get milliseconds/microseconds? |
Re: No historical market data for AAL/STK@VALUE Last 1d
You caught yourself a good one here, David. I am sure our environments are different enough that we get (at least) slightly different results. I am running tests in a paper account, TWS 10.16.1n and a pretty odd Java API 9.85.02 (that is version 161). In that context, requesting historical data for AAL/STK/SMART/NASDAQ works as expected and without any issues. BUT ... Before requesting historical data, our down-loader grabs the head timestamp as described in . And that throws an error similar to what you get. The interesting part is that the error tracks with the value I use for the "exchange" field in the contract: Error when exchange="SMART" 19:43:51:211 <- 87-10000002-139673266-AAL-STK--0.0---SMART-NASDAQ-USD-AAL-NMS-0-1-TRADES-2- No error when "exchange" is one of the legitimate real exchanges for AAL, here for example "NYSE": 19:56:05:306 <- 87-10000002-139673266-AAL-STK--0.0---NYSE-NASDAQ-USD-AAL-NMS-0-1-TRADES-2- Maybe you can try to grab historical data for NYSE/NASDAQ yourself (instead of SMART/NASDAQ). If that works it would probably be something you want to raise with IBKR support. ´³¨¹°ù²µ±ð²Ô On Tue, Aug 2, 2022 at 05:42 PM, David Walker wrote:
|
Re: No historical market data for AAL/STK@VALUE Last 1d
¿ªÔÆÌåÓýHi ´³¨¹°ù²µ±ð²Ô, ? Thanks I had a similar thought, but I traced the contract into the IB client class function and it is definitely submitting the AAL NASDAQ contract.? Here is the contract object as it is inside the reqHistoricalData function in the client class: ? {'comboLegs': None, 'comboLegsDescrip': '', 'conId': 139673266, 'currency': 'USD', 'deltaNeutralContract': None, 'exchange': 'SMART', 'includeExpired': False, 'lastTradeDateOrContractMonth': '', 'localSymbol': 'AAL', 'multiplier': '', 'primaryExchange': 'NASDAQ', 'right': '', 'secId': '', 'secIdType': '', 'secType': 'STK', 'strike': 0.0, 'symbol': 'AAL', 'tradingClass': 'NMS'} ? The conId matches the correct NASDAQ AAL conId on IB¡¯s website.? The conId of the VALUE hosted instrument is 285940697, so it¡¯s hard to see the crossover happening on IB¡¯s side. ? In response to the request with the contract above, the same error is produced: ¡°162 Historical Market Data Service error message:No historical market data for AAL/STK@VALUE Last 1d¡± ? Could you to make an identical request with the exact contract above and see if you receive the same error?? ? Dave ? ? ? From: [email protected] <[email protected]> On Behalf Of ´³¨¹°ù²µ±ð²Ô Reinold via groups.io
Sent: Tuesday, 2 August 2022 4:35 PM To: [email protected] Subject: Re: [TWS API] No historical market data for AAL/STK@VALUE Last 1d ? When you say "I'm retrieving the contract object fresh" are you talking about reqContractDetails? If so, how many contracts does the request return? When I ask for AAL:STOCK (no other fields initialized in the query contract) I get 31 contracts for three instruments:
Only that last contract for "AVIAAM LEASING AB" trades on the VALUE exchange. Any chance wires might get crossed and the historical data request sees that contract? Attached a quick CSV with the contracts I get. ´³¨¹°ù²µ±ð²Ô On Tue, Aug 2, 2022 at 12:02 AM, David Walker wrote:
|
Re: About commissionReport.realizedPNL
¿ªÔÆÌåÓýI think it¡¯s just as simple as monitoring position changes, and then using the reported realizedPNL for that position change directly. It gets reported to you, no need to calculate.?Rgds, Bart
On Aug 2, 2022, at 6:50 AM, david03kimo via groups.io <david03kimo@...> wrote:
|
Re: reqPositionsMulti does not work as intended
The has a field called
toggle quoted message
Show quoted text
that you can use as you wish. The string you set is also carried over to objects´³¨¹°ù²µ±ð²Ô On Tue, Aug 2, 2022 at 09:59 AM, Dojo321 wrote: So, this pertains to specific model portfolios that were set up in advisor accounts in seems?? |
Re: reqPositionsMulti does not work as intended
So, this pertains to specific model portfolios that were set up in advisor accounts in seems??
How do you then keep positions apart for specific strategies? Does this all have to be handled on the user side? I have written an OMS, would I need to keep my positions apart myself inside the OMS? I was hoping to be able to distinguish positions that pertain to specific strategies similar to orders/fills. I am not looking to create hedge accounts but for example, I often trade baskets that are made up of individual assets and at the same time trade individual assets that make up some of the baskets yet I want to see positions and position pnl in a segregated fashion for the baskets and the individual assets. I can easily manage it on my end but it is harder to synchronize and reconcile with broker positions if I am unable to obtain the average prices of positions that represent a slice of the entire net position in my IB account...? |
Re: reqPositionsMulti does not work as intended
Fair enough if that was the case but then what is modelCode good for? I don't seem to be able to make use of it. Orders can be supplied with a model code and that modelCode can be entered into reqPositionsMulti. I don't see the benefit of that if it does not work...?
|
Re: reqPositionsMulti does not work as intended
Dojo321 wrote: ".. net position in TWS would be 0 but when I request positions I want to see two positions, .. "
This is not possible with an IB account. Your IB account is a netting account, meaning that only the net result of all trading activities in a ticker symbol is available as position size. IB does not provide a so-called "hedging account", which is what you would need for your purpose. |
Re: Suggestions on how to deal with blocking pop up from TWS (like last week)
Great question. I didn't get a popup at all. But all orders stopped. And I had to a web interface to actually see to popup and agree.? |
Re: Best method for getting level 2 market depth snapshots on a large number of equities
Thanks for the response Jurgen, really appreciate it. Everything you said about the cancellation requests makes sense to me.
On average, I find I'm able to get about 1 per second if I limit myself to one stream maximum. With a two stream maximum I can get somewhere between 1.5 and 1.8 per second. With a three stream maximum I was getting a bit over 2 per second, but that's my maximum number of streams alas. This is all trading on my own account, so unfortunately I'm a wee bit short of the account values needed to get awarded bonus streams :-)??? and I'm not currently paying for any booster packs. Cheers, Colin On Tue, 2 Aug 2022 at 17:34, ´³¨¹°ù²µ±ð²Ô Reinold via <TwsApiOnGroupsIo=[email protected]> wrote:
|
Re: About commissionReport.realizedPNL
?The various options for PNL feeds are described in ´³¨¹°ù²µ±ð²Ô On Tue, Aug 2, 2022 at 02:17 AM, <david03kimo@...> wrote:Thanks,I think your quick example is exact what I want. |
Re: Best method for getting level 2 market depth snapshots on a large number of equities
I would have used the same approach and cannot see a way to do it differently. How long does it take to grab a snapshot for 30 instruments? When you are done with a snapshot it will take a while for your request to be finalized. TWS sees it right away, but I am sure they won't add the feed back to the "available" pool until TWS receives a cancellation confirmation from the IBKR back-end. So I am not surprised that the next might get denied until TWS has received a cancellation confirmation from IBKR. Unfortunately, has no callback that indicates to you when it is safe to make the next request. This could potentially be an ongoing area of instability. The hard limit for the number of simultaneous Level 2 streams must have been increased, since now says you can have up to 60. But you can only get 10 of them by purchasing booster packs. To get to 60 you must have enough equity or commission to "earn" them. According to the fine print in
If my math is correct, $48,000 in monthly commission or an account value of $60Mio gets you to the 6,000 market line allocations you'd need for 60 simultaneous market depth feeds. Or half of that for 30 feeds :-) ´³¨¹°ù²µ±ð²Ô |
Re: No historical market data for AAL/STK@VALUE Last 1d
When you say "I'm retrieving the contract object fresh" are you talking about reqContractDetails? If so, how many contracts does the request return? When I ask for AAL:STOCK (no other fields initialized in the query contract) I get 31 contracts for three instruments:
Only that last contract for "AVIAAM LEASING AB" trades on the VALUE exchange. Any chance wires might get crossed and the historical data request sees that contract? Attached a quick CSV with the contracts I get. ´³¨¹°ù²µ±ð²Ô On Tue, Aug 2, 2022 at 12:02 AM, David Walker wrote:Hi Everyone, |