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

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

Closed
paragloom opened this issue Oct 22, 2020 · 4 comments
Closed
Assignees

Comments

@paragloom
Copy link

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 Qluxzz self-assigned this Oct 22, 2020
@Qluxzz
Copy link
Owner

Qluxzz commented Oct 22, 2020

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

@Qluxzz Qluxzz closed this as completed Oct 22, 2020
@paragloom
Copy link
Author

paragloom commented Oct 22, 2020

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

@paragloom
Copy link
Author

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 fhqvst/avanza#48 (comment) 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
Copy link
Author

paragloom commented Oct 23, 2020

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 !

:)

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

2 participants