-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IbkrWsKey
should have conid
for market data subscriptions
#18
Comments
Hey @teodorkostov many thanks for describing your issue in detail 👍
Indeed it does require it. The solution I've been running with is to include the conid with the channel string, such as: ws_client.subscribe(channel='mh+265598', ...)
# or
key = IbkrWsKey.MARKET_DATA
ws_client.subscribe(channel=f'{key.channel}+265598', ...) The reason being - from standpoint of both our client and IBKR servers (as far as I could empirically see) if a conid is present, it is married into the channel name:
In essence, the channel+conid pair becomes a de-facto channel name that we subscribe to. It was a choice of simplicity to treat it as just the You can see it being used in this form in these two examples:
Can you see anywhere in the code that would benefit from having these two stored separately?
This is a fair observation, and I'm glad you've pointed it out. I've gone over the code once again to see why was this the decision. Indeed, the answer is related to channel+conid pairs. Why
Why
Would you have any suggestions on how to improve this? |
Sorry, I only just noticed your recommendation is related to a slightly different issue:
Yes, absolutely, we can do this. Got it implemented, I'll publish it in the next release. |
I do agree that it is possible to make it work. However, think about the ibind API from the perspective of a new user. The person does not know how the internals work. To make it work some advanced examples have to be read. Some of the framework code has to be explored. It would be better for the design to guide the user. What if the methods accept a @dataclass(frozen=True)
class Subscription:
key: IbkrWsKey
conid: str = None # or List[str]
data: ... = None
def __post_init__(self):
val(self)
subscription = Subscription(...) # should throw an error if the optional fields are not defined for the special keys
ws_client.subscribe(subscription)
accessor = ws_client.new_queue_accessor(subscription) Then the classes could decide what key to use internally. The user of the API does not have to know. The sooner the user gets an error that something is wrong the better. What do you think? |
Better use a library for that. Something like Pydantic. Data validation is a common problem to solve. It is a certainty that the users of an API will mess up or even exploit it. Minimizing that possibility is good choice. |
Sorry, I'm currently travelling, hence sparsely I find time to look into this. Things should be easing out for me in the upcoming months.
Yeah, that seems like a good idea worth exploring. I agree that having a unified interface would be nicer. Would you like to give it a shot implementing the change? Otherwise, I'm happy to do it once I'm back working. |
And as for this:
Sorry, I'm not sure if I understand what you're referring to here. Could you elaborate? You wanna do data validation for the users' input? |
Hey @teodorkostov just FYI I'm working on this already, you can see the WIP branch here: https://github.com/Voyz/ibind/tree/subscription-overhaul along with |
Problem description
Market data subscriptions require a complex key
smd+conid+{...}
. TheIbkrWsKey
enum does not account for the possibility of having aconid
as a part of the channel.The inconsistent usage of keys in the
QueueController
andSubscriptionController
makes this issue a bit harder to mitigate. TheQueueController
is using theIbkrWsKey
enum as keys. While theSubscriptionController
is using thekey.channel
string as keys.Trying to be smart and getting the
conid
from thedata
dictionary:results in unexpected behavior that generates additional logging:
which forces the silencing:
Solution
QueueController
andSubscriptionController
should use the same keys.IbkrWsKey
should provide a way to incorporate aconid
for market data subscriptionsRecommendation
Add the option to skip key remapping and just return the raw message as is. If I supply field
'84'
(bid price) I would like to get a dictionary with key'84'
and not'bid_price'
. Having the fields as constants is more than enough to write readable code. No need for the processing overhead.The text was updated successfully, but these errors were encountered: