feat(): start adding per-endpoint examples

This commit is contained in:
tiagosiebler
2023-06-07 11:39:59 +01:00
parent d79a09a184
commit af8b3f3e82
13 changed files with 280 additions and 0 deletions

View File

@@ -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.

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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);
});

View File

@@ -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);
});