Qluxzz / avanza

A Python library for the unofficial Avanza API
https://qluxzz.github.io/avanza/
MIT License
85 stars 40 forks source link

Subscribing to ORDERS does not produce updates when orders are entered #12

Closed paragloom closed 3 years ago

paragloom commented 3 years ago

First off. awsome job! I've been trying this api wrapper out a bit and it works well for most parts!

I'm trying to subscribe to ORDERS by specifying a string of account ids formated like this: accounts = "_accountId0,accountId1,accountId2" or accounts = "_2234713,2234713,2234713"

I've also tried providing a list of accountIds and it does not seem to work either.

I would expect the following code to start returning changes made to my orders but nope :( await avanza.subscribe_to_id( ChannelType.ORDERS, accounts, callback )

Has anyone gotten this to work?

Repro steps: 1: subscribe to ORDERS 2: place order 3: no callback :(

Qluxzz commented 3 years ago

Since you're working with multiple ids you have to use the subscribe_to_ids function

Here's an example of how you use subscribe_to_ids

await avanza.subscribe_to_ids(
    channel=ChannelType.ORDERS,
    ids=[
        "_accountId0",
        "accountId1",
        "accountId2"
    ],
    callback=callback
)

I tried this myself and got the expected result

paragloom commented 3 years ago

Thanks for the fast reply. I will test this tomorrow! :)

paragloom commented 3 years ago

I'm still not having any results using the avanza.subscribe_to_ids function unfortunally

overview = avanza.get_overview()
accounts = []
for account in overview['accounts']:
   accounts.append(account['accountId']) 
accounts[0] = "_" + accounts[0]

This generates a list like this: ["_accountId0","accountId1","accountId2","accountId3","accountId4","accountId5","accountId6","accountId7","accountId8","accountId9","accountId10","accountId11","accountId12","accountId13","accountId14"]

I'm wondering if there is an order issue of the accounts or that some types of accounts should not be in this string array for it to work.

from the documentation in the .js api it says I need to provide all accounts but reading https://github.com/fhqvst/avanza/issues/48#issue-628725436 it seems the order is important aswell.

I don't want to inquire too much about what kind of accounts you have but is there any patterns you have observed that could be usefull?

I'm really lost here.

Thanks! :)

paragloom commented 3 years ago

I managed to solve it by inspecting the site and see what is sent. if you sort your account array before appending the "_" to the first element it works like a charm.

here is the code that worked for me:

overview = avanza.get_overview()
accounts = []
for account in overview['accounts']:
   accounts.append(account['accountId']) 
accounts.sort()
accounts[0] = "_" + accounts[0]

Again thanks for the great api !

:)