Skip to content
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

Usage outside of US #63

Open
lach1010 opened this issue Feb 27, 2025 · 7 comments
Open

Usage outside of US #63

lach1010 opened this issue Feb 27, 2025 · 7 comments

Comments

@lach1010
Copy link

Hi Team,

Fantastic work thus far.

I am based outside of the US and looking to use the tool for AUS securities on the ASX Exchange.

Clearly the package has been developed first and foremost with US users at heart, however would be great to see this made just as easy to use globally.

For example the stock_conid_by_symbol function is applying the is_us filter by default, which of course is able to be disabled.

My issue is that downsteam users of the stock_conid_by_symbol api don't necessarily have the ability to disable this behaviour - eg the marketdata_history_by_symbol/s family.

I know this can of course be worked around by the user making separate calls to get the con_id and then get data, but it would be nice for the full API to be geo agnostic.

Immediate options would seem to be to remove the default behaviour; or extend the flag parameter to more of the API, or be able to set a global/client state at initialisation?

Happy to get involved with dev work where it makes sense.

@Voyz
Copy link
Owner

Voyz commented Feb 27, 2025

hey @lach1010 many thanks for the kind words 👍

Clearly the package has been developed first and foremost with US users at heart

Honestly, this actually sounds true, but I have to admit it's purely coincidental. I just went with some kind of default, but I'm not a even a US user myself. Apart from the StockQuery is_us default, do you see this anywhere else?

My issue is that downsteam users of the stock_conid_by_symbol api don't necessarily have the ability to disable this behaviour - eg the marketdata_history_by_symbol/s family.

Can you share an example?

Both marketdata_history_by_symbol and marketdata_history_by_symbols accept StockQuery as its argument, which allows you to disable this behaviour, eg:

client.marketdata_history_by_symbols(StockQuery('AAPL', contract_conditions={}))

It is mentioned here:
https://github.com/Voyz/ibind/wiki/Advanced-REST#-security_stocks_by_symbol
https://github.com/Voyz/ibind/wiki/Advanced-REST#-marketdata_history_by_symbols

That being said, I can see how the code snipped I've just shared is never explicitly shown, nor that this is a nice solution. Thanks for bringing it up.

it would be nice for the full API to be geo agnostic.

I'm all in for it! Thank you for spotting these inconsistencies!

Immediate options would seem to be to remove the default behaviour; or extend the flag parameter to more of the API, or be able to set a global/client state at initialisation?

I think a global_contract_condition parameter for the class would be a nice solution. This way one could disable this if needed, or alter it to whatever way they want.

Happy to get involved with dev work where it makes sense.

Ahh appreciate it - if you're looking to do an easy first-time contribution then you're welcome to, but in all fairness I don't mind doing it myself as it is very straightforward.

@lach1010
Copy link
Author

Ah I see.

So the default_filtering flag is to apply contract_conditions with is_us:True if contract_conditions is not provided in the query.

So currently setting the contract_conditions = {} rather then the default None would be a work around.

Yeah I agree that a neater approach would be nice as the current api implies to me that is_us default filtering is a baseline, on top of which a users query filtering is applied, as the flag is still set. Whilst in reality it's just a default only when nothing is provided.

The other quirk here is that providing a different contract_condition would loose the default behaviour. Ie specifying the asset type to be a stock would take the filtering from being US based - to anywhere and a stock.

Maybe a clarification of this behaviour in the docs would be good.

I might leave this one to you whilst I still get my head around what's on offer here, how things are structured and the rationale for choices made thus far.

Keen to get involved going forward though if your looking for help.

@Voyz
Copy link
Owner

Voyz commented Feb 27, 2025

So the default_filtering flag is to apply contract_conditions with is_us:True if contract_conditions is not provided in the query.
So currently setting the contract_conditions = {} rather then the default None would be a work around.

Correct 👍

The other quirk here is that providing a different contract_condition would loose the default behaviour. Ie specifying the asset type to be a stock would take the filtering from being US based - to anywhere and a stock.
Maybe a clarification of this behaviour in the docs would be good.

Yes, though I would say this isn't unwanted. If explicit contract_condition passed in StockQuery doesn't override the default, how else would we turn it off? It's either default, or completely overridden by what user passes. So it makes sense that specifying asset type to stock would remove the default contract condition.

Indeed, the docs outline it:

"A isUS=True contract condition is applied to all calls of this method by default."

Would you say we could rephrase this to make it clearer?

I might leave this one to you

Sure thing, I'll handle the implementation. I appreciate you helping me out figure out the best way to do this 🙌

Keen to get involved going forward though if your looking for help.

Absolutely, I have a few easy tasks to handle for any contributors interested. Drop me an email if you'd be interested: [email protected]

@hughandersen
Copy link
Contributor

hughandersen commented Feb 28, 2025

I'm based in Brisbane/Australia and trade Asia and the US, so trading international stocks from Australia is possible. It sounds like you solved the problem, if not let me know and I'll try to help.
This endpoint is useful:

[def all_conids_by_exchange(self: 'IbkrClient', exchange: str) -> Result:  # pragma: no cover
        """
        Send out a request to retrieve all contracts made available on a requested exchange. This returns all contracts that are tradable on the exchange, even those that are not using the exchange as their primary listing.

        Note: This is only available for Stock contracts.

        Parameters:
            exchange (str): Specify a single exchange to receive conids for.
        """
        return self.get('trsrv/all-conids', {'exchange': exchange})](url)](url)

@Voyz
Copy link
Owner

Voyz commented Feb 28, 2025

I added a global IbkrClient.default_filtering flag that you can set to disable the filtering globally:

# using stock query field
conids = client.stock_conid_by_symbol(StockQuery('AAPL', contract_conditions={'exchange': 'MEXI'}), default_filtering=False).data
pprint(conids)

# using global flag
client.default_filtering = False
conids = client.stock_conid_by_symbol(StockQuery('AAPL', contract_conditions={'exchange': 'MEXI'})).data
pprint(conids)

Please try it out through pip install ibind==0.1.12rc2 and let me know if it works for you 👍

@lach1010
Copy link
Author

Fantastic. Thanks mate. Will give it a try

@lach1010
Copy link
Author

lach1010 commented Mar 3, 2025

Works great thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants