Keyboard Shortcuts
Likes
- Twsapi
- Messages
Search
reqMktData doesn't lead with current bid/ask
Phil K
I'm just posting for confirmation on reqMktData behavior.? It seems odd to me that, for a live data request,
it doesn't lead with the current bid/ask and then send change callbacks.? For slower, less liquid markets (I work most with option chains), you need to wait, sometimes minutes, until a refresh occurs and you see the very first bid/ask.? If you work with fast, liquid markets you might not even notice the problem, but turn your attention to slower markets and the issue becomes apparent. Phil |
Re: IBAPI - Contract details for micro contracts MYM
开云体育For most futures, you can get the contract by specifying just the sectype, the local symbol and the exchange (for example E-Mini futures on Globex). For some futures, which only trade on a single exchange, you only need the sectype and the local symbol (for example FTSE Futures and DTB futures). ? And MYM is one of the latter: all you need is sectype="FUT" and localsymbol="MYM? JUN 21" ? Note that the localsymbol for ECBOT contracts is a different pattern from many other exchanges, so it's not "MYMM1" as you reasonably guessed. The DTB exchange also uses this format. ? Another ECBOT contract is ZB?? JUN 21 (there are three spaces after ZB), but in this case you have to supply the exchange as well because it also trades on QBALGO. ? What would be handy would be a nice little program that would allow you to try various different contract requests and show you what you get back. Oh wait – I wrote one! It's called the Contract Inspector, it's free and open source, and you can acquire it from here: ? ? I find it really useful for resolving this sort of problem. ? Note: there's a gotcha – this program is currently Windows only, and it uses Microsoft's OneClick technology to keep itself up to date, but at the moment there is a serious problem with OneClick in that it only works via Internet Explorer in Windows 10 20H2 or later (yes, really, Internet Explorer!...). So if you go to the website above with IE the install will work fine, but with any other browser you just get a dumb page of XML displayed. Microsoft are aware of this problem but they seem to be flummoxed by it… ? Richard ? ? From: [email protected] <[email protected]> On Behalf Of Kevin
Sent: 12 May 2021 10:15 To: [email protected] Subject: [TWS API] IBAPI - Contract details for micro contracts MYM ? Hello, contract = Contract()
|
Re: IBAPI - Contract details for micro contracts MYM
I think you still need to define the expiration and the multiplier.
-----Original Message-----
From: Kevin <kevin@...> To: [email protected] Sent: Wed, May 12, 2021 5:15 am Subject: [TWS API] IBAPI - Contract details for micro contracts MYM Hello,
I'm new at this, and would like some help with Contract Definitions for the ECBOT exchange contracts. Using the provided Python sample Program.py and am able to obtain snapshot data for GLOBEX and NYMEX, however with ECBOT I am not able to obtain any snapshot information unless I provide a conId, as per the contract definition: contract = Contract() However when the conId is omitted, as I do in all other contracts, I receive the dreaded 200 error message. ERROR 1005 200 No security definition has been found for the request. Is someone able to help me with the correct way of defining these contracts: MYM, YC, YK and YW? Thanks, KH |
Re: IBAPI - Contract details for micro contracts MYM
This works for me: mym_contract?=?Contract() mym_contract.symbol?=?'MYM' mym_contract.secType?=?'FUT' mym_contract.exchange?=?'ECBOT' mym_contract.currency?=?'USD' mym_contract.lastTradeDateOrContractMonth?=?"202106" On Wed, May 12, 2021 at 12:04 PM Kevin <kevin@...> wrote: Hello, |
IBAPI - Contract details for micro contracts MYM
Hello,
I'm new at this, and would like some help with Contract Definitions for the ECBOT exchange contracts. Using the provided Python sample Program.py and am able to obtain snapshot data for GLOBEX and NYMEX, however with ECBOT I am not able to obtain any snapshot information unless I provide a conId, as per the contract definition: contract = Contract() However when the conId is omitted, as I do in all other contracts, I receive the dreaded 200 error message. ERROR 1005 200 No security definition has been found for the request. Is someone able to help me with the correct way of defining these contracts: MYM, YC, YK and YW? Thanks, KH |
Re: ibapi nextValidId not always invoked
thank you @ScottBrian,
toggle quoted message
Show quoted text
this is indeed my first time to deal with threads. my program is not intended to stop receiving data, but to handle as much of it. about your solution: i see the run() method of EReader is abruptly ending when the connection falls, thus i think it may not snatch responses post disconnection. to my satisfaction, data isn't being lost, as client.reader is pushing it's input to client.msg_queue, q that survives disconnection. a friend (also brian) suggested on stackoverflow to join and stop after disconnection the data consumption loop, the EClient.run(). without very specific explanation, this solution actually works. probably, some later handling of the messages in the queue, does need the now closed connection. here is the working code. i'd like to set the syntax highlighting too:
|
Re: ibapi nextValidId not always invoked
Hi Alex,
I have some additional thoughts: IBapi __init__ calls host_connect which will be unsuccessful if TWS is not yet up. This we know. But then, __init__ instantiates a thread for the EClient run method and starts it. If the client in not yet connected, the EClient run method will see self.Isconnected as False and exit. Later, keepAlive might get connected to TWS, but the EClient run thread is no longer active so we won't be seeing NextValidD get control (or anything else). The quick fix is to instantiate a new run thread in keepAlive after the connect is successful. Also, I suggest that both run thread and keepAlive thread be made a part of the IBapi instance data so that they can be joined during shutdown. Also, threads can not be restarted, so if they are made to be instance data, simply instantiate new threads as needed. Cheers, Scott |
Re: OCA Order Examples
My apologies for the spamming of messages - last one.
I figured it out. For anyone else that searches for and finds this, my mistake was believing that I needed to submit the multiple orders through the one placeOrder. Separating them into 3 placeOrders (and fixing the orderId field) has now worked. |
Re: OCA Order Examples
After working on this further, my main issue seems to be with the contract field in the placeOrder for the OCA. When checking via relevant prints, the list doesn't seem to contain the full contract details. Relevant code pasted below.
? ? ? ? ocaContract = [stock1contract, stock2contract, stock3contract]
? ? ? ? ocaOrders = [stock1limitorder, stock2limitorder, stock3limitorder]
? ? ? ? OneCancelsAll("TestOCA_", ocaOrders, 2)? ? ??
? ? ? ? for o in ocaOrders:
? ? ? ? ? ? self.placeOrder(orderId, Contract(), o)? ??
? ? ? ? ? ??print(Contract(), Order())
? ? ? ? ? ? print("printing o: ", o) def OneCancelsAll(ocaGroup, ocaOrders, ocaType):
? ? for o in ocaOrders:
? ? ? ? o.ocaGroup = ocaGroup
? ? ? ? o.ocaType = ocaType
?
? ? return ocaOrders
|
Re: ibapi nextValidId not always invoked
Hi Alex,
I had a similar problem with a connect being done on the heals of a disconnect. I determined that the EClient disconnect code failed to wait for the reader thread to come home. It was orphaned but still active and snatched the handshaking responses during the following connect. Not sure you have the same problem, but just in case, following is my disconnect code that overrides the EClient disconnect. Try that out if you want. You can either comment out the logging code or get scottbrian-utils from PyPI and add "from scottbrian_utils.diag_msg import get_formatted_call_sequence" to your imports. Note also that you will need the add "self.disconnect_lock = Lock()" in your __init__ method for your IBapi class and add "from threading import Lock" to your imports.? Note also in my disconnect_from_ib that I join the run thread to wait for it to come home before exiting the disconnect process. Having both the reader thread and the run thread finished makes for a clean connect. ########################################################################### ? ? ? ? |
OCA Order Examples
Hey everyone,
I'm in the process of setting up the IB Api in Python and I am pulling my hair out trying to get a One Cancels All order setup correctly (i.e. without errors). I was wondering if anyone would be able to please share some example code from Python for me to better understand the layout? I have reviewed the TWS API github resources extensively, but whether I am just not advanced in Python enough to understand it I don't know. I'm looking to setup OCA orders comprising multiple stocks - so not the typical Bracket Order (comprising parent and stoploss & profit target) OCA that seems to be discussed most often.? Place Orders are going through fine (so the connection and setup of the code are ok) and I'm comfortable with the general logic of Python, but I just cannot work out the format needed to code the OCA order. Any help would be greatly appreciated. Thanks |
Re: How Market Data Farm is ON when the API Client is not connected itself?
Nick
The TWS display of market data farm has nothing to do with the api. It is telling you that TWS itself is connected to IB's data farm server.
toggle quoted message
Show quoted text
You broke your code when you changed it so that you are not calling connect before using other api functions. Or you are connecting, then disconnecting, then trying to use another api function. On 5/11/2021 3:20 AM, Tareq Naushad wrote:
Hello, |