Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Re: Weird change in avg cost for RIO
Having looked into this a bit more I think I can see what's happened.
I partially closed the position and crystalised a loss which should have gone to cash. According to the report what's actually happened is instead of the loss going to cash, IB, having reduced my position appropriately, then redistribute the existing unrealised loss across the smaller number of shares, hence the avg price sinks noticeably. So I end up with no realised loss despite having partially closed the position. I end up with the same (as pre-trade) unrealised loss over a smaller number of shares. Why do they do this? It's really unexpected and hence confusing. Best, G. On Wed, 16 Dec 2020 07:35:51 -0800 "mdelvaux2" <mdelvaux@...> wrote: I am not an IB insider, so takes this with a grain of salt. It seems |
Re: I can't get live market data even with the data subscription
On Tue, Dec 15, 2020 at 10:15 PM, TodyD wrote:
US Securities Snapshot and Futures Value BundleThat subscription only covers snapshot data for securities and not streaming data. You would also need the US Equity and Options Add-On Bundle or the individual Network A, Network B, Network C subscriptions. |
Re: Weird change in avg cost for RIO
I am not an IB insider, so takes this with a grain of salt. It seems that the average cost can be calculated as approximately the (close - realized - unrealized) / position
55.42 + (-304.06 - 385.78) / 86 = 47.39860465116279 That would make the avgCost about what is needed to breakeven on the combined trade |
Python Client Keeps on Disconnecting from IB TWS
Hey everyone,
I am new to IB API and tried developing my first Python client that connects to IB TWS and runs the strategy every two minutes. So once my program starts, the client gets connected to TWS and then every two minutes, it runs the strategy. Until then, code does nothing. Now, the issue is, when my code waits for another iteration, the connection between the client and TWS will remain idle and during that time (precisely after 20 idle seconds), TWS disconnects my client and then on the next iteration, I will get the error that my client is not connected.? Any insights on how can I handle this situation would be great.? |
Weird change in avg cost for RIO
Hey,
I noticed after partially taking a loss on RIO on the 14th, the following day my unrealised P&L had shot back down again and my avg cost had diminished significantly (position is short). Date Avg Cost Close Position Unrealised Realised 10th 51.3580326 55.25 -166 -646.06659 0 11th 51.8844682 55.46 -191 -682.92657 0 14th 47.444749 55.42 -86 -304.06 -385.78 Notice the avg cost on the 14th. Afaics, when CLOSING a position, the avg cost shouldn't change (brokerage would be included in the realised profit/loss I think). Here I've clearly closed the position, but my average cost has dropped a lot, out of the blue it seems to me. I've tried to figure out what they're doing re avg cost rather than read the instructions, so I could be mistaken in the way I'm thinking about it. Anyway, on the open the following day (15th @ 8am), in keeping with the new and improved (although not for me sadly) avg cost, I've made another big loss and the average cost has changed yet again without me having traded. It's moved in my favour very slightly, so it can't be fees. EPIC POS MKT_PRICE AVG_COST MKT_VALUE REALISED UNREALISED ---- --- -------------- ------- -------------- ------------ ------------------- RIO -86.0 55.576950 47.774749 -4779.620000 0.000000 -670.990000 Can someone explain to me what's going on here? Thanks for your help, Graham. |
Re: I can't get live market data even with the data subscription
Hmmm, if you are certain it is finding the correct symbol, maybe there's something about the choice of bundle and or the exchange that is important. I'm sorry, I don't subscribe to the data, so if it's not obvious I can not help. One for the live chat support? Best wishes, M On Wed, 16 Dec 2020, 09:20 TodyD, <vietnamknight2005@...> wrote: I have tried 100 stock_names, they behave consistently. |
Re: I can't get live market data even with the data subscription
I have tried 100 stock_names, they behave consistently.
Error 354, reqId 654: Requested market data is not subscribed.Delayed market data is available.Error&BEST/STK/Top&BEST/STK/Top, contract: Stock(symbol='ADS', exchange='SMART', currency='USD')
Error 354, reqId 655: Requested market data is not subscribed.Delayed market data is available.Error&BEST/STK/Top&BEST/STK/Top, contract: Stock(symbol='ADSK', exchange='SMART', currency='USD')
These work fine if I switch to delayed market data though |
Re: I can't get live market data even with the data subscription
What does tws show when you enter the ticker ? There's a few AEE named tickers, I would not be surprised if it was guessing the wrong one. I've found using contact ID is more reliable. Best wishes, M On Wed, 16 Dec 2020, 08:41 TodyD, <vietnamknight2005@...> wrote: I already waited almost 40 hours, still getting the same things |
Re: I can't get live market data even with the data subscription
Depending on when you subscribed you may have to wait overnight (US) for it to activate. Check in tws if you can see it, that will help isolate the update for you. Best wishes, M On Wed, 16 Dec 2020, 04:15 TodyD, <vietnamknight2005@...> wrote: I already subscribed to the `US Securities Snapshot and Futures Value Bundle` |
I can't get live market data even with the data subscription
I already subscribed to the `US Securities Snapshot and Futures Value Bundle`
However, when I request live data from IB self.ib.reqMarketDataType(1) I keep getting this:? Error 354, reqId 656: Requested market data is not subscribed.Delayed market data is available.Error&BEST/STK/Top&BEST/STK/Top, contract: Stock(symbol='AEE', exchange='SMART', currency='USD') |
API Bracket Order - Order rejected because parent order is being canceled
Hello, I'm trying to place a simple bracket order with a take profit and a stop loss. I manage to buy (parent order) but then the child orders get rejected, saying the parent order is being canceled. As you can see from the code below, transmit is set to 'false' except for the last child. Any suggestions about what's going on? function bracketOrder(parentOrderId, action, quantity, limitPrice, takeProfitLimitPrice, stopLossPrice) { var parent = new OrderBuilder() .setAccount(BROKER_ACCOUNT) .setAction(action) .setQuantity(quantity) .setOrderType(ORDER_TYPE.LIMIT) .setLimitPrice(limitPrice) .setTimeInForce(TIME_IN_FORCE.DAY) .setTransmitOrder(false) .build(); var takeProfit = new OrderBuilder() .setAccount(BROKER_ACCOUNT) .setAction(action == ACTION.BUY ? ACTION.SELL : ACTION.BUY) .setQuantity(quantity) .setOrderType(ORDER_TYPE.LIMIT) .setParentId(parentOrderId) .setLimitPrice(takeProfitLimitPrice) .setTimeInForce(TIME_IN_FORCE.DAY) .setTransmitOrder(false) .build(); var stopLoss = new OrderBuilder() .setAccount(BROKER_ACCOUNT) .setAction(action == ACTION.BUY ? ACTION.SELL : ACTION.BUY) .setQuantity(quantity) .setOrderType(ORDER_TYPE.STOP) .setParentId(parentOrderId) .setStopPrice(stopLossPrice) .setTimeInForce(TIME_IN_FORCE.DAY) .setTransmitOrder(true) .build(); return [parent, takeProfit, stopLoss]; } const stockContract = new ContractBuilder() .setSymbol('BABA') .setSecType(SEC_TYPE.STOCK) .build(); brokerClient.on('nextValidId', nextOrderId => { try { var orders = bracketOrder(nextOrderId,ACTION.BUY, 100, 253, 253.1, 252,9); orders.forEach(order => { brokerClient.placeOrder(nextOrderId++, stockContract, order); }); } catch (err) { console.log(err); } }) brokerClient.on('openOrder', (id, contract, order, orderState) => { console.log('open order', { id, contract, order, orderState }) }) brokerClient.on('error', (id, code, message) => console.log('Error id: ', id, ' code: ', code, ' message: ', message) ) Thank you! |
Re: Python reqMktData blocking?
That's probably the only case where it is NOT fully asynchronous aside of RTVolume tickkind in reqmkdata (which are NOT tick level) As per IB: You ALWAYS have a tickSize after you have a tickPrice, seems the way IB solved that. Documented you even have too many (by 1 in one case) ? |
Re: Symbol in API Market Data Callbacks
See other issue dealt with way to decid what to use for reqid below. But aside of it, my way of handling that is to manage a table reqid => Symbol, not the reverse. Because you may have more than one subscription (each with <> reqid) set for same symbol, hence up to a dozen reqid for same symbol (Like historical, contractdetails, ticks (Various) mkdata, etc ...) So when receiving answer the issue is to find which symbol this answer belong to. That's easier to do at time you submit request to register reqid. Also be careful that answer are asynchronous. (some exception with ticks because the mode require sequencing getting price before volume) ? |
Re: Symbol in API Market Data Callbacks
You are free to use whatever number you want. If you look at IB API samples you see id are 'whatever was in the mind of the coder' BUT!! Even if you can recycle an id, do it only once you are SURE you no longer use it for another subscription! reqid is an "int" so this means 31 bits, means that you will not have problems for your first 2Billion request, Otherwise said, your safe for years if your soft never restart (Id can be reset at each startup) ? The coding rules in practice is to always start from a number and increment it, every time you get a new request to do. Never recycle number, you will have reason to restart your soft earlier than exhaustion of id! ? As per Symbol: IB use "conid" which is a number that uniquely identify the contract. This is generally done trough request for contract details, that report this conid, then save it. Never saw it changingfor same instument Or at least I never found a way to avoid using conid during order , and this it is not even recommended, you MUST know precisely what you order. ? |