Skip to content

Commit

Permalink
add removeFromWatchlist() function
Browse files Browse the repository at this point in the history
Take advantage of the functionality the endpoint 'WATCHLISTS_ADD_PATH'
exposes.
Rename 'WATCHLISTS_ADD_PATH' to 'WATCHLISTS_ADD_DELETE_PATH'
to better reflect the supported methods.
  • Loading branch information
GregerLindblom committed Oct 4, 2017
1 parent b17aa4b commit 0cea002
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 22 deletions.
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
15 changes: 14 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,25 @@ 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('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)
}

/**
* Get instrument information.
*
Expand Down
14 changes: 13 additions & 1 deletion tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test('getTransactions() with options', async (t) => {
test('addToWatchlist()', async (t) => {
await t.context.avanza.addToWatchlist('12345', '54321')

const expectedPath = constants.paths.WATCHLISTS_ADD_PATH
const expectedPath = constants.paths.WATCHLISTS_ADD_DELETE_PATH
.replace('{1}', '12345')
.replace('{0}', '54321')

Expand All @@ -68,6 +68,18 @@ test('addToWatchlist()', async (t) => {
t.deepEqual(actual, expected)
})

test('removeFromWatchlist()', async (t) => {
await t.context.avanza.removeFromWatchlist('12345', '54321')

const expectedPath = constants.paths.WATCHLISTS_ADD_DELETE_PATH
.replace('{1}', '12345')
.replace('{0}', '54321')

const actual = t.context.call.args[0]
const expected = ['DELETE', expectedPath]
t.deepEqual(actual, expected)
})

test('getInstrument()', async (t) => {
await t.context.avanza.getInstrument('STOCK', '12345')

Expand Down

0 comments on commit 0cea002

Please sign in to comment.