¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io
Date

Re: Market depth data has been RESET. Error Code: 317, C++ Program

 

What do you mean by "I purge my bank, and de-facto expect to only receive types 2, or 1 only after I received a first set of new insert (0)." Mainly, "purge my bank", because I think me "flushing" the contents on my order book isn't doing what I think it is doing. Because I am actually only flushing the contents in my stored local order book. I am processing messages every time I call reqMktDepth() though, so I am not sure how my bank could be full, if those are the same thing...


Re: Sim Account Platform Acting Up

 

I am speaking on TWS, and I am simultaneously watching the L2 windows in my paper account. The charts too are not very accurate. The current candle in my chart will take a weird shape that doesn't reflect what data is showing in the L2. The charts will then show price action I am not seeing in the L2 and then a reset occurs and everything seemingly is back up to date and the market, i.e. level 2, will move drastically as it wasn't streaming accurate data. I think the Market Depth Reset Error Code: 317 may be causing this somehow. Maybe b/c my order book needs flushing or resetting the level 2 windows cannot get new data and in the mean time they just stream old data? Because prices still move, but data seen in my candlesticks differ greatly from that in the level 2. A theory...


Re: Duplicate OrderID

 

Yes I know but this repeated order number won't collide with the already executed order because?it's gone


El s¨¢b, 2 dic 2023 a las 8:19, J G via (<windmill_1965=[email protected]>) escribi¨®:
joanmarcel119 wrote: "If the number of the order (still open) is greater than the nextvalidId number I got at the beginning then I update it. This way the next increment is a number which won't collide with another order on the system. " I don't think that this is a foolproof solution. You only check for the highest order ID for the currently open orders. But you neglect to check for the order IDs for the orders that have already filled. It could be that an order (having order ID 120) you placed yesterday is still open, while a next order (e.g. order ID 123), placed today, has already filled.


Re: Duplicate OrderID

 

joanmarcel119 wrote: "If the number of the order (still open) is greater than the nextvalidId number I got at the beginning then I update it. This way the next increment is a number which won't collide with another order on the system. " I don't think that this is a foolproof solution. You only check for the highest order ID for the currently open orders. But you neglect to check for the order IDs for the orders that have already filled. It could be that an order (having order ID 120) you placed yesterday is still open, while a next order (e.g. order ID 123), placed today, has already filled.


Re: Sim Account Platform Acting Up

 

I have noticed very strange behavior recently. I've only been using the paper trading accounts. Specifically, on certain FX pairs, e.g. EURUSD, USDJPY, USDCAD, the balance may not be updated for up to 5 minutes after an order fills. This started last week.

Also, I have noticed that I have to cycle through the various accounts (I have FA accounts) to "force" TWS to update its positions. If I don't do this periodically, the positions page stops updating.

I'm using 10.19.


Re: Sim Account Platform Acting Up

 

Not sure I catch what you seems to imply by differentiating Paper vs Real. I don't think that Paper is less well serving LII than Real.

Some thoughts:
What do you call platform ? TWS or Gateway ?
Are you looking at LII on TWS simultaneously ?
Aside of telco contention:If TWS consider increasing the amount of RAM allocated to TWS

Suggestion too look at the "halt" status, I never seen it moving fast in real time, but it may happens that the market itself is in a stall position.
I also would wonder what is the impact of using Smart mode versus specific venue like the primary exchange or a major one.
If one venue stall maybe it stall the IB deliver process. (unlikely in my deep perception as IB should deliver RT what they have available)

Otherwise said, what you call a halt for split second need to be considered against another reference, like a Bloomberg terminal or that class of platform
Because there are real reason why market may freeze waiting for something that trigger a big move (as in: cause or consequence ?)


Re: Multiple users Read only access

 

Nothing easy popup to my mind.
50 is quit a number of users and you most probably will face a wall with the pacing violation and limitations if you use a single account
There is a concept of ClienId that allow to a certain extent to track what a proxy you have to design could do but you would have to de-consolidate a lot of trading information your self.
IB mind set is even exactly in the opposite direction, allowing a single trader to handle in single action a consolidation of accounts (customer).

So I would suggest you call IBKR direct, IBKR have cost of operation for their advanced service and here this is to deal with users that are not paying for the service in a foreseeable future.
So supporting many user for free is not really rational and they probably never considered this schooling usage in their API, hence reason to contact them and see what they can suggest.


Re: Multiple users Read only access

 

Even if someone can point me to an api spec or high level guidance would suffice. I¡¯m fairly tech savvy?


Sim Account Platform Acting Up

 

Hi,

I have noticed that oftentimes my platform will halt for a split second and the market will suddenly move up or down by a considerable amount. It is as if the level 2 data I am streaming is behind the live market data in the paper trading environment. Can anyone speak to this? This obviously has weird affects on the data I receive in my trading algorithm.

Thank you


Re: Duplicate OrderID

 

My humble solution for this problem of duplicate order Id:

First, I request all the open positions (client id = 0) and on the "openorder" callback:

? ? If orderId >= m_orderId Then
? ? ? ? m_orderId = orderId
? ? End If

If the number of the order (still open) is greater than the nextvalidId number I got at the beginning then I update it. This way the next increment is a number which won't collide with another order on the system.?


El mar, 28 nov 2023 a las 19:45, bespalex (<bespalex@...>) escribi¨®:
Jurgen, I will perform this check from now on.


Multiple users Read only access

 

I¡¯m quiet new so please bear with me!

I¡¯ve been thinking about setting a training group and observe the students trades on IBKR as read only access. Is there any api, including this which allows me to set read only access via api to multiple accounts (50+). Even if it¡¯s limited May one on of you guys lead me to the right api. Do the users need to grant the permission on their account ? How does it work. Any help is approached?


Re: Market depth data has been RESET. Error Code: 317, C++ Program

 

It has been happening quite a bit throughout the day. I would say it happened atleast 10 times today, once in the last hour of trading and several times throughout the day. Also, happened yesterday many times. I am fairly certain I am flushing very frequently so not sure how it could get so full so as to report this error.


Re: Market depth data has been RESET. Error Code: 317, C++ Program

 

Here is my call -> reqMktDepth(reqId, m_contract, 5, false, TagValueListSPtr());
I am incrementing reqId every time I request, and the contract is for NQ e-mini expiring for december, NQZ3. My algo still gets data after this happens, & I do flush the book at most every second.


Re: Target order in bracket order not being placed!

 

Fantastic! That was the issue. Now works. Thank you very much Jurgen and Gordon for you quick responses and assistance. Very grateful indeed!?


Re: Target order in bracket order not being placed!

 

I can't say for sure, but I can believe that this case would not generate an error. For TWS/IBGW this could very much look like on order change. They may not look at those two as separate orders (after all, they have the same orderId).

´³¨¹°ù²µ±ð²Ô

PS. The first line of pseudo code in my previous post should have been parentOrder.orderId = nextOrderId()


On Thu, Nov 30, 2023 at 04:20 PM, Gordon Eldest wrote:
On Thu, Nov 30, 2023 at 02:08 PM, nesbitcrab wrote:
trailstop.orderId = parent.orderId + 1
should be +2

I would expect an error message to be generated but as the "transmit" is collective maybe your takeprofit it is silently overwritten by your trailstop. I am not familiar enough with Python to go further in the analysis


Re: Target order in bracket order not being placed!

 

´³¨¹°ù²µ±ð²Ô did answer while I was also answering.
His suggestion is sounder, you should avoid "hard" assignment of order id.


Re: Target order in bracket order not being placed!

 

On Thu, Nov 30, 2023 at 02:08 PM, nesbitcrab wrote:
trailstop.orderId = parent.orderId + 1
should be +2

I would expect an error message to be generated but as the "transmit" is collective maybe your takeprofit it is silently overwritten by your trailstop. I am not familiar enough with Python to go further in the analysis


Re: Target order in bracket order not being placed!

 

Without a lot of research into your code what jumps at me is that you assign the same orderId to the profitTaker and trailStop orders. Both are set to "parent.orderId + 1'.

Using this incremental orderId assignment is a very bad idea (yes, I know even IBKR uses it in code examples - still bad idea). You should implement a small orderId manager that increments the orderId each time you call it. Something like this:

parentOrder = nextOrderId()
...
takeProfit.orderId = nextOrderId()
...
trailstop.orderId = nextOrderid()

´³¨¹°ù²µ±ð²Ô


On Thu, Nov 30, 2023 at 04:08 PM, nesbitcrab wrote:
I am at my wits end here, and have pulled out what his left of my hair trying to resolve this. The code below is basically to place two identical orders, but one with take profit and the other without. No errors are generated when I run the code, and both orders are placed (qty, stp lmt, trail etc.) but not the take profit for some reason. What am I doing wrong. Image of orders on TWS, and code below. Thank you.?

wb = xw.Book("SendOrders.xlsm")
ws1 = wb.sheets["Main"]


def BracketStopLimitOrder(parentOrderId: int, action: str, quantity: int,
limitPrice: float, stopPrice: float, takeProfitLimitPrice: float, trailingPercent: float, trailStopPrice: float):

parent = Order()
parent.orderId = parentOrderId
parent.action = action
parent.orderType = "STP LMT"
parent.totalQuantity = quantity
parent.lmtPrice = limitPrice
parent.auxPrice = stopPrice
parent.transmit = False

takeProfit = Order()
takeProfit.orderId = parent.orderId + 1
takeProfit.action = "SELL" if action == "BUY" else "BUY"
takeProfit.orderType = "LMT"
takeProfit.totalQuantity = quantity
takeProfit.lmtPrice = takeProfitLimitPrice
takeProfit.parentId = parentOrderId
takeProfit.transmit = False

# [trailingstop]
trailstop = Order()
trailstop.orderId = parent.orderId + 1
trailstop.action = "SELL" if action == "BUY" else "BUY"
trailstop.orderType = "TRAIL"
trailstop.totalQuantity = quantity
trailstop.trailingPercent = trailingPercent
trailstop.trailStopPrice = trailStopPrice
trailstop.parentId = parentOrderId
trailstop.outsideRth = True # I added this additionally
trailstop.transmit = True

bracketOrder = [parent, takeProfit, trailstop]
return bracketOrder




def BracketStopLimitOrder2(parentOrderId: int, action: str, quantity: int,
limitPrice: float, stopPrice: float, trailingPercent: float, trailStopPrice: float):

parent = Order()
parent.orderId = parentOrderId
parent.action = action
parent.orderType = "STP LMT"
parent.totalQuantity = quantity
parent.lmtPrice = limitPrice
parent.auxPrice = stopPrice
parent.transmit = False


#[trailingstop]
trailstop= Order()
trailstop.orderId = parent.orderId + 1
trailstop.action = "SELL" if action == "BUY" else "BUY"
trailstop.orderType = "TRAIL"
trailstop.totalQuantity = quantity
trailstop.trailingPercent = trailingPercent
trailstop.trailStopPrice = trailStopPrice
trailstop.parentId = parentOrderId
trailstop.outsideRth = True # I added this additionally
trailstop.transmit = True

bracketOrder = [parent, trailstop]
return bracketOrder


order_placed = ws1['J2']
ticker_symbol = ws1['B2'].value
order_qty = ws1['C2'].value
order_lmt_Prc = ws1['D2'].value
order_lmt_Prc = round(order_lmt_Prc, 2) # this was needed to prevent the error "The price does not conform to the minimum price variation for this contract"
aux_stop_prc = ws1['E2'].value
aux_stop_prc = round(aux_stop_prc, 2) # this was needed to prevent the error "The price does not conform to the minimum price variation for this contract"
target_profit = ws1["H2"].value
target_profit = round(target_profit, 2)
submit_it = ws1['I2'].value
trailing_percent = ws1["F2"].value
trailing_percent = round(trailing_percent, 2)
trailstpprc = ws1["G2"].value
trailStpprc = round(trailstpprc, 2)



# note for above code. for 'round' not to return error, values in corresponding excel cells cannot be blank

if submit_it == 1:
# create contract
ticker_contract = Stock(ticker_symbol, 'SMART', 'USD')
ib.qualifyContracts(ticker_contract)
# create bracket order

bracket = BracketStopLimitOrder(ib.client.getReqId(), action='BUY', quantity=order_qty, limitPrice=order_lmt_Prc,
stopPrice=aux_stop_prc, takeProfitLimitPrice=target_profit, trailingPercent=trailing_percent, trailStopPrice=trailStpprc)

# place bracket order
for ord in bracket:
ib.placeOrder(ticker_contract, ord)
ib.sleep(1)


# create contract
ticker_contract = Stock(ticker_symbol,'SMART', 'USD')
ib.qualifyContracts(ticker_contract)
# create bracket order

bracket2 = BracketStopLimitOrder2(ib.client.getReqId(), action='BUY', quantity=order_qty, limitPrice=order_lmt_Prc,
stopPrice=aux_stop_prc, trailingPercent=trailing_percent, trailStopPrice=trailStpprc)

#place bracket order
for ord in bracket2:
ib.placeOrder(ticker_contract, ord)
ib.sleep(1)



order_placed.value = "Yes"


Target order in bracket order not being placed!

 

I am at my wits end here, and have pulled out what his left of my hair trying to resolve this. The code below is basically to place two identical orders, but one with take profit and the other without. No errors are generated when I run the code, and both orders are placed (qty, stp lmt, trail etc.) but not the take profit for some reason. What am I doing wrong. Image of orders on TWS, and code below. Thank you.?


wb = xw.Book("SendOrders.xlsm")
ws1 = wb.sheets["Main"]


def BracketStopLimitOrder(parentOrderId: int, action: str, quantity: int,
limitPrice: float, stopPrice: float, takeProfitLimitPrice: float, trailingPercent: float, trailStopPrice: float):

parent = Order()
parent.orderId = parentOrderId
parent.action = action
parent.orderType = "STP LMT"
parent.totalQuantity = quantity
parent.lmtPrice = limitPrice
parent.auxPrice = stopPrice
parent.transmit = False

takeProfit = Order()
takeProfit.orderId = parent.orderId + 1
takeProfit.action = "SELL" if action == "BUY" else "BUY"
takeProfit.orderType = "LMT"
takeProfit.totalQuantity = quantity
takeProfit.lmtPrice = takeProfitLimitPrice
takeProfit.parentId = parentOrderId
takeProfit.transmit = False

# [trailingstop]
trailstop = Order()
trailstop.orderId = parent.orderId + 1
trailstop.action = "SELL" if action == "BUY" else "BUY"
trailstop.orderType = "TRAIL"
trailstop.totalQuantity = quantity
trailstop.trailingPercent = trailingPercent
trailstop.trailStopPrice = trailStopPrice
trailstop.parentId = parentOrderId
trailstop.outsideRth = True # I added this additionally
trailstop.transmit = True

bracketOrder = [parent, takeProfit, trailstop]
return bracketOrder




def BracketStopLimitOrder2(parentOrderId: int, action: str, quantity: int,
limitPrice: float, stopPrice: float, trailingPercent: float, trailStopPrice: float):

parent = Order()
parent.orderId = parentOrderId
parent.action = action
parent.orderType = "STP LMT"
parent.totalQuantity = quantity
parent.lmtPrice = limitPrice
parent.auxPrice = stopPrice
parent.transmit = False


#[trailingstop]
trailstop= Order()
trailstop.orderId = parent.orderId + 1
trailstop.action = "SELL" if action == "BUY" else "BUY"
trailstop.orderType = "TRAIL"
trailstop.totalQuantity = quantity
trailstop.trailingPercent = trailingPercent
trailstop.trailStopPrice = trailStopPrice
trailstop.parentId = parentOrderId
trailstop.outsideRth = True # I added this additionally
trailstop.transmit = True

bracketOrder = [parent, trailstop]
return bracketOrder


order_placed = ws1['J2']
ticker_symbol = ws1['B2'].value
order_qty = ws1['C2'].value
order_lmt_Prc = ws1['D2'].value
order_lmt_Prc = round(order_lmt_Prc, 2) # this was needed to prevent the error "The price does not conform to the minimum price variation for this contract"
aux_stop_prc = ws1['E2'].value
aux_stop_prc = round(aux_stop_prc, 2) # this was needed to prevent the error "The price does not conform to the minimum price variation for this contract"
target_profit = ws1["H2"].value
target_profit = round(target_profit, 2)
submit_it = ws1['I2'].value
trailing_percent = ws1["F2"].value
trailing_percent = round(trailing_percent, 2)
trailstpprc = ws1["G2"].value
trailStpprc = round(trailstpprc, 2)



# note for above code. for 'round' not to return error, values in corresponding excel cells cannot be blank

if submit_it == 1:
# create contract
ticker_contract = Stock(ticker_symbol, 'SMART', 'USD')
ib.qualifyContracts(ticker_contract)
# create bracket order

bracket = BracketStopLimitOrder(ib.client.getReqId(), action='BUY', quantity=order_qty, limitPrice=order_lmt_Prc,
stopPrice=aux_stop_prc, takeProfitLimitPrice=target_profit, trailingPercent=trailing_percent, trailStopPrice=trailStpprc)

# place bracket order
for ord in bracket:
ib.placeOrder(ticker_contract, ord)
ib.sleep(1)


# create contract
ticker_contract = Stock(ticker_symbol,'SMART', 'USD')
ib.qualifyContracts(ticker_contract)
# create bracket order

bracket2 = BracketStopLimitOrder2(ib.client.getReqId(), action='BUY', quantity=order_qty, limitPrice=order_lmt_Prc,
stopPrice=aux_stop_prc, trailingPercent=trailing_percent, trailStopPrice=trailStpprc)

#place bracket order
for ord in bracket2:
ib.placeOrder(ticker_contract, ord)
ib.sleep(1)



order_placed.value = "Yes"


Re: Market depth data has been RESET. Error Code: 317, C++ Program

 

Any clue you can give on which instrument generate it ? At what time ?
How many rows did you look for ?
What did you choose for isSmartDepth ?
I would be very interested to know if you still see updateMktDepth messages arriving after your 317 for the same reqid. This is a sine qua non condition to avoid re-doing a request

I don't see any rationalized method to avoid it as I see this as a message from IB that should be implemented (many errors are to be seen as message).
Nothing I foresee that can be done from client side, but if I have to guess I would say that isSmartDepth? may influence this.

The full message is "Market depth data has been RESET. Please empty deep book contents before applying any new entries."
As I can't reproduce at will, I can only tell you what I implemented as a provision: If I receive a 317 then I do what IB asks:
I purge my bank, and de-facto expect to only receive types 2, or 1 only after I received a first set of new insert (0).? At least I assert that next new message will be an insert.
Note:
I have a counter averaging the number of entries I should expect and restart the algo only once I reach this threshold/2? (to avoid taking decision on too few entries) this of course depend upon your algo.
What I didn't do and probably should, is to call again to update the exch mapping. It may have changed (unlikely that it did change a lot, hence lack of motivation to finish this part, also this require a new request) Anyway at least a mapping to an unknown exchange throw an exception.

Unless mistaken this approach doesn't need to restart a new request (as opposed to error like the 316) hence can stay in same processing thread, but again it's a provision and I have/had no method to QA it