开云体育

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

Re: orderReference missing in flex reports

 

On Sun, Feb 2, 2020 at 10:43 AM, ds-avatar wrote:
Order Ref is available in flex reports for the last single trading day. One way to retrieve it regularly is to set up an email subscription.
Thank you for that clarification.? I was running into problems trying to get OrderRef out of flex reports for prior periods.


Re: reqHistoricalData formatDate with 2 means UTC for returned times but not for endTime?

Nick
 

开云体育

I suppose I should add that I always request that the date be returned as an epoch (which is always UTC) and convert to local time. This avoids ambiguity as to the time zone of the returned data.


On 2/3/2020 9:04 AM, Nick wrote:

The documentation is rather lacking for this function.

formatDate only refers to the returned bars. The last I heard is that endDateTime is always in the TWS time zone.


On 2/2/2020 10:18 PM, Traveler wrote:

Passing formatDate=2 to reqHistoricalData() returns times that are in the UTC timezone.

But it appears that even if the passed in value for endDateTime is timezone-aware and in UTC.

Is this correct and should it be? The formatIBDatetime() function prints it in the proper timezone but I suspect that TWS is treating it as local.




Re: reqHistoricalData formatDate with 2 means UTC for returned times but not for endTime?

Nick
 

开云体育

The documentation is rather lacking for this function.

formatDate only refers to the returned bars. The last I heard is that endDateTime is always in the TWS time zone.


On 2/2/2020 10:18 PM, Traveler wrote:

Passing formatDate=2 to reqHistoricalData() returns times that are in the UTC timezone.

But it appears that even if the passed in value for endDateTime is timezone-aware and in UTC.

Is this correct and should it be? The formatIBDatetime() function prints it in the proper timezone but I suspect that TWS is treating it as local.



multiple request of historical data using loops

 

Hello, I am new to TWS API, trying to write a simple program that reads stock tickers from excel and then using it to acquire historical data. Right now the program I wrote only print out historical data of the first symbol, but I want it to print the historical data for all symbols. If anyone can provide insight into how can I approach this that will be really appreciated. Thank you.

def __init__(self):
    EClient.__init__(self,self)
    self.barsList=[]
def error(self, reqId, errorCode, errorString):
    print(reqId,"error",errorString)
def nextValidId(self,reqId):
    self.start()


def historicalData(self, reqId, bar):
    print(bar)


def start(self):
    contract = Contract()
    wb = Workbook.load_workbook('StockTickers.xlsx')
    sheet_ranges=wb['Sheet1']


    empty_list=[]
    empty_list.append(sheet_ranges['A1'].value)
    empty_list.append(sheet_ranges['A2'].value)
    empty_list.append(sheet_ranges['A3'].value)
    for i in empty_list:
        contract.symbol=str(i)
        print(i)




    contract.secType = "STK"
    contract.exchange = "SMART"
    contract.currency = "USD"
    contract.primaryExchange = "NASDAQ"

    self.reqHistoricalData(1, contract, "", "26 W", "1 day", "MIDPOINT", 0, 1, False, [])

def stop(self):
    self.done=True
    self.disconnect()

def main():

app = TestApp()
app.nextOrderId=0
app.connect("127.0.0.1", 7497, 0)
Timer(3, app.stop).start()


app.run()
if?name=="main":
main()


Re: reqHistoricalData formatDate with 2 means UTC for returned times but not for endTime?

 

On Sun, Feb 2, 2020 at 07:18 PM, Traveler wrote:

Sorry, dropped out some text:

But it appears that even if the passed in value for endDateTime is timezone-aware and in UTC.

But it appears that even if the passed in value for endDateTime is timezone-aware and in UTC that TWS does not respect that in the API.


reqHistoricalData formatDate with 2 means UTC for returned times but not for endTime?

 

Passing formatDate=2 to reqHistoricalData() returns times that are in the UTC timezone.

But it appears that even if the passed in value for endDateTime is timezone-aware and in UTC.

Is this correct and should it be? The formatIBDatetime() function prints it in the proper timezone but I suspect that TWS is treating it as local.


Re: Python IBAPI vs. REST API.. pros & cons?

 

"the reason I don't want to consider this is because IB, in their wisdom, need the gateway running in order to make the calls to the API."

my understanding though is that you don't actually need the gateway running to interact with the REST API, they have an oauth authentication flow, no??


Re: orderReference missing in flex reports

 

Order Ref is available in flex reports for the last single trading day. One way to retrieve it regularly is to set up an email subscription.


Re: (Realatively) high speed trading

 

On Sun, Feb 2, 2020 at 12:59 AM, Francois G wrote:
On Sat, Feb 1, 2020 at 09:06 AM, Edward wrote:
the Paper account is VERY similar to the real execution
Edward, I would not be as optimistic as you... Maybe with SPY, or one cent bid/ask spread, but when dealing with stocks, a midpoint limit order is likely to be filled on real trading, while paper trading platform still waits for the bid/ask (worst) price to be filled...
My experience with IB's paper trader is that it is pretty useless for simulating order execution.? The real wonder of the paper trader is not that it works well, but that it works at all.? When you think about what happens in the marketplace during execution, especially in the highly fragmented environment of USA stocks, it becomes more apparent.? If you have a marketable order working, nobody can see it but you because it doesn't really exist. The paper trader needs a trade-through, or at least a number of trades at your price, to make a reasonable guess whether you get a fill.

For pretty much the same reason, the paper trader is also not very useful for testing if a system is profitable.? The one exception I would make is that if paper trading shows a loss, it's probably time to scrap the system.
[rwk]


Re: (Realatively) high speed trading

 

On Sat, Feb 1, 2020 at 09:06 AM, Edward wrote:
the Paper account is VERY similar to the real execution
Edward, I would not be as optimistic as you... Maybe with SPY, or one cent bid/ask spread, but when dealing with stocks, a midpoint limit order is likely to be filled on real trading, while paper trading platform still waits for the bid/ask (worst) price to be filled...


Re: (Realatively) high speed trading

 

Yes I agree Nick, that's what I'm going to do, strip everything down to the bare minimum to ensure I don't have a queue of messages being left unprocessed and looking at old prices.
Everything does work in-memory but at the start till I had a grip on what was going on I was logging anything and everything, so it may just be a case of needing to switch off the logging.
It's a bit frustrating I can only test Monday to Friday during trading hours in a different timezone but so be it ;-)


Re: (Realatively) high speed trading

Nick
 

I'm not sure if it's a language or terminology issue but something doesn't fit here.

Shared memory is the fastest thing you can do for inter-thread or inter-process communication. Disk is the slowest (other than something crazy like text or email).

It seems like you need an understanding of program architecture for your platform in general, unrelated to TWS Api. TWS Api is just a specific implementation of an appropriate architecture.

Maybe I'm not understanding your issue with sells being filled but with limit orders your order will not be filled until you are at the front of the line for that price (ask) and a bid comes along at your price or better. If there's no bid then your order will sit until one comes along, which could be hours.

Seems like you need to take a step back and research your platform, then build the simplest possible TWS Api app to verify that your performance goals can be met, then add the actual trading system last.

On 2/1/2020 8:14 PM, dominic.keeley@... wrote:
Up till now the processes to make the requests and to process the market data feeds used shared memory resources but that is clearly way too slow. I'm guessing the fastest way will be to stream market data feeds to disk in the most efficient way possible


Re: (Realatively) high speed trading

 

That's very useful information, thanks.
Indeed I went to the TWS and API logs and I can see that the cancellation is getting triggered around exactly when I would expect.
Its clear there is some lag in the process and I haven't worked out whether it's in the transmission of the status from TWS/API or in my program which processes the messages sent out, but I'm suspecting it's in my program as it was built initially to get the functionality up and running rather than with an eye on performance and dumps a lot of information to disk files and has database read/writes. It turns out that at least in some cases I'm not processing prices until 30 after they appear in the TWS/API logs so that could well be the reason we haven't had much success getting orders fulfilled.
If anyone has any suggestions of the best framework to process market data feeds quickly that would be really appreciated. Up till now the processes to make the requests and to process the market data feeds used shared memory resources but that is clearly way too slow. I'm guessing the fastest way will be to stream market data feeds to disk in the most efficient way possible and the then have an entirely separate process that reads the disk files and links the request ID to the original request.
It's a shame the api logs can't be read directly as that would take one step out of the process.?


Re: orderReference missing in flex reports

 

I ran into this in Feb 2019 on a live account and was told by IB that it ‘operates as designed’, meaning OrderRef in a FlexQuery will always be blank.? This is obviously odd since it is available as a selection in the report setup.

?

A workaround is to log all order and execution messages to a database at runtime, both of which contain any OrderRef value included when placing the order.? Also logged is the unique PermId for every order, which is the key you can use for linking orders, order legs, and executions for any reporting based on OrderRef.

?

Incidentally, if you are using TWS and set ‘Show trades for:’ to ‘Last 7 Days’ before you connect the API, the initial execution messages received after API connection will include the OrderRef.? So basically, TWS has visibility to OrderRef, but they are dropped at IB before they can make it into a FlexQuery.


Re: FYI - OCA Group Filled Renders Unfilled Order Inactive

 
Edited

[Regrettably, what I said here regarding transmit=false and transmit=true is no longer true (though it used to be - see?/g/twsapi/message/43728).]

Well, just to be precise, setting transmit=true will cause any orders that were placed with transmit=false to be actioned by TWS (ie all orders since the last time placeOrder() was called with an order that had transmit=true).

?

It’s nothing at all to do with ocaGroups or bracket orders.

?

?

From: [email protected] <[email protected]> On Behalf Of David Armour
Sent: 01 February 2020 10:20
To: [email protected]
Subject: Re: [TWS API] FYI - OCA Group Filled Renders Unfilled Order Inactive

?

For orders that are grouped by an OCA Group code, you need to set TRANSMIT=FALSE for all orders except the last one to be sent to prevent premature order fills. The last order being set TRANSMIT=TRUE will turn TRUE on for all orders in the same OCA Group.?

?


Re: FYI - OCA Group Filled Renders Unfilled Order Inactive

 

开云体育

You just set transmit=true on the last order in the group before calling placeOrder().

?

?

From: [email protected] <[email protected]> On Behalf Of Dragos Durlut
Sent: 01 February 2020 10:11
To: [email protected]
Subject: Re: [TWS API] FYI - OCA Group Filled Renders Unfilled Order Inactive

?

Transmit is set to true at the moment.

If I set the Transmit to false, how do i then tell IB that i want to transmit all the orders in the OCA group?


Re: FYI - OCA Group Filled Renders Unfilled Order Inactive

 
Edited

[Regrettably, what I said here regarding transmit=false and transmit=true is no longer true (though it used to be - see?/g/twsapi/message/43728).]

I disagree.

?

You can place the orders separately with transmit=true and set the ocagroup for each one. In exactly the same way, you can place all the orders in a bracket order with transmit=true, and the bracket order will be constructed ok.

?

The point about setting transmit=false for all except the last order is that it avoids potential situations like the OP described.

?

You can even submit all the orders with transmit=true, then update them later with parentId or ocaGroup as required.

?

Similarly you can place any number of orders with transmit=false, not in any kind of bracket order or ocaGroup, or even along with orders in a bracket order or ocaGroup, and they will all be submitted when an order with transmit=true is placed.

?

The only meaning of transmit=true is for TWS to action all orders that have been placed with TWS=false. This gives a mechanism for semi-automated trading strategies to place orders but have them held until the user manually transmits them.

?

Try it!

?

Richard

?

?

From: [email protected] <[email protected]> On Behalf Of Josh via Groups.Io
Sent: 31 January 2020 22:59
To: [email protected]
Subject: Re: [TWS API] FYI - OCA Group Filled Renders Unfilled Order Inactive

?

On Fri, Jan 31, 2020 at 04:18 PM, Richard L King wrote:

Is it possible that you didn’t set transmit=false

Richard I think thats only usually done with bracket orders; regular OCA groups won't all be sent together when one is received with transmit=True in the same way.?

?


Re: FYI - OCA Group Filled Renders Unfilled Order Inactive

 

For orders that are grouped by an OCA Group code, you need to set TRANSMIT=FALSE for all orders except the last one to be sent to prevent premature order fills. The last order being set TRANSMIT=TRUE will turn TRUE on for all orders in the same OCA Group.?


Re: orderReference missing in flex reports

 

I also have a live account with some spare change.

?

I will try to also run it there. Maybe i'll see a difference.


Re: FYI - OCA Group Filled Renders Unfilled Order Inactive

 

Transmit is set to true at the moment.

If I set the Transmit to false, how do i then tell IB that i want to transmit all the orders in the OCA group?