Expand API support, including some V2 endpoints (#4)
Switch to V2 versions of some APIs: * place order * cancel order Add missing APIs: * cancel all orders * replace order * get symbols Add support for custom order ID for cancel active order.
This commit is contained in:
@@ -14,13 +14,19 @@ If you only use the [public endpoints](#public-endpoints) you can ommit key and
|
|||||||
### Private enpoints
|
### Private enpoints
|
||||||
|
|
||||||
#### async placeActiveOrder(params)
|
#### async placeActiveOrder(params)
|
||||||
[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#place-active-order)
|
[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#place-active-order-v2)
|
||||||
|
|
||||||
#### async getActiveOrder(params)
|
#### async getActiveOrder(params)
|
||||||
[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#get-active-order)
|
[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#get-active-order)
|
||||||
|
|
||||||
#### async cancelActiveOrder(params)
|
#### async cancelActiveOrder(params)
|
||||||
[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#cancel-active-order)
|
[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#open-apiordercancelv2post)
|
||||||
|
|
||||||
|
#### async cancelAllActiveOrders(params)
|
||||||
|
[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#open-apiordercancelallpost)
|
||||||
|
|
||||||
|
#### async replaceActiveOrder(params)
|
||||||
|
[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#open-apiorderreplacepost)
|
||||||
|
|
||||||
#### async placeConditionalOrder(params)
|
#### async placeConditionalOrder(params)
|
||||||
[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#place-conditional-order)
|
[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#place-conditional-order)
|
||||||
@@ -55,7 +61,6 @@ If you only use the [public endpoints](#public-endpoints) you can ommit key and
|
|||||||
#### async getOrderTradeRecords(params)
|
#### async getOrderTradeRecords(params)
|
||||||
[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#get-the-trade-records-of-a-order)
|
[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#get-the-trade-records-of-a-order)
|
||||||
|
|
||||||
|
|
||||||
### Public enpoints
|
### Public enpoints
|
||||||
|
|
||||||
#### async getOrderBook(params)
|
#### async getOrderBook(params)
|
||||||
@@ -67,10 +72,16 @@ If you only use the [public endpoints](#public-endpoints) you can ommit key and
|
|||||||
#### async getServerTime()
|
#### async getServerTime()
|
||||||
[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#server-time)
|
[See bybit documentation](https://github.com/bybit-exchange/bybit-official-api-docs/blob/master/en/rest_api.md#server-time)
|
||||||
|
|
||||||
|
#### 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)
|
||||||
|
|
||||||
|
[See bybit documentation](https://bybit-exchange.github.io/bybit-official-api-docs/en/index.html#operation/query_symbol)
|
||||||
|
|
||||||
#### async getTimeOffset()
|
#### async getTimeOffset()
|
||||||
|
|
||||||
Returns the time offset in ms to the server time retrieved by [`async getServerTime`](#async-getservertime).
|
Returns the time offset in ms to the server time retrieved by [`async getServerTime`](#async-getservertime).
|
||||||
If positive the time on the server is ahead of the clients time, if negative the time on the server is behind the clients time.
|
If positive the time on the server is ahead of the clients time, if negative the time on the server is behind the clients time.
|
||||||
|
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ module.exports = class RestClient {
|
|||||||
|
|
||||||
if(params.order_type === 'Limit') assert(params.price, 'Parameter price is required for limit orders');
|
if(params.order_type === 'Limit') assert(params.price, 'Parameter price is required for limit orders');
|
||||||
|
|
||||||
return await this.request.post('/open-api/order/create', params);
|
return await this.request.post('/v2/private/order/create', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getActiveOrder(params) {
|
async getActiveOrder(params) {
|
||||||
@@ -28,9 +28,24 @@ module.exports = class RestClient {
|
|||||||
|
|
||||||
async cancelActiveOrder(params) {
|
async cancelActiveOrder(params) {
|
||||||
assert(params, 'No params passed');
|
assert(params, 'No params passed');
|
||||||
assert(params.order_id, 'Parameter order_id is required');
|
assert(params.order_id || params.order_link_id, 'Parameter order_id OR order_link_id is required');
|
||||||
|
|
||||||
return await this.request.post('/open-api/order/cancel', params);
|
return await this.request.post('/v2/private/order/cancel', params);
|
||||||
|
}
|
||||||
|
|
||||||
|
async cancelAllActiveOrders(params) {
|
||||||
|
assert(params, 'No params passed');
|
||||||
|
assert(params.symbol, 'Parameter symbol is required');
|
||||||
|
|
||||||
|
return await this.request.post('/v2/private/order/cancelAll', params);
|
||||||
|
}
|
||||||
|
|
||||||
|
async replaceActiveOrder(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
async placeConditionalOrder(params) {
|
async placeConditionalOrder(params) {
|
||||||
@@ -126,6 +141,10 @@ module.exports = class RestClient {
|
|||||||
return await this.request.get('/v2/public/time');
|
return await this.request.get('/v2/public/time');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getSymbols() {
|
||||||
|
return await this.request.get('/v2/public/symbols');
|
||||||
|
}
|
||||||
|
|
||||||
async getTimeOffset() {
|
async getTimeOffset() {
|
||||||
return await this.request.getTimeOffset();
|
return await this.request.getTimeOffset();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user