HellAmbro / Trading212API

Unofficial Trading212 API
MIT License
57 stars 27 forks source link

Orders extract only shows latest orders #16

Closed Adam48521 closed 1 year ago

Adam48521 commented 1 year ago

Hi,

Is there a way to extract all orders via the "trading212.get_orders()" function? Currently in this format it only shows the most recent orders.

Thanks

HellAmbro commented 1 year ago

Hi, thanks for reporting it, i've just updated the API. Unfortunately Trading212 does not provide a way to do that, as a workaround i've added older_than and newer_than to get_orders function so you can filter the orders. You can find an example here If Trading212 does not report all orders (as i think, i've not tried jet), you can simply call multiple times get_orders by only changing older_than and newer_than parameters. I wish i helped you.

HellAmbro commented 1 year ago

Hi, i think that it's a limitation of Trading212. You could try to do it "manually". Roughly speaking if you want to get the latest orders of the year you need to call:

get_orders(older_than=december, newer_than=September) get_orders(older_than=September, newer_than=June)

And so on... Replace months with the datetime. If you want you can use loop. Please let me now if it's work. Maybe i can implement a function that do it automatically. Sorry but as an unofficial API sometimes we are struggling with Trading212 limitations.

Il ven 2 set 2022, 17:49 Adam48521 @.***> ha scritto:

Hi,

Thanks for adding that feature! It works, however it doesn't seem to extract anything which is older than 3 months. I am trying with the code below (I want to ideally get my entire portfolio orders extracted from March 2021) however it generates nothing.

older_than = datetime.datetime(year=2021, month=3, day=1,tzinfo=pytz.timezone("Europe/London")) newer_than = datetime.datetime(year=2021, month=6, day=1, tzinfo=pytz.timezone("Europe/London"))

orders = trading212.get_orders(older_than=older_than, newer_than=newer_than)

If I set the older_than to today (.now as you have in your example) and put newer_than as any date >3 months ago, then I only get results up to July 2022.

— Reply to this email directly, view it on GitHub https://github.com/HellAmbro/Trading212API/issues/16#issuecomment-1235657019, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKY54CESGOY6LQSQYW7KUHLV4IO2DANCNFSM6AAAAAAQCRDCIA . You are receiving this because you commented.Message ID: @.***>