Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
Re: Problem allocation for placeOrder(app.nextorderId, FX_order('EURUSD'), order)
开云体育Oops, thanks for pointing that out. Must do better!... ? I'll edit it in the message archive, but of course all those who receive posts by email will have it in their Inbox. ? I doubt any harm will come from it, but nevertheless I think it's unwise for members to include this sort of detail in their posts. ? By the way, when posting something that should really only go the group owner/moderator, please send it to ?[email protected] rather than to the usual group email address. Posting to everyone just potentially makes the situation worse. ? Richard King Group Owner and Moderator |
Re: Not receiving some (many) historical ticks from TWS through API
开云体育When I run your specified query I get 1000 ticks back. I've attached a file containing the results. ? Note that the timestamps are in my local timezone (UK), which is how the API returns the data, but they correspond to the range you specified. ? So I can't confirm your problem. ? ? ? From: [email protected] <[email protected]> On Behalf Of ds-avatar
Sent: 05 February 2021 11:17 To: [email protected] Subject: [TWS API] Not receiving some (many) historical ticks from TWS through API ? I'm having a problem getting a great deal of historical trade ticks from TWS that are available in Time & Sales and this issue appears pretty frequent for the more liquid stocks. For certain days in certain stocks, all I receive is a bunch of ticks until some intraday time, and nothing beyond that. If this issue is reproducible I will have to abandon my attempts to work with historical ticks through API. useRTH = 0 ? This above is a request for a few trades in the Micron stock at a particular time. I can't get anything beyond 11:03:21 on 7 Jan 2021 despite heavy trading which is fully reflected in TWS Time and Sales and so apparently available from IBKR servers. This issue appears to be pretty frequent for this stock as well as BABA and some others that I checked. I'm not getting historical trades for MU also on January 25 and 27, and for BABA the situation is pretty horrible altogether - most of the days are incomplete. The issue seems to correlate with stocks' trading density as it's rarely seen in the less liquid stocks. |
Re: Problem allocation for placeOrder(app.nextorderId, FX_order('EURUSD'), order)
Moderator, You missed an account number in the example.
?
Best wishes,
?
M
On Fri, 5 Feb 2021, 17:34 GUY, <guy.bonnardel@...> wrote:
|
Problem allocation for placeOrder(app.nextorderId, FX_order('EURUSD'), order)
Good morning I'm working on the TWS API. Everything went very well until I got to the order with the PYTHON command app.placeOrder (app.nextorderId, FX_order ('EURUSD'), order) Previously I had launched the order app.reqAccountUpdates (True, "U**") The order has been transmitted well and is well placed on the TWS platform with the associated transmit. But that's where the bottom hurts. it is impossible for me to transmit the order because the 'allocation' is blank. I have to manually enter this allowance in order to be able to execute this order. I don tried to update the default settings like this with my account number U** But nothing has changed . I am completely stuck in this ultimate step. Can you help me? I'll take it back to you in advance. best regards ? ? |
Re: Place a Limit Order with 2 Profit Takers and 1 Stop Loss for a Stock
Nick
The OCA is set automatically by IB for bracket orders. You don't have to set the OCA explicitly.
toggle quoted message
Show quoted text
On 2/5/2021 10:12 AM, Orionn via groups.io wrote:
According to my knowledge/experience, the size/quantity of a child order attached to a parent order must have the same size/quantity of the parent order. Hence my suggestion to use two sets of parent and attached OCA child orders. By the way, the TWS API example in the link that you indicate should set the OCA attribute in the stop loss and profit taker orders to guarantee that if one order fills then the other is automatically canceled. |
Re: Place a Limit Order with 2 Profit Takers and 1 Stop Loss for a Stock
According to my knowledge/experience, the size/quantity of a child order attached to a parent order must have the same size/quantity of the parent order. Hence my suggestion to use two sets of parent and attached OCA child orders. By the way, the TWS API example in the link that you indicate should set the OCA attribute in the stop loss and profit taker orders to guarantee that if one order fills then the other is automatically canceled.
-- |
Not receiving some (many) historical ticks from TWS through API
I'm having a problem getting a great deal of historical trade ticks from TWS that are available in Time & Sales and this issue appears pretty frequent for the more liquid stocks. For certain days in certain stocks, all I receive is a bunch of ticks until some intraday time, and nothing beyond that. If this issue is reproducible I will have to abandon my attempts to work with historical ticks through API.
Can someone with good knowledge and easy access to API operations please check if you can get any content from the API with the following request: Request: reqHistoricalTicks() Args: contract: STK MU SMART USD startDateTime = "20210107 11:04:00" @America/New_York numberOfTicks = 1000 whatToShow = "TRADES" (data callback:?EWrapper.historicalTicksLast) useRTH = 0
?
This above is a request for a few trades in the Micron stock at a particular time. I can't get anything beyond 11:03:21 on 7 Jan 2021 despite heavy trading which is fully reflected in TWS Time and Sales and so apparently available from IBKR servers. This issue appears to be pretty frequent for this stock as well as BABA and some others that I checked. I'm not getting historical trades for MU also on January 25 and 27, and for BABA the situation is pretty horrible altogether - most of the days are incomplete. The issue seems to correlate with stocks' trading density as it's rarely seen in the less liquid stocks.Many thanks in advance. |
Re: Python API vs C/C++ API advantage?
Newbie here - just starting out with IB. I have coded my own algo systems in the past but not with IB. Those have been in Python(even though C++ was also an offered interface)? and I have never had any issue with them in terms of performance. Another thing to consider though is, does it really matter if you are an individual algo trader? How many of us here are depending on very high speed of execution for great returns? If one is, then doesn't that bring about questions as to whether the system(and returns) need to be more independent to execution speeds? I firmly believe execution speeds are in the realm of HFT shops (ala highly sophisticated infrastructure). On Thu, Feb 4, 2021 at 12:09 PM Robert Crim <machine@...> wrote:
|
Re: Python API vs C/C++ API advantage?
Nick
开云体育You've gotten some good answers, I'll give an answer from a different perspective. There are latencies you can't do anything about - quotes and orders traveling from exchanges to IB, within IB's infrastructure, from IB's infrastructure to your app. Trying to optimize beyond these latencies is probably not helpful
to a strategy. The institutions have seen the quote, made a
decision and executed a trade before you even get the quote. Who
is it that you gain an advantage over by reducing your latency by
a millisecond? You do want to deal with the socket efficiently. Hanging around
on timers or polling is not desirable. I don't use IB's libraries
so I can't say which of their libraries have a better
implementation of dealing with the socket. On 2/4/2021 1:39 PM,
bruceb444@... wrote:
Hi, |
Re: Python API vs C/C++ API advantage?
The max speed of interacting with TWS is NOT determined by the language you write in.? C++ is faster than Python but that doesn't matter as TWS's I/O is throttled (pacing violations).? Your code should have no problem keeping up.? What I do is cache all the historical pricing and other data I need locally (on disk, in files) and use that for looking into the past.? Only then does the speed of my code matter because I'm no longer interacting with TWS. A good way to see this is to look at the CPU utilization of your agent.? Unless that's max'ed out (100% x the number of threads in your agent), its very likely that your code is spending much of its time waiting for TWS to send more data.? Unless you are doing something very weird, if you are interacting with TWS you shouldn't be max'ing out the CPU. Also, C++ is fastest at pure computation but Fortan is faster at matrix operations (on the CPU).? However, CUDA code (running on a GPU) is much (much much much) faster than Fortan for matrix operations.? So the actual fastest language depends on what you are doing.? But again, this shouldn't matter when you are interacting with TWS.? TWS is the slow thing bottlenecking your performance. Hunter PS Writing efficient code is hard and unless someone pays you for your coding ability, then its very unlikely your code is fast/efficient.? If I wrote my code in JS (ick), it would probably still be faster than 99% of the code written by folks on this list.? That's not because they aren't smart/skilled people, its just that they haven't spent decades learning how to write code that performs efficiently on modern CPUs.? Most professional programmers can't do this well (its a specialty of mine and I often do talks at programming conferences on the topic) so someone with a non-CS background and/or without decades of programming probably won't either. PPS Its very rare for code to be CPU bound.? Almost all code is memory or I/O bound for at least 15 years (when the motherboard's buses started to be improved).? How you manage your agent's memory is far more important than the algorithms you use if you are trying to optimize your code.? And since you can't do that in Python (but can in C++), I'm guessing that you are probably looking at the wrong thing to make faster.
On Thursday, February 4, 2021, 12:09:17 PM PST, Robert Crim <machine@...> wrote:
Specific?benchmarks are probably not useful here. C/C++ are in general "faster" than python, all things equal, but it's not that simple.? Working with the IB api is mostly I/O-bound, meaning performance is more a function not blocking the rest of your program while waiting to transfer data over the network. You can do this in Python (with async/await) while maintaining a lot of the benefits of working in python. It's also worth keeping in mind that performance-sensitive parts of python programs often implemented in native code, especially in the language?itself* and popular numerical/analytics libraries, so a lot of computationally-expensive code is implemented in C (or fortran) anyway.? Finally, writing high-performance code requires particular expertise and is more nuanced?than just number crunching, and has some serious trade offs in terms of complexity, reuse, and safety. So the guidance is typically just to work with what you're more productive in and optimize only where you are impacted by performance problems you actually have. Working in Python won't paint you in a corner here. On Thu, Feb 4, 2021 at 10:39 AM <bruceb444@...> wrote: Hi, |
Re: Python API vs C/C++ API advantage?
Specific?benchmarks are probably not useful here. C/C++ are in general "faster" than python, all things equal, but it's not that simple.? Working with the IB api is mostly I/O-bound, meaning performance is more a function not blocking the rest of your program while waiting to transfer data over the network. You can do this in Python (with async/await) while maintaining a lot of the benefits of working in python. It's also worth keeping in mind that performance-sensitive parts of python programs often implemented in native code, especially in the language?itself* and popular numerical/analytics libraries, so a lot of computationally-expensive code is implemented in C (or fortran) anyway.? Finally, writing high-performance code requires particular expertise and is more nuanced?than just number crunching, and has some serious trade offs in terms of complexity, reuse, and safety. So the guidance is typically just to work with what you're more productive in and optimize only where you are impacted by performance problems you actually have. Working in Python won't paint you in a corner here. On Thu, Feb 4, 2021 at 10:39 AM <bruceb444@...> wrote: Hi, |
Python API vs C/C++ API advantage?
Hi,
Has anyone benchmarked speed of making requests and receiving data (the full cycle) with C/C++ VS Python? Does it make a difference to go with either or in speed? (Excluding after the fact calculations which I am thinking with high probability that C wins). Please post your numbers if you have gauges this. Thanks, |
Re: Place a Limit Order with 2 Profit Takers and 1 Stop Loss for a Stock
Two lots of commission though.
toggle quoted message
Show quoted text
-----Original Message----- |
Re: Place a Limit Order with 2 Profit Takers and 1 Stop Loss for a Stock
My suggestion is that you create two sets of orders. Each set includes the parent limit order and two attached OCA child orders (profit taker and stop loss). The limit price of the profit taker orders is different on each set of orders. To update the stop loss orders, just monitor the status of the profit taker order in the first set (wait for a fill) and then place the stop loss orders again with modified prices. You may simply trigger the stop loss order modification when the first profit taker order fills. Hope this helps.
-- |
tif of child orders
If I place a buy limit order with a stop loss order attached as a child order and the original order is valid just for the day it will be the same for the stop order, correct?
Meaning if the trade is executed the stop order will become active but it will vanish at the end of the day so I will have to place again the next day (I assume here that I want to have the stop order for the whole life of the trade)? |
Re: Place a Limit Order with 2 Profit Takers and 1 Stop Loss for a Stock
Note that when you attach multiple child orders, IB may place limitations on the possible combinations of allowed child-order parameters. For example, when you add a MOC exit order to the standard bracket child-orders, IB only allows the child orders to have an OCA type of 3 (Reduce on fill without block) and not 1 (Cancel on fill with block) or 2 (Reduce on fill with block). Without the extra MOC child order, you could have your child bracket orders also use OCA Types 2 & 3, not just 1. Such limitations may depend on your specific secType and exchange.
|
Re: Place a Limit Order with 2 Profit Takers and 1 Stop Loss for a Stock
开云体育No it isn't possible, that's why I suggested what I did. If I had thought it were possible, I'd have said so: it was obvious from your question that that was what you were hoping for. ? When you create a bracket order, you can attach any number of child orders to the parent, and the child orders all become an OCA group, with an IB-generated OCA group identifier: for example you could add a both a limit profit taker and also a MOC profit taker, the latter only being relevant if the limit price is not reached during the session. When any one of the child orders is eventually filled, all the others are cancelled, precisely because they are an OCA group. But you already know this because that's exactly what you found… ? It would be nice if IB could extend this mechanism to allow multiple child OCA groups (for example by allowing the API client to specifically set the OCA group identifier differently for different child order groups), but I suspect this would considerably complicate IB's logic and there may be tricky edge cases. Also I doubt it would actually be much used. ? Richard ? ? From: [email protected] <[email protected]> On Behalf Of Pavan M
Sent: 04 February 2021 08:05 To: [email protected] Subject: Re: [TWS API] Place a Limit Order with 2 Profit Takers and 1 Stop Loss for a Stock ? Thank You for your response Richard. ? Actually I should have been a little more specific.? Is it possible to pack them into 1 order. Meaning - IB treats a Bracket Order (Limit Order with 1 Profit Taker and 1 Stop Loss) as 1 order (although internally we are placing 3 orders when using the API and handling transmit settings). Similarly can I create a package such that "Limit Order with 2 Profit Takers and 1 Stop Loss" is also treated as 1 order.? ? Thank You. -- |
Re: Place a Limit Order with 2 Profit Takers and 1 Stop Loss for a Stock
Thank You for your response Richard.
?
Actually I should have been a little more specific.? Is it possible to pack them into 1 order. Meaning - IB treats a Bracket Order (Limit Order with 1 Profit Taker and 1 Stop Loss) as 1 order (although internally we are placing 3 orders when using the API and handling transmit settings). Similarly can I create a package such that "Limit Order with 2 Profit Takers and 1 Stop Loss" is also treated as 1 order.?
?
Thank You.
-- Best Regards, Pavan |