From bd10bd9e637298819eebd9296457373571bca40b Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Tue, 7 May 2024 13:10:12 +0100 Subject: [PATCH 1/2] v3.10.3: feat(#340) fix pass-through headers for proxying via nginx. add second proxy example. --- examples/rest-v5-proxies.ts | 5 ++++ examples/rest-v5-proxies2.ts | 54 ++++++++++++++++++++++++++++++++++++ package-lock.json | 4 +-- package.json | 2 +- src/util/BaseRestClient.ts | 1 + tea.yaml | 5 ++++ 6 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 examples/rest-v5-proxies2.ts create mode 100644 tea.yaml diff --git a/examples/rest-v5-proxies.ts b/examples/rest-v5-proxies.ts index 89a2c7a..ed89109 100644 --- a/examples/rest-v5-proxies.ts +++ b/examples/rest-v5-proxies.ts @@ -17,7 +17,12 @@ const client = new RestClientV5( // recv_window: 10000, }, { + /** + * Axios has a native way of supporting http/https proxies. It works for most proxy services but not all. + * If you have issues making any proxied requests this way, take a look at the rest-v5-proxies2.ts example using the https-proxy-agent. + */ proxy: { + protocol: 'http', // or 'https' host: 'proxyhost', port: Number('proxyport'), auth: { diff --git a/examples/rest-v5-proxies2.ts b/examples/rest-v5-proxies2.ts new file mode 100644 index 0000000..423b199 --- /dev/null +++ b/examples/rest-v5-proxies2.ts @@ -0,0 +1,54 @@ +// @ts-ignore +import { HttpsProxyAgent } from 'https-proxy-agent'; + +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; + +/** + * Some proxy services don't work with the proxy configuration that axios supports. + * + * For these, you can try using HttpsProxyAgent or SocksProxyAgent (depending on your proxy type, HTTP or SOCKS). + * + * The following example uses the HttpsProxyAgent (via the npm module https-proxy-agent). + */ + +const proxyDetails = { + user: 'yourProxyUser', + pass: 'yourProxyPassword', + host: '127.0.0.1', + port: 31413, +}; + +const proxyURL = `http://${proxyDetails.user}:${proxyDetails.pass}@${proxyDetails.host}:${proxyDetails.port}`; +const proxyAgent = new HttpsProxyAgent(proxyURL); + +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, + }, + { + httpAgent: proxyAgent, + httpsAgent: proxyAgent, + }, +); + +(async () => { + try { + const res = await client.getWalletBalance({ accountType: 'UNIFIED' }); + + console.log('response: ', JSON.stringify(res, null, 2)); + } catch (e) { + console.error('request failed: ', e); + } +})(); diff --git a/package-lock.json b/package-lock.json index 941c4f5..19b85ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bybit-api", - "version": "3.10.1", + "version": "3.10.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "bybit-api", - "version": "3.10.1", + "version": "3.10.3", "license": "MIT", "dependencies": { "axios": "^1.6.6", diff --git a/package.json b/package.json index 77b759b..67a5d68 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bybit-api", - "version": "3.10.2", + "version": "3.10.3", "description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/util/BaseRestClient.ts b/src/util/BaseRestClient.ts index 74ba654..515ee93 100644 --- a/src/util/BaseRestClient.ts +++ b/src/util/BaseRestClient.ts @@ -132,6 +132,7 @@ export default abstract class BaseRestClient { // custom request options based on axios specs - see: https://github.com/axios/axios#request-config ...networkOptions, headers: { + ...networkOptions.headers, 'x-referer': APIID, }, }; diff --git a/tea.yaml b/tea.yaml new file mode 100644 index 0000000..60166ee --- /dev/null +++ b/tea.yaml @@ -0,0 +1,5 @@ +--- +version: 1.0.0 +codeOwners: + - '0xeb1a7BF44a801e33a339705A266Afc0Cba3D6D54' +quorum: 1 From d4ebc8227c393512052b25da24103a7bc1ae6a08 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Tue, 7 May 2024 13:15:46 +0100 Subject: [PATCH 2/2] feat(#339): add longshort ratio v5 method --- src/rest-client-v5.ts | 8 ++++++++ src/types/request/v5-market.ts | 7 +++++++ src/types/response/v5-market.ts | 9 ++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/rest-client-v5.ts b/src/rest-client-v5.ts index 0fdc302..d053fb4 100644 --- a/src/rest-client-v5.ts +++ b/src/rest-client-v5.ts @@ -69,6 +69,7 @@ import { GetInternalDepositRecordParamsV5, GetInternalTransferParamsV5, GetKlineParamsV5, + GetLongShortRatioParamsV5, GetMarkPriceKlineParamsV5, GetOpenInterestParamsV5, GetOptionDeliveryPriceParamsV5, @@ -94,6 +95,7 @@ import { InternalTransferRecordV5, LeverageTokenInfoV5, LeveragedTokenMarketResultV5, + LongShortRatioV5, MMPModifyParamsV5, MMPStateV5, OHLCKlineV5, @@ -390,6 +392,12 @@ export class RestClientV5 extends BaseRestClient { return this.get('/v5/market/delivery-price', params); } + getLongShortRatio( + params: GetLongShortRatioParamsV5, + ): Promise> { + return this.get('/v5/market/account-ratio', params); + } + /** * ****** Trade APIs diff --git a/src/types/request/v5-market.ts b/src/types/request/v5-market.ts index 9e836b7..0619a32 100644 --- a/src/types/request/v5-market.ts +++ b/src/types/request/v5-market.ts @@ -125,3 +125,10 @@ export interface GetDeliveryPriceParamsV5 { limit?: number; cursor?: string; } + +export interface GetLongShortRatioParamsV5 { + category: 'linear' | 'inverse'; + symbol: string; + period: OpenInterestIntervalV5; + limit?: number; +} diff --git a/src/types/response/v5-market.ts b/src/types/response/v5-market.ts index b121e29..4a40982 100644 --- a/src/types/response/v5-market.ts +++ b/src/types/response/v5-market.ts @@ -120,7 +120,7 @@ export interface SpotInstrumentInfoV5 { riskParameters: { limitParameter: string; marketParameter: string; - } + }; } type InstrumentInfoV5Mapping = { @@ -290,3 +290,10 @@ export interface DeliveryPriceV5 { deliveryPrice: string; deliveryTime: string; } + +export interface LongShortRatioV5 { + symbol: string; + buyRatio: string; + sellRatio: string; + timestamp: string; +}