¿ªÔÆÌåÓý

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

Re: Unrealisedpnl

 

Unrealized PnL is basically ( avg_position_price - current_ticker_price ) * position_size for longs, and ( current_ticker_price?- avg_position_price?) * position_size for shorts.


Re: what is the right internet connection speed?

 

¿ªÔÆÌåÓý

I repeat:

?

10 * 1000 * (100 + 50) = 1,500,000 BYTES per second (ie 1.5 megaBYTES per second)

?

Which is 15 megaBITS per second (approx).

?

?

?

From: [email protected] <[email protected]> On Behalf Of bh@...
Sent: Thursday, December 28, 2023 12:35 AM
To: [email protected]
Subject: Re: [TWS API] what is the right internet connection speed?

?

I think that's 1.5mbs, not 15mbs...


Re: what is the right internet connection speed?

 

Thanks for all the replies.? I feel much better.


Re: what is the right internet connection speed?

 

Do you (anyone) find cloud services useful?

Thank you.?

On Wed, Dec 27, 2023, 11:56 AM Richard L King <rlking@...> wrote:

It¡¯s not easy to give a precise answer, but let¡¯s make some very broad assumptions that will give us some kind of indication.

?

Assume:

?

  • Each tick-by-tick stream generates 1000 events per second (this is much too high, except perhaps over very short periods)

?

  • Each API message is received in the same format as passed to the API client (last time I looked, which was a good many years ago, this was not true: IB used some sort of compression to reduce the message size. I¡¯ve no reason to believe that¡¯s not still true: in other words, this assumption is an over-estimate of the size)

?

  • Each API message is carried in its own FIX protocol wrapper (IB uses the FIX protocol for communication between TWS and the market data servers. Again this is probably an over-estimate: with this amount of data I would expect there to be some kind of batching of API messages that occur practically simultaneously into single FIX messages ¨C but I may well be wrong about that)

?

  • Each tick-by-tick API message has a length of about 50 bytes (from direct observation), but let¡¯s be pessimistic and assume that it¡¯s 100 bytes

?

  • Each FIX message has an overhead of 50 bytes (see for details if you¡¯re interested)

?

With these assumptions the data per second is:

?

number_of_streams * number_of_messages_per_stream * (avg_API_msg_length + FIX_overhead)

?

or

?

10 * 1000 * (100 + 50) = 1500000 bytes per second

?

which is 15 Mbits per second

?

This is small enough that it would be insignificant on a 400 Mbps connection. And with the assumptions above, this is almost certainly a massive over-estimate.

?

So I don¡¯t think you need worry about your data connection. You¡¯re much more likely to suffer from problems with your API client program not being able to keep up with this level of data, unless you¡¯re very conscious of performance considerations in you code.

?

Richard

?

?

?

From: [email protected] <[email protected]> On Behalf Of zlzhao22@...
Sent: Wednesday, December 27, 2023 2:47 AM
To: [email protected]
Subject: [TWS API] what is the right internet connection speed?

?

Hello, suppose I need to receive 10 tick-by-tick streaming data from my api, what is the right internet connection speed requirement?? Right now, my ISP has 100 MB and I am not sure if it is enough.


Re: what is the right internet connection speed?

 

10 instruments, the busiest ones, maybe 50 Kbps at the open total, and half that the rest of the day.? Maybe 100Kbps tops when something huge happens for a brief minute.? So your 100MB is enough to trade 10 stocks, while watching 15 Netflix HD movies concurrently, and listening to a lot of radio channels with the space left over, all at the same time.

20 years ago, you could stream the entire Nasdaq live, across whatever normal bandwidth we had back then.?? I think you should be safe with just a mere 100MB today.


Re: what is the right internet connection speed?

 

¿ªÔÆÌåÓý

Oops, sorry you said your connection was 100 Mbps, not 400 Mbps. Still 15 Mbps is a low level of utilisation, only 15%, so still no problem.

?

Richard

?

?

From: [email protected] <[email protected]> On Behalf Of Richard L King
Sent: Wednesday, December 27, 2023 10:56 AM
To: [email protected]
Subject: Re: [TWS API] what is the right internet connection speed?

?

It¡¯s not easy to give a precise answer, but let¡¯s make some very broad assumptions that will give us some kind of indication.

?

Assume:

?

  • Each tick-by-tick stream generates 1000 events per second (this is much too high, except perhaps over very short periods)

?

  • Each API message is received in the same format as passed to the API client (last time I looked, which was a good many years ago, this was not true: IB used some sort of compression to reduce the message size. I¡¯ve no reason to believe that¡¯s not still true: in other words, this assumption is an over-estimate of the size)

?

  • Each API message is carried in its own FIX protocol wrapper (IB uses the FIX protocol for communication between TWS and the market data servers. Again this is probably an over-estimate: with this amount of data I would expect there to be some kind of batching of API messages that occur practically simultaneously into single FIX messages ¨C but I may well be wrong about that)

?

  • Each tick-by-tick API message has a length of about 50 bytes (from direct observation), but let¡¯s be pessimistic and assume that it¡¯s 100 bytes

?

  • Each FIX message has an overhead of 50 bytes (see for details if you¡¯re interested)

?

With these assumptions the data per second is:

?

number_of_streams * number_of_messages_per_stream * (avg_API_msg_length + FIX_overhead)

?

or

?

10 * 1000 * (100 + 50) = 1500000 bytes per second

?

which is 15 Mbits per second

?

This is small enough that it would be insignificant on a 400 Mbps connection. And with the assumptions above, this is almost certainly a massive over-estimate.

?

So I don¡¯t think you need worry about your data connection. You¡¯re much more likely to suffer from problems with your API client program not being able to keep up with this level of data, unless you¡¯re very conscious of performance considerations in you code.

?

Richard

?

?

?

From: [email protected] <[email protected]> On Behalf Of zlzhao22@...
Sent: Wednesday, December 27, 2023 2:47 AM
To: [email protected]
Subject: [TWS API] what is the right internet connection speed?

?

Hello, suppose I need to receive 10 tick-by-tick streaming data from my api, what is the right internet connection speed requirement?? Right now, my ISP has 100 MB and I am not sure if it is enough.


Re: what is the right internet connection speed?

 

¿ªÔÆÌåÓý

It¡¯s not easy to give a precise answer, but let¡¯s make some very broad assumptions that will give us some kind of indication.

?

Assume:

?

  • Each tick-by-tick stream generates 1000 events per second (this is much too high, except perhaps over very short periods)

?

  • Each API message is received in the same format as passed to the API client (last time I looked, which was a good many years ago, this was not true: IB used some sort of compression to reduce the message size. I¡¯ve no reason to believe that¡¯s not still true: in other words, this assumption is an over-estimate of the size)

?

  • Each API message is carried in its own FIX protocol wrapper (IB uses the FIX protocol for communication between TWS and the market data servers. Again this is probably an over-estimate: with this amount of data I would expect there to be some kind of batching of API messages that occur practically simultaneously into single FIX messages ¨C but I may well be wrong about that)

?

  • Each tick-by-tick API message has a length of about 50 bytes (from direct observation), but let¡¯s be pessimistic and assume that it¡¯s 100 bytes

?

  • Each FIX message has an overhead of 50 bytes (see for details if you¡¯re interested)

?

With these assumptions the data per second is:

?

number_of_streams * number_of_messages_per_stream * (avg_API_msg_length + FIX_overhead)

?

or

?

10 * 1000 * (100 + 50) = 1500000 bytes per second

?

which is 15 Mbits per second

?

This is small enough that it would be insignificant on a 400 Mbps connection. And with the assumptions above, this is almost certainly a massive over-estimate.

?

So I don¡¯t think you need worry about your data connection. You¡¯re much more likely to suffer from problems with your API client program not being able to keep up with this level of data, unless you¡¯re very conscious of performance considerations in you code.

?

Richard

?

?

?

From: [email protected] <[email protected]> On Behalf Of zlzhao22@...
Sent: Wednesday, December 27, 2023 2:47 AM
To: [email protected]
Subject: [TWS API] what is the right internet connection speed?

?

Hello, suppose I need to receive 10 tick-by-tick streaming data from my api, what is the right internet connection speed requirement?? Right now, my ISP has 100 MB and I am not sure if it is enough.


Unrealisedpnl

 

Hi,

how to retrieve unrealied pnl for the current open position only?

existing call back method includes previously closed positions pnl also into unrealised pnl.

Thanks
Anil


what is the right internet connection speed?

 

Hello, suppose I need to receive 10 tick-by-tick streaming data from my api, what is the right internet connection speed requirement?? Right now, my ISP has 100 MB and I am not sure if it is enough.


position return from reqPosition() does not have comboLegs filled

 

Do there is a way to return combo information for existing combo option positions? Call reqPosition only return legs for combo position with comboLegs as empty list and blank?comboLegsDescription.

Thanks?
?


Merry Christmas and/or Happy Holidays to all

 

Hi All,
Merry Christmas and/or Happy Holidays.
Thanks to all, especially to ´³¨¹°ù²µ±ð²Ô, Richard and countless others, for all the help you've given me over the years.

Thanks, as always,
Lou Dudka


Re: Is there a way to automate retrieving margin report?

 

There is no API request that generates a "Margin Report", but then I am not so sure that such a report would be terribly helpful since your client would have to analyze the report to make the data actionable. TWS API does however, give you access to all kinds of margin info on a transactional basis that your trading logic can base order decisions on.

As bespalex already mentioned, reqAccountSummary? gives you a global margin view. Both, as a snapshot when you make the request as well as on an ongoing basis when margin changes. There are well more than 100 different values you might receive, among them (at least) these margin related ones:
  • (Totals) FullInitMarginReq, FullMaintMarginReq, InitMarginReq, LookAheadInitMarginReq, LookAheadMaintMarginReq, MaintMarginReq, NLVAndMarginInReview, PostExpirationMargin, RegTMargin
  • Plus subtotals for commodities (suffix -C)
  • Plus subtotals for equities (suffix -S)

When your application places orders, callbacks report their possible impact in case they execute with ~10 margin, equity, and loan related values. Your application could remember those and verify them against reqAccountSummary updates once those orders execute.

You can use the feature (just like the "Check Margin" in TWS) at any point to check the possible margin impact of an order before you place it. Or, as krkeane pointed out, you can submit fully liquidating "what if" orders for the positions you are interested in to see the margin impact of those positions.

And finally, there are warnings and errors your application may receive, such as:
  • Error 201 --> Order rejected - reason:YOUR ORDER IS NOT ACCEPTED. IN ORDER TO OBTAIN THE DESIRED POSITION YOUR NET LIQ [XXXXXX USD] MUST EXCEED THE MARGIN REQ [YYYYYY USD]
  • Warning 2148 --> Based upon a review of your positions and qualifying equity, your account is not projected to be in compliance? with the daily increase in margin requirements from intraday to overnight levels. Note that accounts which? report a margin deficiency when overnight requirements go into effect are subject to forced liquidation of? positions to ensure margin compliance. To avoid this action, please review your "Look Ahead" account balances? within the TWS Account Window and take the steps necessary to reduce margin exposure.? Account: XXXXXXXX
  • Warning 2148 --> ALERT: Your account, while currently margin compliant, maintains qualifying equity (i.e., Equity with Loan? Value) at a level only 10% above that which is required.? Please note that we do not issue margin calls and? should this cushion erode and your account no longer remain margin compliant, it will be subject to forced? position liquidations. To ensure continued compliance, please consider depositing additional funds to increase? equity and/or closing or hedging positions to lessen margin exposure. Further note that funds in transit or? subject to a credit hold are not considered when liquidating positions.? Account: XXXXXXXX
  • Warning 2148 --> URGENT: Please note that the qualifying equity within your account (i.e., Equity with Loan Value) is? insufficient to satisfy the margin requirement and, to restore margin compliance, liquidation of positions may? commence without further notice.? Account: XXXXXXXX
I am sure I missed something, but I hope this helps.
´³¨¹°ù²µ±ð²Ô


On Sat, Dec 23, 2023 at 01:16 PM, @jiamin wrote:
No, it doesn't.? I think reqAccountSummary only shows the margin status for the account,? but what I want to see if the margin requirement of every ticker.? Please let me know if I am not correct. Thank you.


Re: Is there a way to automate retrieving margin report?

 

On Sat, Dec 23, 2023 at 02:16 PM, @jiamin wrote:
I want to see the margin requirement of every ticker
If you submit a fully liquidating order for each position, you will see the margin impact of each position.


Re: Is there a way to automate retrieving margin report?

 

No, it doesn't.? I think reqAccountSummary only shows the margin status for the account,? but what I want to see if the margin requirement of every ticker.? Please let me know if I am not correct. Thank you.


Re: Is there a way to automate retrieving margin report?

 

Does not reqAccountSummary satisfy your requirements??


Re: Reconnect

 

Found a solution:
1. app.disconnect()
2. app.connect()
3. restart api thread
4. restart data requests
working nicely so far.
Any issues with this approach?


Re: How to Get SPX/SPXW Quote price or current price

 

JavaScript is not one of the IBKR TWS APIs we are focused on here. So you'd have to reach out to the makers/group that supports that version.

TWS 10.19 is fine and has a server version of 173. There seems to be something wrong with the JavaScript TWS API module.

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


On Thu, Dec 21, 2023 at 11:00 AM, arun kumar m wrote:
dont why i can use this ib.serverVersion() in my node js app it throws an error as its not a function. attached my tws version details.

if my server version is lesser how to update it


Re: How to Get SPX/SPXW Quote price or current price

 

dont why i can use this ib.serverVersion() in my node js app it throws an error as its not a function. attached my tws version details.

if my server version is lesser how to update it



Reconnect

 

Hi Guys,
What is the best way to implement api reconnection in case of a loss with an error 504?
My app is in python, and api is in a thread running app.run().
Just running app.connect() again after disconnect doesn't work. Apparently some cleanup is required.
Should an old thread be abandoned and a new thread be started? I am confused.


Re: How to Get SPX/SPXW Quote price or current price

 

Which versions of TWS API and TWS/IBGW you are using?

Reason why I ask is that the root cause for your errors are not the data requests, but by the fact that your TWS API did not negotiate a valid common server version during connection with TWS/IBGW.
  • Error "It does not support historical data backfill" is caused at a "server version" of < 16
  • Error "It does not support delta-neutral orders" is caused at a "server version" < 40

Depending on the exact TWS API and TWS/IBGW, sever versions are now in the range of 170 to 180.

You need to review your connection logic for any issues and you can check the negotiated version after connection with the serverVersion() method of the EClient object.

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


On Thu, Dec 21, 2023 at 09:25 AM, <arunmak654@...> wrote:

i am trying to get the current price of SPX or SPXW but i am getting error. while trying with request Historical data getting the below error

error :? "It does not support historical data backfill."

?

code snippet:

const contract = {

? symbol: 'SPX',

? secType: 'IND',

? exchange: 'CBOE',

? currency: 'USD'

};

?

ibClient.reqHistoricalData( 1, contract, '', '1 D', '1 min', 'TRADES', 1, 1, false, [] );

?

also i tried with request market data still getting error as "It does not support delta-neutral orders"

?

Thanks in advance

?

const contract = {

? symbol: 'SPX',

? secType: 'IND',

? exchange: 'CBOE',

? currency: 'USD'

};

ib.reqMktData(1, contract, '', false);

?