Skip to content

Commit

Permalink
Merge pull request #10 from GregerLindblom/fix-watchlists
Browse files Browse the repository at this point in the history
Change addToWatchlist() request method
  • Loading branch information
fhqvst authored Oct 15, 2017
2 parents 7c1e43f + 0cea002 commit 88cfc76
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 960 deletions.
12 changes: 7 additions & 5 deletions .env-example
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
USERNAME=
PASSWORD=
ACCOUNT=
STOCK=
WATCHLIST=
AVANZA_USERNAME=
AVANZA_PASSWORD=
AVANZA_ACCOUNT=
AVANZA_STOCK=5479
AVANZA_STOCK2=5269
AVANZA_WATCHLIST=
#AVANZA_USER_AGENT=
27 changes: 27 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [getTransactions](#gettransactions)
- [getWatchlists](#getwatchlists)
- [addToWatchlist](#addtowatchlist)
- [removeFromWatchlist](#removefromwatchlist)
- [getInstrument](#getinstrument)
- [getOrderbook](#getorderbook)
- [getOrderbooks](#getorderbooks)
Expand Down Expand Up @@ -345,6 +346,7 @@ Get all transactions of an account.
| Property | Type | Note |
| :----------------- | :----- | ---- |
| `account` | Object | |
| `amount` | Number | |
| `currency` | String | |
| `description` | String | |
| `id` | String | |
Expand Down Expand Up @@ -404,6 +406,15 @@ Add an instrument to the watchlist.
- `instrumentId` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The ID of the instrument to add.
- `watchlistId` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The ID of the watchlist to add the instrument to.

### removeFromWatchlist

Remove an instrument from the watchlist.

**Parameters**

- `instrumentId` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The ID of the instrument to remove.
- `watchlistId` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The ID of the watchlist to remove the instrument from.

### getInstrument

Get instrument information.
Expand Down Expand Up @@ -539,6 +550,7 @@ Get orderbook information.
| `orderbook` | Object | |
| `orderDepthLevels` | Array | |
| `orderDepthReceivedTime` | String | |
| `suitability` | Object | |
| `tickSizeRules` | Array | |
| `untradableDates` | Array | |

Expand Down Expand Up @@ -569,6 +581,21 @@ Get orderbook information.
| `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**

- `instrumentType` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The type of the instrument. See
Expand Down
40 changes: 20 additions & 20 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ const constants = {
* Paths
*/
constants.paths = {}
constants.paths.POSITIONS_PATH = '/_mobile/account/positions'
constants.paths.OVERVIEW_PATH = '/_mobile/account/overview'
constants.paths.ACCOUNT_OVERVIEW_PATH = '/_mobile/account/{0}/overview'
constants.paths.DEALS_AND_ORDERS_PATH = '/_mobile/account/dealsandorders'
constants.paths.WATCHLISTS_PATH = '/_mobile/usercontent/watchlist'
constants.paths.WATCHLISTS_ADD_PATH = '/_api/usercontent/watchlist/{0}/orderbooks/{1}'
constants.paths.STOCK_PATH = '/_mobile/market/stock/{0}'
constants.paths.FUND_PATH = '/_mobile/market/fund/{0}'
constants.paths.CERTIFICATE_PATH = '/_mobile/market/certificate/{0}'
constants.paths.INSTRUMENT_PATH = '/_mobile/market/{0}/{1}'
constants.paths.ORDERBOOK_PATH = '/_mobile/order/{0}'
constants.paths.ORDERBOOK_LIST_PATH = '/_mobile/market/orderbooklist/{0}'
constants.paths.CHARTDATA_PATH = '/_mobile/chart/orderbook/{0}'
constants.paths.ORDER_PLACE_DELETE_PATH = '/_api/order'
constants.paths.ORDER_EDIT_PATH = '/_api/order/{0}/{1}'
constants.paths.ORDER_GET_PATH = '/_mobile/order/{0}'
constants.paths.SEARCH_PATH = '/_mobile/market/search/{0}'
constants.paths.AUTHENTICATION_PATH = '/_api/authentication/sessions/username'
constants.paths.INSPIRATION_LIST_PATH = '/_mobile/marketing/inspirationlist/{0}'
constants.paths.TRANSACTIONS_PATH = '/_mobile/account/transactions/{0}'
constants.paths.POSITIONS_PATH = '/_mobile/account/positions'
constants.paths.OVERVIEW_PATH = '/_mobile/account/overview'
constants.paths.ACCOUNT_OVERVIEW_PATH = '/_mobile/account/{0}/overview'
constants.paths.DEALS_AND_ORDERS_PATH = '/_mobile/account/dealsandorders'
constants.paths.WATCHLISTS_PATH = '/_mobile/usercontent/watchlist'
constants.paths.WATCHLISTS_ADD_DELETE_PATH = '/_api/usercontent/watchlist/{0}/orderbooks/{1}'
constants.paths.STOCK_PATH = '/_mobile/market/stock/{0}'
constants.paths.FUND_PATH = '/_mobile/market/fund/{0}'
constants.paths.CERTIFICATE_PATH = '/_mobile/market/certificate/{0}'
constants.paths.INSTRUMENT_PATH = '/_mobile/market/{0}/{1}'
constants.paths.ORDERBOOK_PATH = '/_mobile/order/{0}'
constants.paths.ORDERBOOK_LIST_PATH = '/_mobile/market/orderbooklist/{0}'
constants.paths.CHARTDATA_PATH = '/_mobile/chart/orderbook/{0}'
constants.paths.ORDER_PLACE_DELETE_PATH = '/_api/order'
constants.paths.ORDER_EDIT_PATH = '/_api/order/{0}/{1}'
constants.paths.ORDER_GET_PATH = '/_mobile/order/{0}'
constants.paths.SEARCH_PATH = '/_mobile/market/search/{0}'
constants.paths.AUTHENTICATION_PATH = '/_api/authentication/sessions/username'
constants.paths.INSPIRATION_LIST_PATH = '/_mobile/marketing/inspirationlist/{0}'
constants.paths.TRANSACTIONS_PATH = '/_mobile/account/transactions/{0}'

/**
* Search
Expand Down
17 changes: 15 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,23 @@ class Avanza extends EventEmitter {
* @param {String} watchlistId The ID of the watchlist to add the instrument to.
*/
addToWatchlist(instrumentId, watchlistId) {
const path = constants.paths.WATCHLISTS_ADD_PATH
const path = constants.paths.WATCHLISTS_ADD_DELETE_PATH
.replace('{0}', watchlistId)
.replace('{1}', instrumentId)
return this.call('GET', path)
return this.call('PUT', path)
}

/**
* Remove an instrument from the watchlist.
*
* @param {String} instrumentId The ID of the instrument to remove.
* @param {String} watchlistId The ID of the watchlist to remove the instrument from.
*/
removeFromWatchlist(instrumentId, watchlistId) {
const path = constants.paths.WATCHLISTS_ADD_DELETE_PATH
.replace('{0}', watchlistId)
.replace('{1}', instrumentId)
return this.call('DELETE', path)
}

/**
Expand Down
Loading

0 comments on commit 88cfc76

Please sign in to comment.