From af8b3f3e8262518e5ad9c94c5034035fe1e55371 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Wed, 7 Jun 2023 11:39:59 +0100 Subject: [PATCH] feat(): start adding per-endpoint examples --- examples/apidoc/README.md | 3 ++ examples/apidoc/V5/Trade/amend-order.js | 25 ++++++++++++ examples/apidoc/V5/Trade/batch-amend-order.js | 27 +++++++++++++ .../apidoc/V5/Trade/batch-cancel-order.js | 25 ++++++++++++ examples/apidoc/V5/Trade/batch-place-order.js | 39 +++++++++++++++++++ examples/apidoc/V5/Trade/cancel-all-orders.js | 19 +++++++++ examples/apidoc/V5/Trade/cancel-order.js | 20 ++++++++++ examples/apidoc/V5/Trade/get-open-orders.js | 21 ++++++++++ examples/apidoc/V5/Trade/get-order-history.js | 19 +++++++++ .../apidoc/V5/Trade/get-spot-borrow-quota.js | 16 ++++++++ examples/apidoc/V5/Trade/place-order.js | 27 +++++++++++++ examples/apidoc/V5/Trade/set-dcp.js | 16 ++++++++ examples/rest-linear-public.ts | 23 +++++++++++ 13 files changed, 280 insertions(+) create mode 100644 examples/apidoc/README.md create mode 100644 examples/apidoc/V5/Trade/amend-order.js create mode 100644 examples/apidoc/V5/Trade/batch-amend-order.js create mode 100644 examples/apidoc/V5/Trade/batch-cancel-order.js create mode 100644 examples/apidoc/V5/Trade/batch-place-order.js create mode 100644 examples/apidoc/V5/Trade/cancel-all-orders.js create mode 100644 examples/apidoc/V5/Trade/cancel-order.js create mode 100644 examples/apidoc/V5/Trade/get-open-orders.js create mode 100644 examples/apidoc/V5/Trade/get-order-history.js create mode 100644 examples/apidoc/V5/Trade/get-spot-borrow-quota.js create mode 100644 examples/apidoc/V5/Trade/place-order.js create mode 100644 examples/apidoc/V5/Trade/set-dcp.js create mode 100644 examples/rest-linear-public.ts diff --git a/examples/apidoc/README.md b/examples/apidoc/README.md new file mode 100644 index 0000000..9c4c6e9 --- /dev/null +++ b/examples/apidoc/README.md @@ -0,0 +1,3 @@ +# API Doc Examples + +These are per-endpoint JavaScript examples also found in Bybit's API documentation website, demonstrating how to interact with each endpoint with the Node.js SDK. diff --git a/examples/apidoc/V5/Trade/amend-order.js b/examples/apidoc/V5/Trade/amend-order.js new file mode 100644 index 0000000..522a539 --- /dev/null +++ b/examples/apidoc/V5/Trade/amend-order.js @@ -0,0 +1,25 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .submitOrder({ + category: 'linear', + symbol: 'ETHPERP', + orderLinkId: 'linear-004', + triggerPrice: '1145', + qty: '0.15', + price: '1050', + takeProfit: '0', + stopLoss: '0', + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/Trade/batch-amend-order.js b/examples/apidoc/V5/Trade/batch-amend-order.js new file mode 100644 index 0000000..b5c2341 --- /dev/null +++ b/examples/apidoc/V5/Trade/batch-amend-order.js @@ -0,0 +1,27 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .batchAmendOrders('option', [ + { + symbol: 'ETH-30DEC22-500-C', + orderIv: '6.8', + orderId: 'b551f227-7059-4fb5-a6a6-699c04dbd2f2', + }, + { + symbol: 'ETH-30DEC22-700-C', + price: '650', + orderId: 'fa6a595f-1a57-483f-b9d3-30e9c8235a52', + }, + ]) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/Trade/batch-cancel-order.js b/examples/apidoc/V5/Trade/batch-cancel-order.js new file mode 100644 index 0000000..25411f7 --- /dev/null +++ b/examples/apidoc/V5/Trade/batch-cancel-order.js @@ -0,0 +1,25 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .batchCancelOrders('option', [ + { + symbol: 'ETH-30DEC22-500-C', + orderId: 'b551f227-7059-4fb5-a6a6-699c04dbd2f2', + }, + { + symbol: 'ETH-30DEC22-700-C', + orderId: 'fa6a595f-1a57-483f-b9d3-30e9c8235a52', + }, + ]) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/Trade/batch-place-order.js b/examples/apidoc/V5/Trade/batch-place-order.js new file mode 100644 index 0000000..70ed808 --- /dev/null +++ b/examples/apidoc/V5/Trade/batch-place-order.js @@ -0,0 +1,39 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .batchSubmitOrders('option', [ + { + symbol: 'ETH-30DEC22-500-C', + orderType: 'Limit', + side: 'Buy', + qty: '1', + orderIv: '6', + timeInForce: 'GTC', + orderLinkId: 'option-test-001', + mmp: false, + reduceOnly: false, + }, + { + symbol: 'ETH-30DEC22-700-C', + orderType: 'Limit', + side: 'Sell', + qty: '2', + price: '700', + timeInForce: 'GTC', + orderLinkId: 'option-test-001', + mmp: false, + reduceOnly: false, + }, + ]) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/Trade/cancel-all-orders.js b/examples/apidoc/V5/Trade/cancel-all-orders.js new file mode 100644 index 0000000..ab425df --- /dev/null +++ b/examples/apidoc/V5/Trade/cancel-all-orders.js @@ -0,0 +1,19 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .cancelAllOrders({ + category: 'linear', + settleCoin: 'USDT', + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/Trade/cancel-order.js b/examples/apidoc/V5/Trade/cancel-order.js new file mode 100644 index 0000000..92d4340 --- /dev/null +++ b/examples/apidoc/V5/Trade/cancel-order.js @@ -0,0 +1,20 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .cancelOrder({ + category: 'linear', + symbol: 'BTCPERP', + orderId: 'c6f055d9-7f21-4079-913d-e6523a9cfffa', + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/Trade/get-open-orders.js b/examples/apidoc/V5/Trade/get-open-orders.js new file mode 100644 index 0000000..8cdba88 --- /dev/null +++ b/examples/apidoc/V5/Trade/get-open-orders.js @@ -0,0 +1,21 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .getActiveOrders({ + category: 'linear', + symbol: 'ETHUSDT', + openOnly: 0, + limit: 1, + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/Trade/get-order-history.js b/examples/apidoc/V5/Trade/get-order-history.js new file mode 100644 index 0000000..cabfb1e --- /dev/null +++ b/examples/apidoc/V5/Trade/get-order-history.js @@ -0,0 +1,19 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .getHistoricOrders({ + category: 'linear', + limit: 1, + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/Trade/get-spot-borrow-quota.js b/examples/apidoc/V5/Trade/get-spot-borrow-quota.js new file mode 100644 index 0000000..99c0168 --- /dev/null +++ b/examples/apidoc/V5/Trade/get-spot-borrow-quota.js @@ -0,0 +1,16 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .getSpotBorrowCheck('BTCUSDT', 'Buy') + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/Trade/place-order.js b/examples/apidoc/V5/Trade/place-order.js new file mode 100644 index 0000000..1cba6bb --- /dev/null +++ b/examples/apidoc/V5/Trade/place-order.js @@ -0,0 +1,27 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .submitOrder({ + category: 'spot', + symbol: 'BTCUSDT', + side: 'Buy', + orderType: 'Market', + qty: '0.1', + price: '15600', + timeInForce: 'PostOnly', + orderLinkId: 'spot-test-postonly', + isLeverage: 0, + orderFilter: 'Order', + }) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/V5/Trade/set-dcp.js b/examples/apidoc/V5/Trade/set-dcp.js new file mode 100644 index 0000000..3387780 --- /dev/null +++ b/examples/apidoc/V5/Trade/set-dcp.js @@ -0,0 +1,16 @@ +const { RestClientV5 } = require('bybit-api'); + +const client = new RestClientV5({ + testnet: true, + key: 'apikey', + secret: 'apisecret', +}); + +client + .setDisconnectCancelAllWindow('option', 40) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/rest-linear-public.ts b/examples/rest-linear-public.ts new file mode 100644 index 0000000..84f4df4 --- /dev/null +++ b/examples/rest-linear-public.ts @@ -0,0 +1,23 @@ +import { LinearClient } from '../src/index'; + +// or +// import { LinearClient } from 'bybit-api'; + +const client = new LinearClient(); + +(async () => { + try { + // console.log('getSymbols: ', await client.getSymbols()); + // console.log('getOrderBook: ', await client.getOrderBook(symbol)); + console.log( + 'getKline: ', + await client.getKline({ + symbol: 'ETHUSDT', + interval: 'D', + from: 1, + }), + ); + } catch (e) { + console.error('request failed: ', e); + } +})();