fix #29 & process recent api deprecations

This commit is contained in:
tiagosiebler
2020-11-10 22:14:34 +00:00
parent 4d93e5f14e
commit dc4491e1a7
4 changed files with 98 additions and 33 deletions

View File

@@ -1,6 +1,4 @@
const assert = require('assert');
const RequestWrapper = require('./util/requestWrapper');
module.exports = class RestClient {
@@ -54,6 +52,17 @@ module.exports = class RestClient {
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.post('v2/private/order/replace', params);
}
/**
* @deprecated use replaceActiveOrder()
*/
async replaceActiveOrderOld(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.post('open-api/order/replace', params);
}
@@ -66,6 +75,24 @@ module.exports = class RestClient {
}
async placeConditionalOrder(params) {
assert(params, 'No params passed');
assert(params.side, 'Parameter side is required');
assert(params.symbol, 'Parameter symbol is required');
assert(params.order_type, 'Parameter order_type is required');
assert(params.qty, 'Parameter qty is required');
assert(params.base_price, 'Parameter base_price is required');
assert(params.stop_px, 'Parameter stop_px is required');
assert(params.time_in_force, 'Parameter time_in_force is required');
if (params.order_type === 'Limit') assert(params.price, 'Parameter price is required for limit orders');
return await this.request.post('v2/private/stop-order/create', params);
}
/**
* @deprecated use placeConditionalOrder
*/
async placeConditionalOrderOld(params) {
assert(params, 'No params passed');
assert(params.side, 'Parameter side is required');
assert(params.symbol, 'Parameter symbol is required');
@@ -81,10 +108,28 @@ module.exports = class RestClient {
}
async getConditionalOrder(params) {
assert(params.symbol, 'Parameter symbol is required');
return await this.request.get('v2/private/stop-order/list', params);
}
/**
* @deprecated use placeConditionalOrder
*/
async getConditionalOrderOld(params) {
return await this.request.get('open-api/stop-order/list', params);
}
async cancelConditionalOrder(params) {
assert(params, 'No params passed');
assert(params.stop_order_id || params.order_link_id, 'Parameter stop_order_id OR order_link_id is required');
return await this.request.post('v2/private/stop-order/cancel', params);
}
/**
* @deprecated use cancelConditionalOrder
*/
async cancelConditionalOrderOld(params) {
assert(params, 'No params passed');
assert(params.stop_order_id, 'Parameter stop_order_id is required');
@@ -99,6 +144,17 @@ module.exports = class RestClient {
}
async replaceConditionalOrder(params) {
assert(params, 'No params passed');
assert(params.stop_order_id || params.order_link_id, 'Parameter stop_order_id OR order_link_id is required');
assert(params.symbol, 'Parameter symbol is required');
return await this.request.post('v2/private/stop-order/replace', params);
}
/**
* @deprecated use replaceConditionalOrder
*/
async replaceConditionalOrderOld(params) {
assert(params, 'No params passed');
assert(params.stop_order_id, 'Parameter stop_order_id is required');
assert(params.symbol, 'Parameter symbol is required');
@@ -114,10 +170,17 @@ module.exports = class RestClient {
return await this.request.get('v2/private/stop-order', params);
}
/**
* @deprecated use getPosition() instead
*/
async getUserLeverage() {
return await this.request.get('user/leverage');
}
async getPosition(params) {
return await this.request.get('v2/private/position/list', params);
}
async changeUserLeverage(params) {
assert(params, 'No params passed');
assert(params.leverage, 'Parameter leverage is required');
@@ -126,13 +189,9 @@ module.exports = class RestClient {
return await this.request.post('user/leverage/save', params);
}
async getPosition(params) {
assert(params, 'No params passed');
assert(params.symbol, 'Parameter symbol is required');
return await this.request.get('v2/private/position/list', params);
}
/**
* @deprecated use getPosition() instead
*/
async getPositions() {
return await this.request.get('position/list');
}