From 9b8626a023aa8b34e367a4d90bcbd521ac6da757 Mon Sep 17 00:00:00 2001 From: Asif Mithawala Date: Sun, 29 Aug 2021 18:29:01 +0200 Subject: [PATCH 1/4] Update constants.js --- lib/constants.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/constants.js b/lib/constants.js index 87cbcdd..f539ed1 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -30,6 +30,7 @@ constants.paths.AUTHENTICATION_PATH = '/_api/authentication/sessions/usercredent constants.paths.TOTP_PATH = '/_api/authentication/sessions/totp' constants.paths.INSPIRATION_LIST_PATH = '/_mobile/marketing/inspirationlist/{0}' constants.paths.TRANSACTIONS_PATH = '/_mobile/account/transactions/{0}' +constants.paths.PRICE_ALERT_PATH = '/_cqbe/marketing/service/alert/{0}'; /** * Search From 0f37e3ca89f2c9de6926e68a94516b8932a7d509 Mon Sep 17 00:00:00 2001 From: Asif Mithawala Date: Sun, 29 Aug 2021 18:30:44 +0200 Subject: [PATCH 2/4] Update index.js --- lib/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/index.js b/lib/index.js index c24874d..f683b17 100644 --- a/lib/index.js +++ b/lib/index.js @@ -629,6 +629,20 @@ class Avanza extends EventEmitter { const path = constants.paths.WATCHLISTS_ADD_DELETE_PATH.replace('{0}', watchlistId).replace('{1}', instrumentId) return this.call('DELETE', path) } + + /** + * Add an price alert. + * + * @param {String} instrumentId The ID of the instrument to add. + * @param {Object} Alert options + * @param {String} [options.price] The target price to receive an alert on. + * @param {String} [options.validUntil] A date on the form YYYY-MM-DD. Cancels alert if this date is passed. + */ + addPriceAlert(instrumentId, options) { + options.notification = true + const path = constants.paths.PRICE_ALERT_PATH.replace('{0}', instrumentId) + return this.call('POST', path, options) + } /** * Get instrument information. From d9904f92080f45065bfddf8eba302b6a436d5220 Mon Sep 17 00:00:00 2001 From: Asif Mithawala Date: Sun, 29 Aug 2021 18:31:35 +0200 Subject: [PATCH 3/4] Update API.md --- API.md | 190 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 104 insertions(+), 86 deletions(-) diff --git a/API.md b/API.md index 95ccd49..c82a2ba 100644 --- a/API.md +++ b/API.md @@ -1,3 +1,4 @@ + ### Table of Contents @@ -25,31 +26,33 @@ - [Parameters][21] - [removeFromWatchlist][22] - [Parameters][23] - - [getInstrument][24] + - [addPriceAlert][24] - [Parameters][25] - - [getOrderbook][26] + - [getInstrument][26] - [Parameters][27] - - [getOrderbooks][28] + - [getOrderbook][28] - [Parameters][29] - - [getChartdata][30] + - [getOrderbooks][30] - [Parameters][31] - - [getInspirationLists][32] - - [getInspirationList][33] - - [Parameters][34] - - [subscribe][35] + - [getChartdata][32] + - [Parameters][33] + - [getInspirationLists][34] + - [getInspirationList][35] - [Parameters][36] - - [placeOrder][37] + - [subscribe][37] - [Parameters][38] - - [getOrder][39] + - [placeOrder][39] - [Parameters][40] - - [editOrder][41] + - [getOrder][41] - [Parameters][42] - - [deleteOrder][43] + - [editOrder][43] - [Parameters][44] - - [search][45] + - [deleteOrder][45] - [Parameters][46] - - [call][47] + - [search][47] - [Parameters][48] + - [call][49] + - [Parameters][50] ## Avanza @@ -145,11 +148,11 @@ generate codes can be provided in `totpSecret`. #### Parameters -- `credentials` **[Object][49]** - - `credentials.username` **[String][50]** - - `credentials.password` **[String][50]** - - `credentials.totp` **[String][50]** - - `credentials.totpSecret` **[String][50]** +- `credentials` **[Object][51]** + - `credentials.username` **[String][52]** + - `credentials.password` **[String][52]** + - `credentials.totp` **[String][52]** + - `credentials.totpSecret` **[String][52]** ### disconnect @@ -284,7 +287,7 @@ Get an overview of the users holdings for a specific account at Avanza Bank. #### Parameters -- `accountId` **[String][50]** A valid account ID. +- `accountId` **[String][52]** A valid account ID. ### getDealsAndOrders @@ -351,14 +354,14 @@ Get all transactions of an account. #### Parameters -- `accountOrTransactionType` **[String][50]** A valid account ID or a - [Transaction Type][51]. -- `options` **[Object][49]** Configuring which transactions to fetch. - - `options.from` **[String][50]?** On the form YYYY-MM-DD. - - `options.to` **[String][50]?** On the form YYYY-MM-DD. - - `options.maxAmount` **[Number][52]?** Only fetch transactions of at most this value. - - `options.minAmount` **[Number][52]?** Only fetch transactions of at least this value. - - `options.orderbookId` **([String][50] \| [Array][53])?** Only fetch transactions involving +- `accountOrTransactionType` **[String][52]** A valid account ID or a + [Transaction Type][53]. +- `options` **[Object][51]** Configuring which transactions to fetch. + - `options.from` **[String][52]?** On the form YYYY-MM-DD. + - `options.to` **[String][52]?** On the form YYYY-MM-DD. + - `options.maxAmount` **[Number][54]?** Only fetch transactions of at most this value. + - `options.minAmount` **[Number][54]?** Only fetch transactions of at least this value. + - `options.orderbookId` **([String][52] \| [Array][55])?** Only fetch transactions involving this/these orderbooks. ### getWatchlists @@ -395,8 +398,8 @@ Add an instrument to the watchlist. #### Parameters -- `instrumentId` **[String][50]** The ID of the instrument to add. -- `watchlistId` **[String][50]** The ID of the watchlist to add the instrument to. +- `instrumentId` **[String][52]** The ID of the instrument to add. +- `watchlistId` **[String][52]** The ID of the watchlist to add the instrument to. ### removeFromWatchlist @@ -404,8 +407,19 @@ Remove an instrument from the watchlist. #### Parameters -- `instrumentId` **[String][50]** The ID of the instrument to remove. -- `watchlistId` **[String][50]** The ID of the watchlist to remove the instrument from. +- `instrumentId` **[String][52]** The ID of the instrument to remove. +- `watchlistId` **[String][52]** The ID of the watchlist to remove the instrument from. + +### addPriceAlert + +Add an price alert. + +#### Parameters + +- `instrumentId` **[String][52]** The ID of the instrument to add. +- `options` **[Object][51]** Alert options. + - `options.price` **[Number][54]** The target price to receive an alert on. + - `options.validUntil` **[String][52]** A date on the form YYYY-MM-DD. Cancels alert if this date is passed. ### getInstrument @@ -513,9 +527,9 @@ Get instrument information. #### Parameters -- `instrumentType` **[String][50]** The type of the instrument. See +- `instrumentType` **[String][52]** The type of the instrument. See [Instrument Types][3]. -- `instrumentId` **[String][50]** Likely the same as the instrumentId. +- `instrumentId` **[String][52]** Likely the same as the instrumentId. ### getOrderbook @@ -579,9 +593,9 @@ Get orderbook information. #### Parameters -- `instrumentType` **[String][50]** The type of the instrument. See +- `instrumentType` **[String][52]** The type of the instrument. See [Instrument Types][3]. -- `orderbookId` **[String][50]** Likely the same as the instrumentId. +- `orderbookId` **[String][52]** Likely the same as the instrumentId. ### getOrderbooks @@ -610,7 +624,7 @@ Get information about multiple orderbooks. #### Parameters -- `orderbookIds` **[Array][53]** A list of orderbook IDs. +- `orderbookIds` **[Array][55]** A list of orderbook IDs. ### getChartdata @@ -648,7 +662,7 @@ Get an array of prices over a period of time. #### Parameters -- `orderbookId` **[String][50]** The orderbook to fetch price data about. +- `orderbookId` **[String][52]** The orderbook to fetch price data about. - `period` **Period** The period from which to fetch data. See [Periods][4]. ### getInspirationLists @@ -722,7 +736,7 @@ Get information about a single inspiration list. #### Parameters -- `type` **[String][50]** List type. See [Lists][5] +- `type` **[String][52]** List type. See [Lists][5] ### subscribe @@ -730,11 +744,11 @@ Subscribe to real-time data. #### Parameters -- `channel` **[String][50]** The channel on which to listen. See [Channels][6]. -- `ids` **([String][50] \| [Array][53]<[String][50]>)** One or many IDs to subscribe to. -- `callback` **[Function][54]** Function to call whenever the subscription receives a new message +- `channel` **[String][52]** The channel on which to listen. See [Channels][6]. +- `ids` **([String][52] \| [Array][55]<[String][52]>)** One or many IDs to subscribe to. +- `callback` **[Function][56]** Function to call whenever the subscription receives a new message -Returns **[Function][54]** Call to unsubscribe. +Returns **[Function][56]** Call to unsubscribe. ### placeOrder @@ -742,16 +756,16 @@ Place a limit order. #### Parameters -- `options` **[Object][49]** Order options. - - `options.accountId` **[String][50]** ID of the account to trade on. - - `options.orderbookId` **[String][50]** ID of the instrument to trade. - - `options.orderType` **[String][50]** One of "BUY" or "SELL". - - `options.price` **[Number][52]** The price limit of the order. - - `options.validUntil` **[String][50]** A date on the form YYYY-MM-DD. Cancels +- `options` **[Object][51]** Order options. + - `options.accountId` **[String][52]** ID of the account to trade on. + - `options.orderbookId` **[String][52]** ID of the instrument to trade. + - `options.orderType` **[String][52]** One of "BUY" or "SELL". + - `options.price` **[Number][54]** The price limit of the order. + - `options.validUntil` **[String][52]** A date on the form YYYY-MM-DD. Cancels the order if this date is passed. - - `options.volume` **[Number][52]** How many securities to order. + - `options.volume` **[Number][54]** How many securities to order. -Returns **[Object][49]** Properties are `messages`, `requestId`, `status`, `orderId`. +Returns **[Object][51]** Properties are `messages`, `requestId`, `status`, `orderId`. ### getOrder @@ -766,10 +780,10 @@ contains information you already have (such as order price or volume). #### Parameters -- `instrumentType` **[String][50]** Instrument type of the pertaining instrument. +- `instrumentType` **[String][52]** Instrument type of the pertaining instrument. See [Instrument Types][3]. -- `accountId` **[String][50]** ID of the account which this order was placed on. -- `orderId` **[String][50]** ID of the order. +- `accountId` **[String][52]** ID of the account which this order was placed on. +- `orderId` **[String][52]** ID of the order. ### editOrder @@ -777,10 +791,10 @@ Edit an order. #### Parameters -- `instrumentType` **[String][50]** Instrument type of the pertaining instrument. +- `instrumentType` **[String][52]** Instrument type of the pertaining instrument. See [Instrument Types][3]. -- `orderId` **[String][50]** Order ID received when placing the order. -- `options` **[Object][49]** Order options. See [placeOrder()][37]. +- `orderId` **[String][52]** Order ID received when placing the order. +- `options` **[Object][51]** Order options. See [placeOrder()][37]. ### deleteOrder @@ -788,8 +802,8 @@ Delete and cancel an order. #### Parameters -- `accountId` **[String][50]** ID of the account on which this order was placed. -- `orderId` **[String][50]** Order ID received when the order was placed. +- `accountId` **[String][52]** ID of the account on which this order was placed. +- `orderId` **[String][52]** Order ID received when the order was placed. ### search @@ -827,8 +841,8 @@ Free text search for an instrument. #### Parameters -- `searchQuery` **[String][50]** Search query. -- `type` **[String][50]?** An instrument type. +- `searchQuery` **[String][52]** Search query. +- `type` **[String][52]?** An instrument type. ### call @@ -837,11 +851,11 @@ marks from `path`. #### Parameters -- `method` **[String][50]** HTTP method to use. (optional, default `'GET'`) -- `path` **[String][50]** The URL to send the request to. (optional, default `''`) -- `data` **[Object][49]** JSON data to send with the request. (optional, default `{}`) +- `method` **[String][52]** HTTP method to use. (optional, default `'GET'`) +- `path` **[String][52]** The URL to send the request to. (optional, default `''`) +- `data` **[Object][51]** JSON data to send with the request. (optional, default `{}`) -Returns **[Promise][55]** +Returns **[Promise][57]** [1]: #avanza @@ -889,66 +903,70 @@ Returns **[Promise][55]** [23]: #parameters-4 -[24]: #getinstrument +[24]: #addpricealert [25]: #parameters-5 -[26]: #getorderbook +[26]: #getinstrument [27]: #parameters-6 -[28]: #getorderbooks +[28]: #getorderbook [29]: #parameters-7 -[30]: #getchartdata +[30]: #getorderbooks [31]: #parameters-8 -[32]: #getinspirationlists +[32]: #getchartdata -[33]: #getinspirationlist +[33]: #parameters-9 -[34]: #parameters-9 +[34]: #getinspirationlists -[35]: #subscribe +[35]: #getinspirationlist [36]: #parameters-10 -[37]: #placeorder +[37]: #subscribe [38]: #parameters-11 -[39]: #getorder +[39]: #placeorder [40]: #parameters-12 -[41]: #editorder +[41]: #getorder [42]: #parameters-13 -[43]: #deleteorder +[43]: #editorder [44]: #parameters-14 -[45]: #search +[45]: #deleteorder [46]: #parameters-15 -[47]: #call +[47]: #search [48]: #parameters-16 -[49]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object +[49]: #call + +[50]: #parameters-17 + +[51]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object -[50]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String +[52]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String -[51]: #transaction-type +[53]: #transaction-type -[52]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number +[54]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number -[53]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array +[55]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array -[54]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function +[56]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function -[55]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise +[57]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise From ec30c74ccc2217dc2aefcc04d4d0bba06c089585 Mon Sep 17 00:00:00 2001 From: Asif Mithawala Date: Sun, 29 Aug 2021 18:40:19 +0200 Subject: [PATCH 4/4] Update index.js --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index f683b17..e4e9a23 100644 --- a/lib/index.js +++ b/lib/index.js @@ -640,7 +640,7 @@ class Avanza extends EventEmitter { */ addPriceAlert(instrumentId, options) { options.notification = true - const path = constants.paths.PRICE_ALERT_PATH.replace('{0}', instrumentId) + const path = constants.paths.PRICE_ALERT_PATH.replace('{0}', instrumentId) return this.call('POST', path, options) }