Skip to content

Latest commit

 

History

History
954 lines (714 loc) · 29.4 KB

API.md

File metadata and controls

954 lines (714 loc) · 29.4 KB

Table of Contents

Avanza

Extends EventEmitter

An Avanza API wrapper.

Constants

Some methods require certain constants as parameters. These are described below.

Instrument types

Type Note
Avanza.STOCK
Avanza.FUND
Avanza.BOND
Avanza.OPTION
Avanza.FUTURE_FORWARD
Avanza.CERTIFICATE
Avanza.WARRANT
Avanza.EXCHANGE_TRADED_FUND
Avanza.INDEX
Avanza.PREMIUM_BOND
Avanza.SUBSCRIPTION_OPTION
Avanza.EQUITY_LINKED_BOND
Avanza.CONVERTIBLE

Periods

Period Note
Avanza.TODAY
Avanza.ONE_WEEK
Avanza.ONE_MONTH
Avanza.THREE_MONTHS
Avanza.THIS_YEAR
Avanza.ONE_YEAR
Avanza.FIVE_YEARS

Lists

List Note
Avanza.HIGHEST_RATED_FUNDS
Avanza.LOWEST_FEE_INDEX_FUNDS
Avanza.BEST_DEVELOPMENT_FUNDS_LAST_THREE_MONTHS
Avanza.MOST_OWNED_FUNDS

Channels

Note that for all channels where a sequence of account IDs are expected (<accountId1>,<accountId2>,...), you must supply all of your account IDs, regardless of whether or not you want data for that account.

Channel Note
Avanza.QUOTES Minute-wise data containing current price, change, total volume traded etc. Expects an orderbookId.
Avanza.ORDERDEPTHS Best five offers and current total volume on each side. Expects an orderbookId.
Avanza.TRADES Updates whenever a new trade is made. Data contains volume, price, broker etc. Expects an orderbookId.
Avanza.BROKERTRADESUMMARY Pushes data about which brokers are long/short and how big their current net volume is. Expects an orderbookId.
Avanza.POSITIONS Your positions in an instrument. Expects a string of <orderbookId>_<accountId1>,<accountId2,<accountId3>,....
Avanza.ORDERS Your current orders. Expects a string of _<accountId1>,<accountId2,<accountId3>,....
Avanza.DEALS Recent trades you have made. Expects a string of _<accountId1>,<accountId2,<accountId3>,....
Avanza.ACCOUNTS N/A. Expects a string of _<accountId>.

Transaction Types

Transaction type Note
Avanza.OPTIONS
Avanza.FOREX
Avanza.DEPOSIT_WITHDRAW
Avanza.BUY_SELL
Avanza.DIVIDEND
Avanza.INTEREST
Avanza.FOREIGN_TAX

Order Types

Order type Note
Avanza.BUY
Avanza.SELL

authenticate

Authenticate the client.

If second factor authentication is needed, either the one time code can be provided in totp, or the secret to generate codes can be provided in totpSecret.

Parameters

disconnect

Disconnects by simulating a client that just goes away.

getPositions

Get all positions held by this user.

Returns

getPositions()

Property Type Note
instrumentPositions Array
totalBalance Number
totalBuyingPower Number
totalOwnCapital Number
totalProfit Number
totalProfitPercent Number

getOverview

Get an overview of the users holdings at Avanza Bank.

Returns

getOverview()

Property Type Note
accounts Array
numberOfDeals Number
numberOfIntradayTransfers Number
numberOfOrders Number
numberOfTransfers Number
totalBalance Number
totalBuyingPower Number
totalOwnCapital Number
totalPerformance Number
totalPerformancePercent Number

getOverview().accounts[i]

Property Type Note
accountId String
accountPartlyOwned Boolean
accountType String
active Boolean
attorney Boolean
buyingPower Number
depositable Boolean
interestRate Number
name String
ownCapital Number
performance Number
performancePercent Number
totalBalance Number
totalBalanceDue Number
totalProfit Number
totalProfitPercent Number
tradable Boolean

getAccountOverview

Get an overview of the users holdings for a specific account at Avanza Bank.

Returns

getAccountOverview()

Property Type Note
accountId String
accountName String
accountType String
accountTypeName String
accruedInterest Number
allowMonthlySaving Boolean
availableSuperLoanAmount Number
buyingPower Number
clearingNumber String
courtageClass String
creditAfterInterest Number
creditLimit Number
currencyAccounts Array
depositable Boolean
forwardBalance Number
instrumentTransferPossible Boolean
interestRate Number
internalTransferPossible Boolean
jointlyOwned Boolean
numberOfDeals Number
numberOfIntradayTransfers Number
numberOfOrders Number
numberOfTransfers Number
overdrawn Boolean
overMortgaged Boolean
ownCapital Number
performance Number
performancePercent Number
performanceSinceOneMonth Number
performanceSinceOneMonthPercent Number
performanceSinceOneWeek Number
performanceSinceOneWeekPercent Number
performanceSinceOneYear Number
performanceSinceOneYearPercent Number
performanceSinceSixMonths Number
performanceSinceSixMonthsPercent Number
performanceSinceThreeMonths Number
performanceSinceThreeMonthsPercent Number
performanceSinceThreeYears Number
performanceSinceThreeYearsPercent Number
reservedAmount Number
sharpeRatio Number
standardDeviation Number
totalBalance Number
totalCollateralValue Number
totalPositionsValue Number
totalProfit Number
totalProfitPercent Number
withdrawable Boolean

getAccountOverview().currencyAccounts[i]

Property Type Note
balance Number
currency String

Parameters

  • accountId String A valid account ID.

getDealsAndOrders

Get recent deals and orders.

Returns

getDealsAndOrders()

Property Type Note
accounts Array
deals Array
orders Array
reservedAmount Number

getDealsAndOrders().accounts[i]

Property Type Note
id String
name String
type String

getDealsAndOrders().deals[i]

Property Type Note
account Object
dealId String
dealTime String
marketTransaction Boolean
orderbook Object
orderId String
price Number
sum Number
type String
volume Number

getTransactions

Get all transactions of an account.

Returns

getTransactions()

Property Type Note
totalNumberOfTransactions Number
transactions Array

getTransactions().transactions[i]

Property Type Note
account Object
amount Number
currency String
description String
id String
transactionType String
verificationDate String

Parameters

  • accountOrTransactionType String A valid account ID or a Transaction Type.
  • options Object Configuring which transactions to fetch.
    • options.from String? On the form YYYY-MM-DD.
    • options.to String? On the form YYYY-MM-DD.
    • options.maxAmount Number? Only fetch transactions of at most this value.
    • options.minAmount Number? Only fetch transactions of at least this value.
    • options.orderbookId (String | Array)? Only fetch transactions involving this/these orderbooks.

getWatchlists

Get all watchlists created by this user. Note that the second table was created from a specific watchlist, and so the response from the API will be different for you.

Returns

getWatchlists()[i]

Property Type Note
editable Boolean
id String
name String
orderbooks Array

getWatchlists()[i].orderbooks[i]

Property Type Note
0 String
1 String
2 String
3 String
4 String
5 String

addToWatchlist

Add an instrument to the watchlist.

Parameters

  • instrumentId String The ID of the instrument to add.
  • watchlistId String The ID of the watchlist to add the instrument to.

removeFromWatchlist

Remove an instrument from the watchlist.

Parameters

  • instrumentId String The ID of the instrument to remove.
  • watchlistId String The ID of the watchlist to remove the instrument from.

getInstrument

Get instrument information.

Returns

getInstrument()

Property Type Note
annualMeetings Array
brokerTradeSummary Object
change Number
changePercent Number
company Object
companyOwners Object
companyReports Array
country String
currency String
dividends Array
flagCode String
hasInvestmentFees Boolean
highestPrice Number
id String
isin String
keyRatios Object
lastPrice Number
lastPriceUpdated String
latestTrades Array
loanFactor Number
lowestPrice Number
marketList String
marketMakerExpected Boolean
marketPlace String
marketTrades Boolean
morningStarFactSheetUrl String
name String
numberOfOwners Number
numberOfPriceAlerts Number
orderDepthLevels Array
orderDepthReceivedTime String
positions Array
positionsTotalValue Number
priceAtStartOfYear Number
priceFiveYearsAgo Number
priceOneMonthAgo Number
priceOneWeekAgo Number
priceOneYearAgo Number
priceSixMonthsAgo Number
priceThreeMonthsAgo Number
priceThreeYearsAgo Number
pushPermitted Boolean
quoteUpdated String
relatedStocks Array
shortSellable Boolean
superLoan Boolean
tickerSymbol String
totalValueTraded Number
totalVolumeTraded Number
tradable Boolean

getInstrument().annualMeetings[i]

Property Type Note
eventDate String
extra Boolean

getInstrument().companyReports[i]

Property Type Note
eventDate String
reportType String

getInstrument().dividends[i]

Property Type Note
amountPerShare Number
currency String
exDate String
paymentDate String

getInstrument().latestTrades[i]

Property Type Note
cancelled Boolean
dealTime String
matchedOnMarket Boolean
price Number
volume Number

getInstrument().relatedStocks[i]

Property Type Note
flagCode String
id String
lastPrice Number
name String
priceOneYearAgo Number

Parameters

getOrderbook

Get orderbook information.

Returns

getOrderbook()

Property Type Note
account Object
brokerTradeSummary Object
customer Object
firstTradableDate String
hasInstrumentKnowledge Boolean
hasInvestmentFees Object
hasShortSellKnowledge Boolean
lastTradableDate String
latestTrades Array
marketMakerExpected Boolean
marketTrades Boolean
orderbook Object
orderDepthLevels Array
orderDepthReceivedTime String
tickSizeRules Array
untradableDates Array

getOrderbook().latestTrades[i]

Property Type Note
cancelled Boolean
dealTime String
matchedOnMarket Boolean
price Number
volume Number

getOrderbook().tickSizeRules[i]

Property Type Note
maxPrice Number
minPrice Number
tickSize Number

getOrderbook().untradableDates[i]

Property Type Note
0 String
1 String
2 String
3 String
4 String
5 String
6 String
7 String
8 String
9 String

Parameters

getOrderbooks

Get information about multiple orderbooks.

Returns

getOrderbooks()[i]

Property Type Note
change Number
changePercent Number
currency String
flagCode String
highestPrice Number
id String
instrumentType String
lastPrice Number
lowestPrice Number
name String
priceThreeMonthsAgo Number
totalVolumeTraded Number
tradable Boolean
updated String

Parameters

  • orderbookIds Array A list of orderbook IDs.

getChartdata

Get an array of prices over a period of time.

Returns

getChartdata()

Property Type Note
ceiling Number
change Number
changePercent Number
comparisonName String
comparisonSeries Array
dataSeries Array
floor Number
max Number
min Number

getChartdata().comparisonSeries[i]

Property Type Note
timestamp String
value Number

getChartdata().dataSeries[i]

Property Type Note
timestamp String
value Number

Parameters

  • orderbookId String The orderbook to fetch price data about.
  • period Period The period from which to fetch data. See Periods.

getInspirationLists

List all inspiration lists.

Returns

getInspirationLists()[i]

Property Type Note
averageChange Number
averageChangeSinceThreeMonths Number
highlightField Object
id String
imageUrl String
information String
instrumentType String
name String
orderbooks Array
statistics Object

getInspirationLists()[i].orderbooks[i]

Property Type Note
change Number
changePercent Number
currency String
flagCode String
highlightValue Number
id String
lastPrice Number
name String
priceOneYearAgo Number
priceThreeMonthsAgo Number
updated String

getInspirationList

Get information about a single inspiration list.

Returns

getInspirationList()

Property Type Note
averageChangeSinceThreeMonths Number
highlightField Object
id String
imageUrl String
information String
instrumentType String
name String
orderbooks Array
statistics Object

getInspirationList().orderbooks[i]

Property Type Note
changeSinceOneDay Number
changeSinceOneYear Number
changeSinceThreeMonths Number
highlightValue Number
id String
lastUpdated String
name String

Parameters

subscribe

Subscribe to real-time data.

Parameters

  • channel String The channel on which to listen. See Channels.
  • ids (String | Array<String>) One or many IDs to subscribe to.
  • callback Function Function to call whenever the subscription receives a new message

Returns Function Call to unsubscribe.

placeOrder

Place a limit order.

Parameters

  • options Object Order options.
    • options.accountId String ID of the account to trade on.
    • options.orderbookId String ID of the instrument to trade.
    • options.orderType String One of "BUY" or "SELL".
    • options.price Number The price limit of the order.
    • options.validUntil String A date on the form YYYY-MM-DD. Cancels the order if this date is passed.
    • options.volume Number How many securities to order.

Returns Object Properties are messages, requestId, status, orderId.

getOrder

Get information about an order.

It is quite hard to automatically generate tables of what this endpoint returns since orders are merely temporary entities.

The returned object however looks very much like that from getOrderbook() with an extra property order which contains information you already have (such as order price or volume).

Parameters

  • instrumentType String Instrument type of the pertaining instrument. See Instrument Types.
  • accountId String ID of the account which this order was placed on.
  • orderId String ID of the order.

editOrder

Edit an order.

Parameters

deleteOrder

Delete and cancel an order.

Parameters

  • accountId String ID of the account on which this order was placed.
  • orderId String Order ID received when the order was placed.

search

Free text search for an instrument.

Returns

search()

Property Type Note
hits Array
totalNumberOfHits Number

search().hits[i]

Property Type Note
instrumentType String
numberOfHits Number
topHits Array

search().hits[i].topHits[i]

Property Type Note
changePercent Number
currency String
flagCode String
id String
lastPrice Number
name String
tickerSymbol String
tradable Boolean

Parameters

  • searchQuery String Search query.
  • type String? An instrument type.

call

Make a call to the API. Note that this method will filter dangling question marks from path.

Parameters

  • method String HTTP method to use. (optional, default 'GET')
  • path String The URL to send the request to. (optional, default '')
  • data Object JSON data to send with the request. (optional, default {})

Returns Promise