feat(#186): add proxy & rate limits example. Misc doc updates.

This commit is contained in:
tiagosiebler
2023-12-22 11:47:54 +00:00
parent 923b1b02e0
commit 48eaa4785d
17 changed files with 216 additions and 68 deletions

View File

@@ -0,0 +1,5 @@
# Deprecated Examples
The examples in this folder use old/deprecated/obsolete APIs. They should all have a modern alternative.
As of December 2023, use the V5 APIs & WebSockets.

View File

@@ -1,4 +1,4 @@
import { ContractClient } from '../src/index';
import { ContractClient } from '../../src/index';
// or
// import { ContractClient } from 'bybit-api';

View File

@@ -3,7 +3,7 @@
*/
// For testing with the repo directly, import from the src folder
import { ContractClient } from '../src';
import { ContractClient } from '../../src';
// or, use the version installed with npm
// import { ContractClient } from 'bybit-api';

View File

@@ -1,4 +1,4 @@
import { CopyTradingClient } from '../src/index';
import { CopyTradingClient } from '../../src/index';
// or
// import { CopyTradingClient } from 'bybit-api';

View File

@@ -1,4 +1,4 @@
import { LinearClient } from '../src/index';
import { LinearClient } from '../../src/index';
// or
// import { LinearClient } from 'bybit-api';

View File

@@ -1,4 +1,4 @@
import { ContractClient } from '../src/index';
import { ContractClient } from '../../src/index';
// or
// import { ContractClient } from 'bybit-api';

View File

@@ -1,4 +1,4 @@
import { SpotClientV3 } from '../src/index';
import { SpotClientV3 } from '../../src/index';
// or
// import { SpotClientV3 } from 'bybit-api';

View File

@@ -1,4 +1,4 @@
import { SpotClientV3 } from '../src/index';
import { SpotClientV3 } from '../../src/index';
// or
// import { SpotClientV3 } from 'bybit-api';
@@ -25,7 +25,7 @@ const client = new SpotClientV3({
symbol,
orderId,
ordersPerPage,
0
0,
);
console.log('normal orders:', normalOrders);
@@ -33,7 +33,7 @@ const client = new SpotClientV3({
symbol,
orderId,
ordersPerPage,
1
1,
);
console.log('tpSlOrders:', tpSlOrders);
} catch (e) {

View File

@@ -1,4 +1,4 @@
import { UnifiedMarginClient } from '../src/index';
import { UnifiedMarginClient } from '../../src/index';
// or
// import { UnifiedMarginClient } from 'bybit-api';
@@ -36,7 +36,7 @@ const client = new UnifiedMarginClient({
});
console.log(
'both to compare:',
JSON.stringify(historicOrdersBoth, null, 2)
JSON.stringify(historicOrdersBoth, null, 2),
);
} catch (e) {
console.error('request failed: ', e);

View File

@@ -1,4 +1,4 @@
import { UnifiedMarginClient } from '../src/index';
import { UnifiedMarginClient } from '../../src/index';
// or
// import { UnifiedMarginClient } from 'bybit-api';

View File

@@ -1,7 +1,7 @@
/* eslint-disable no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-empty-function */
import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../src';
import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../../src';
// or
// import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from 'bybit-api';

View File

@@ -1,7 +1,7 @@
/* eslint-disable no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-empty-function */
import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../src';
import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../../src';
// or
// import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from 'bybit-api';

View File

@@ -1,4 +1,4 @@
import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../src';
import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../../src';
// or
// import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from 'bybit-api';
@@ -22,7 +22,7 @@ const wsClient = new WebsocketClient(
// market: 'unifiedOption',
market: 'contractUSDT',
},
logger
logger,
);
wsClient.on('update', (data) => {

View File

@@ -0,0 +1,66 @@
import { RestClientV5 } from '../src/index';
// or
// import { RestClientV5 } from 'bybit-api';
const key = process.env.API_KEY_COM;
const secret = process.env.API_SECRET_COM;
const client = new RestClientV5(
{
key: key,
secret: secret,
parseAPIRateLimits: true,
testnet: true,
// Sometimes using a proxy introduces recv timestamp errors (due to the extra latency)
// If that happens, you can try increasing the recv window (which is 5000ms by default)
// recv_window: 10000,
},
{
proxy: {
host: 'proxyhost',
port: Number('proxyport'),
auth: {
username: 'proxyuserifneeded',
password: 'proxypassifneeded',
},
},
},
);
(async () => {
try {
const res = await client.getWalletBalance({ accountType: 'UNIFIED' });
console.log('response: ', JSON.stringify(res, null, 2));
// const orders = await client.batchSubmitOrders('linear', [
// {
// symbol: 'ETHUSDT',
// orderType: 'Limit',
// side: 'Buy',
// qty: '1',
// orderIv: '6',
// timeInForce: 'GTC',
// orderLinkId: 'option-test-001',
// mmp: false,
// reduceOnly: false,
// },
// {
// symbol: 'ETHUSDT',
// orderType: 'Limit',
// side: 'Sell',
// qty: '2',
// price: '700',
// timeInForce: 'GTC',
// orderLinkId: 'option-test-001',
// mmp: false,
// reduceOnly: false,
// },
// ]);
// console.log('orders: ', JSON.stringify(orders, null, 2));
} catch (e) {
console.error('request failed: ', e);
}
})();

View File

@@ -0,0 +1,66 @@
import {
APIResponseV3WithTime,
CategoryListV5,
RestClientV5,
TickerLinearInverseV5,
} from '../src/index';
// or
// import { RestClientV5 } from 'bybit-api';
/**
* If you don't plan on making any private api calls,
* you can instance the REST client without any parameters
*/
const client = new RestClientV5();
(async () => {
try {
// const klineResult = await client.getKline({
// category: 'linear',
// interval: '15',
// symbol: 'BTCUSDT',
// });
// console.log('klineResult: ', klineResult);
// const markPriceKlineResult = await client.getMarkPriceKline({
// category: 'linear',
// interval: '15',
// symbol: 'BTCUSDT',
// });
// console.log('markPriceKlineResult: ', markPriceKlineResult);
// const indexPriceKline = await client.getIndexPriceKline({
// category: 'linear',
// interval: '15',
// symbol: 'BTCUSDT',
// });
// console.log('indexPriceKline: ', indexPriceKline);
// const openInterest = await client.getOpenInterest({
// category: 'linear',
// symbol: 'BTCUSDT',
// intervalTime: '5min',
// });
const tickers = await client.getTickers({ category: 'linear' });
// console.log(
// JSON.stringify(
// tickers.result.list.map((ticker) => ticker.symbol),
// null,
// 2,
// ),
// );
console.log('response', tickers);
// openInterest.result.list.forEach((row) => {
// console.log('int: ', {
// timestamp: row.timestamp,
// value: row.openInterest,
// });
// });
// console.log('openInterest: ', openInterest.result.list);
} catch (e) {
console.error('request failed: ', e);
}
})();