From d8c7a551a4f5d52104f81d5ff8dc9c750fa86f8f Mon Sep 17 00:00:00 2001 From: Stefan Aebischer Date: Fri, 17 Jan 2020 21:36:41 -0500 Subject: [PATCH] Add missing endpoints, switch to v2 Adds missing endpoints: * queryActiveOrder * cancelAllConditionalOrders * queryConditionalOrder * setTradingStop * getWalletFundRecords * getWithdrawRecords * setRiskLimit * getRiskLimitList * getPublicTradingRecords * getApiAnnouncements Switches Endpoints to v2: * getPosition --- doc/rest-client.md | 32 ++++++++++++++++++++++- lib/rest-client.js | 63 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 93 insertions(+), 2 deletions(-) diff --git a/doc/rest-client.md b/doc/rest-client.md index 974a231..0b13355 100644 --- a/doc/rest-client.md +++ b/doc/rest-client.md @@ -28,6 +28,9 @@ If you only use the [public endpoints](#public-endpoints) you can ommit key and #### async replaceActiveOrder(params) [See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#open-apiorderreplacepost) +#### async queryActiveOrder(params) +[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#query-active-order-real-time) + #### async placeConditionalOrder(params) [See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#place-conditional-order) @@ -37,6 +40,12 @@ If you only use the [public endpoints](#public-endpoints) you can ommit key and #### async cancelConditionalOrder(params) [See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#cancel-conditional-order-) +#### async cancelAllConditionalOrders(params) +[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#cancel-all-conditional-orders) + +#### async queryConditionalOrder(params) +[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#query-stop-order-real-time) + #### async getUserLeverage() [See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#user-leverage) @@ -44,11 +53,26 @@ If you only use the [public endpoints](#public-endpoints) you can ommit key and [See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#-change-user-leverage) #### async getPosition() -[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#-my-position) +[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#-my-position-v2) #### async changePositionMargin(params) [See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#-change-position-margin) +#### async setTradingStop(params) +[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#-set-trading-stop) + +#### async getWalletFundRecords(params) +[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#-get-wallet-fund-records) + +#### async getWithdrawRecords(params) +[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#-get-withdraw-records) + +#### async setRiskLimit(params) +[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#set-risk-limit-) + +#### async getRiskLimitList() +[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#get-risk-limit-list-) + #### async getLastFundingRate(params) [See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#-get-the-last-funding-rate) @@ -69,9 +93,15 @@ If you only use the [public endpoints](#public-endpoints) you can ommit key and #### async getLatestInformation() [See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#latest-information-for-symbol) +#### async getPublicTradingRecords(params) +[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#get-public-trading-records) + #### async getServerTime() [See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#server-time) +#### async getApiAnnouncements() +[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#open-apiannouncement) + #### async getSymbols() Returns symbol information (such as tick size & min notional): [Meeting price restrictions](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#price-price) diff --git a/lib/rest-client.js b/lib/rest-client.js index eac39c6..08d2ff1 100644 --- a/lib/rest-client.js +++ b/lib/rest-client.js @@ -48,6 +48,14 @@ module.exports = class RestClient { return await this.request.post('/open-api/order/replace', params); } + async queryActiveOrder(params) { + assert(params, 'No params passed'); + assert(params.order_id || params.order_link_id, 'Parameter order_id OR order_link_id is required'); + assert(params.symbol, 'Parameter symbol is required'); + + return await this.request.get('/v2/private/order', params); + } + async placeConditionalOrder(params) { assert(params, 'No params passed'); assert(params.side, 'Parameter side is required'); @@ -74,6 +82,21 @@ module.exports = class RestClient { return await this.request.post('/open-api/stop-order/cancel', params); } + async cancelAllConditionalOrders(params) { + assert(params, 'No params passed'); + assert(params.symbol, 'Parameter symbol is required'); + + return await this.request.post('/v2/private/stop-order/cancelAll', params); + } + + async queryConditionalOrder(params) { + assert(params, 'No params passed'); + assert(params.stop_order_id || params.order_link_id, 'Parameter order_id OR order_link_id is required'); + assert(params.symbol, 'Parameter symbol is required'); + + return await this.request.get('GET /v2/private/stop-order', params); + } + async getUserLeverage() { return await this.request.get('/user/leverage'); } @@ -87,7 +110,7 @@ module.exports = class RestClient { } async getPosition() { - return await this.request.get('/position/list'); + return await this.request.get('/v2/private/position/list'); } async changePositionMargin(params) { @@ -98,6 +121,33 @@ module.exports = class RestClient { return await this.request.post('/position/change-position-margin', params); } + async setTradingStop(params) { + assert(params, 'No params passed'); + assert(params.symbol, 'Parameter symbol is required'); + + return await this.request.post('/open-api/position/trading-stop', params); + } + + async getWalletFundRecords(params) { + return await this.request.get('/open-api/wallet/fund/records', params); + } + + async getWithdrawRecords(params) { + return await this.request.get('/open-api/wallet/withdraw/list', params); + } + + async setRiskLimit(params) { + assert(params, 'No params passed'); + assert(params.symbol, 'Parameter symbol is required'); + assert(params.risk_id, 'Parameter risk_id is required'); + + return await this.request.post('/open-api/wallet/risk-limit', params); + } + + async getRiskLimitList() { + return await this.request.get('/open-api/wallet/risk-limit/list'); + } + async getLastFundingRate(params) { assert(params, 'No params passed'); assert(params.symbol, 'Parameter symbol is required'); @@ -137,10 +187,21 @@ module.exports = class RestClient { return await this.request.get('/v2/public/tickers'); } + async getPublicTradingRecords(params) { + assert(params, 'No params passed'); + assert(params.symbol, 'Parameter symbol is required'); + + return await this.request.get('/v2/public/trading-records', params); + } + async getServerTime() { return await this.request.get('/v2/public/time'); } + async getApiAnnouncements() { + return await this.request.get('/v2/public/announcement'); + } + async getSymbols() { return await this.request.get('/v2/public/symbols'); }