Closed pudgereyem closed 6 years ago
Apparently the POSITIONS
-channel require you to provide an orderbookId
, as well as a sequence of all your accountIds. I've updated the docs regarding that.
Assuming I have three accounts: 123, 456 and 789, here's what subscribing to my positions for orderbookId 5479 might look like.
avanza.subscribe(Avanza.POSITIONS, '5479_123,456,789', (position) => {
console.log('Updated position:', position)
})
If you want to subscribe to changes for all instruments, use the DEALS
-channel instead.
Hey @fhqvst,
I'll explain first what I'm trying to do, so it's easier to understand what I'm trying to achieve.
Right now I'm just trying to build an "Real time overview of all the stocks I own". It's wrapped inside an Electron app, and lives in the menubar.
To achieve this, I'm first using getPositions
to get all my positions, and then using subscribe
to get updates for the positions. But I'm not sure what channel I should use to get these updates. Do you have any idea?
orderbookId
, is it the ID for a certain instrument/stock?POSITIONS
-channel, why would we pass a orderBookId
and multiple accountId
s? I was thinking that the POSITIONS
-channel would give me updates about ALL the stocks in the accounts I provideDEALS
-channel but I don't get any updates. Could you provide an example?I think it would be cool if we could provide better documentation for the different channels. What they are supposed to return, and how they differ. Would love to see more information in the docs.
Hi! Sorry for the late response, very busy at the moment.
1.
orderbookId
is almost always the ID representing an instrument/stock, but Avanza seems to model orderbooks and instruments as separate entities, and so there is no guarantee that there exists one orderbook for every instrument and vice versa.
I agree, it might seem misleading. This module is really only a wrapper around some endpoints I found, which the iPhone app (as well as the Avanza website) uses to retrieve data. Because of this, most endpoints are specifically made for a certain screen. In the POSITIONS
-case, it is used on the website while you're placing orders (look at the bottom of the screen).
In the same manner, converting this unofficial API into a nice RESTful getOrder(), addOrder(), ...
type of thing becomes very inefficient. Calls to an endpoint might leave you without the data you expected because that data is not used in the screen which the endpoint was designed for.
Hopefully PSD2 makes this module obsolete in 2018! :)
The DEALS
-channel should work exactly like POSITIONS
minus the orderbookId
. Let's again assume that 123, 456, and 789 are the accountIds for all of my accounts. Hit me up if you're still not receiving any data and I'll have a look at it.
avanza.subscribe(Avanza.DEALS, '_123,456,789', (deal) => {
console.log('Received new deal:', deal)
})
It's actually really uncomplicated. Have a look at Charles Proxy.
Hi @fhqvst, no worries, thanks for answering
* I have 5 accounts, all 7 digits long. But I don't get any response. I was thinking that this may be expected when the market is closed? Do you get any data when subscribing this time a day? I'm not sure how you could investigate this further without me taking up to much of your time.. Really appreciate your help.
The DEALS
-channel will give you updates when a transaction is performed (which can only occur when the market is open).
@fhqvst
Hi there,
This subscribe function doesn't work on the positions
channel, I tried parameters such as:
<stockid>_<accountid1>,<accountid2>
_<accountid1>,<accountid2>
<stockid>_<accountid1>
<accountid1>
<stockid>
And yet doesn't get anything. so I'm interested, how can I access the protocols and some deeper documentation of the Avanza API? Also, do I do anything wrong here? or it is a real issue?
thank you in advance.
First of all, awesome project man 👏
Issue
When trying to subscribe for my own positions, using
subscribe
I don't get any responses.Does this work for you? If so, could you provide some example code?
This is what my code looks like
Other
Also, when I read the documentation for channel
Avanza.POSITIONS
:I wonder, when are you using
accountId
and when are you usingorderbookId_accountId
?