Keyboard Shortcuts
Likes
- Ib-Async
- Messages
Search
Re: Same code not work for Hong Kong stock options
Sorry, here is the code :
from ib_async import * ib = IB() ib.connect('127.0.0.1', 7497) ticker = '941' ccy = 'HKD' exchange = 'SEHK' expiry = '20240627' strike = 75 leg1 = Option(ticker, expiry, strike, 'C', exchange=exchange, currency=ccy) leg2 = Option(ticker, expiry, strike, 'P', exchange=exchange, currency=ccy) ib.qualifyContracts(leg1, leg2) ib.sleep(4) combo_legs = [ ? ? ComboLeg(conId=leg1.conId, ratio=1, action='BUY'), ? ? ComboLeg(conId=leg2.conId, ratio=1, action='BUY')] combo_contract = Contract(symbol=ticker, secType='BAG', currency=ccy, exchange=exchange, comboLegs=combo_legs) order = LimitOrder('BUY', 1, 0.7) trade = ib.placeOrder(combo_contract, order) ib.sleep(3) ib.disconnect() |
Same code not work for Hong Kong stock options
The following code works fine for US stock options, like TSLA, KO...etc., but the same code (just changed stock code, exchange, currency and strike price) resulted in Error 200, reqId 227: No security definition has been found for the request. Have I missed anything? Any idea would be appreciated. Thanks
|
Re: Not properly parsing modified orders or am I missing the point of `Trade` objects?
I notice that in the trade object you received from orderStatusEvent and modifyOrderEvent, the tradingClass is 'NMS' (instead of 'TSLA'). I am not sure this is related to your problem encountered, but in fact I have been stuck with this incorrect tradingClass issue (when defining option contract) for the past weeks and still couldn't? figure out why some tickers could get the correct tradingClass while some tickers got the wrong one. Similarly, sometimes a wrong expiry date for the option contract was used even though I have explicitly put in a correct expiry date. when defining the option contract. Interestingly, the wrong expiry date issue only occurred in Live system (socket 7496), while the same code ran smoothly without error in the Test system (socket 7497). Anyway, not sure my issues are related to yours, but I may create a new topic for my encountered issues later.?
|
Incorrect
I have been running ib_insync/ib_async in production for over 4 years with few issues. Lately I have seen more and more cases where I receive missing or incorrect positionEvent responses. I checked the ibgateway API logs, and the API looks correct.
20240606.114602.671 W handle_position_update WESTW new qty=0, was 141 came from PortfolioItem, not Position: PortfolioItem(contract=Warrant(conId=582332975, symbol='WEST', lastTradeDateOrContractMonth='20270829', strike=11.5, right='C', multiplier='1', primaryExchange='NASDAQ', currency='USD', localSymbol='WESTW', tradingClass='WEST'), position=0.0, marketPrice=2.2950001, marketValue=0.0, averageCost=0.0, unrealizedPNL=0.0, realizedPNL=119.78, account='UXXX') |
Re: Not properly parsing modified orders or am I missing the point of `Trade` objects?
Here is something that may be related. ?Take a look at line 512 of ib_async/wrapper.py, in the openOrder function, where it does ? ? ? ? ? ? trade.order.lmtPrice = order.lmtPriceIn my experience, after I submit a modified orde via ib_async to change the lmtPrice, later, when the modified order is then accepted by the server, IBKR sends back a response that ib_async handles via this openOrder function. ?Among other things, the openOrder function updates the lmtPrice field of the order registered with the trade (at the line noted above). ? This is how I've been tracking when IBKR accepts price modifications (which doesn't always happen right away). ?This has worked pretty reliably for me. ?There was a short email thread about it in the old ib_insync forum, which I don't have a copy of now. Here is code for the "patched" limit order object that I've used to implement this. ?It adds a new event that fires when the price is accepted in this way: class PatchedIBOrder(ibs.Order): |
Not properly parsing modified orders or am I missing the point of `Trade` objects?
I'm having some issues getting correct modified order data returned by As an example workflow, I place a position order and a stop order. Once the position order fills, I modify the stop order and send it. Placed Order
Here are the TWS API Logs to corroborate what's in the returned
Modified Order
However, the TWS API Logs show the modified price in the callback:
Since TWS is sending back the price as modified, maybe I'm missing the point of |
Re: Forum planning
#forum_planning
Dear Mel,
thanks for the discussion. Indeed I would appreciate a general instruction like your mentioned general framework. Personally, I have still the problem that I don't know if I am running into troubles as a result of a wrong IB setup routine (e.g. starting the async loop or qasync loop or using ib_async loop or class implementation or something else) or wrong calls of ib_async functions (e.g. ib.reqContractDetails vs. ib.reqContractDetailsAsync). I moved to ib_in/async because I ended with the tws-api in a dead-end street (of my knowledge), now I don't know if I should move left (function calls) or right (async calls) or is 3 times right = 1 time left (which means it's possible to mix with async calls) Therefore it would be very helpfull to have a structured example with base functions. It's not needed to have a full running code, but the logic should be visible to get the used strategie. There are many ways to Rome... Kind Regards Hans |
Re: Forum planning
#forum_planning
That is where sample code is difficult... I have a lot of basic modules I can call such as starting IB, various reporting, Flex Reports and on and on. But then when it comes to others using that code, there can be issues such as you would need to use the same folder structure as I do to use a lot of my code as I have the code in 3 folders (code, gui, flex) depending on what I want to run. I also have parm, input & output that all my modules expect to find. The other issue comes to other added modues... I use tkinter as it is already built in. Others use pyQt, pySide or even pyGame. One fellow built a nice framework () that was nice but complex. The downside was he wanted to make it multi broker and then TDA merged with Schwab and the API was gone. I may have to delve into it again and consider something like that except just for IB. If something like a general framework that utilizes ib-async interests you and you want to work on it with others, let me know and I will set up a repo for it. Then people could install that and have a lot of built in capabilities for ib_async. Just thoughts... Mel |
Re: Forum planning
#forum_planning
Dear Ray,
yes, I know them. But indeed, for use in a program they are sometimes not handy enough. Do you think that it makes sense to write small programs (Pyqt6 in my case) to demonstrate the usages and keep them like the notebook receipes? So, e.g. if we have a 'standard' init function for IB, it will also be easier to support and find bugs / program issues. Kind Regards Hans |
Re: Forum planning
#forum_planning
Yes I have added the new addresses to the Links Wiki. I re-wrote some of those notebooks to run simply with python as I don't use Jupyter Notebook. I will have those on ib_tools if anyone is interested. Thanks, Mel |
Updated Wiki Page: Links
#wiki-notice
Group Notification
The wiki page Links has been updated by Mel <climbermel@...>. |
Re: Merci
¿ªÔÆÌåÓýWe don't have the "raw" files from the old forum.? One user has provided all the emails and email digests, but they need the personal data removed which we are close to finishing. Mel -------- Original message -------- From: "MB via groups.io" <mbaker@...> Date: 2024-06-06 5:33 a.m. (GMT-08:00) Subject: Re: [ib-async] Merci |
Re: Forum planning
#forum_planning
¿ªÔÆÌåÓýI have been trying to do something along those lines in my ib_tools.? It was a place for me to collect functions as I got them working.? I haven't used async much but I just posted an example there from the old forum that shows setting up a callback. I don't use jupyter so the notebooks were a pain when I first started.? So my ib_tools runs just under python. If there is a specific part you are having trouble with give us an example and some code that isn't working and I'm sure one of us can help. Welcome, Mel -------- Original message -------- From: "hjm via groups.io" <hjm@...> Date: 2024-06-06 5:33 a.m. (GMT-08:00) Subject: Re: [ib-async] Forum planning #forum_planning Hi there and many thanks that some people continue the work of erdewit. According suggestion what's interesting for the 'new' forum, I will give my 5 cent. |
Re: Forum planning
#forum_planning
Hans,
I assume you are familiar with the Ib_Insync Notebooks, code recipes and docs? For now, all or most of that code should still work for Ib_async: https://ib-insync.readthedocs.io/readme.html Kind regards Ray |
Re: Forum planning
#forum_planning
Hi there and many thanks that some people continue the work of erdewit. According suggestion what's interesting for the 'new' forum, I will give my 5 cent. |
Re: ib_tool on GitHub
¿ªÔÆÌåÓýI do that with clean up.? So I but an app for that.? It's a little python app that will search any drive or folder including network folders and servers. -------- Original message -------- From: "Patrick Dufour via groups.io" <info@...> Date: 2024-06-05 11:49 a.m. (GMT-08:00) Subject: Re: [ib-async] ib_tool on GitHub Mel, There is so many other examples i want to create. You know as me the recurring requests from beginners. This fall i hope i will have time to send you a bunch of them. From the one i have posted, i think there is 2 that could be interesting:
|
Re: ib_tool on GitHub
Mel, There is so many other examples i want to create. You know as me the recurring requests from beginners. This fall i hope i will have time to send you a bunch of them. From the one i have posted, i think there is 2 that could be interesting:
|
ib_tool on GitHub
I am cleaning up my ib_tools and I have added this code from the old forum as requested. Message #6484 1a. Re: Async event handling problem with orderStatusEvent From: Patrick Dufour Date: Tue, 29 Jun 2021 Sample Algo Template: If there are any code samples you feel would be good to put on there as well let me know. I do need to clean up the code as it is all using ib_insyc still. Mel |
Re: accessing advancing / declining issues
I did a bit of looking into this, here is some basic code to start with: You can change the AD-AMEX & AMEX to AD-NYSE & NYSE The marketDataType(3) gives me delayed data since I'm not subscribed to that index data. The code below gave the the same numbers as shown for Advancing Issues and Declining Issues as seen in the Market Statistics tab. I'll check on getting the other numbers. sym = 'AD-AMEX' ex = 'AMEX' contract = Contract(secType='IND', symbol=sym, exchange=ex, currency='USD') ib.qualifyContracts(contract) ib.reqMarketDataType(3) data = ib.reqMktData(contract) ib.sleep(2) AdvIssuses = data.bid DecIssuses = data.ask print(AdvIssuses) print(DecIssuses) Cheers, Mel |