Skip to content

Commit

Permalink
Merge pull request #293 from tiagosiebler/next
Browse files Browse the repository at this point in the history
v3.7.4: feat(#251, #291) add optional endpoint rate limit parsing, add deprecation warnings for v1/v2 rest clients, improve v5 types, bump dependencies
  • Loading branch information
tiagosiebler authored Oct 30, 2023
2 parents 81ca8a6 + 976a4e8 commit a64b2ca
Show file tree
Hide file tree
Showing 28 changed files with 685 additions and 774 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ const restClientOptions = {

/** Default: true. whether to try and post-process request exceptions. */
parse_exceptions?: boolean;

/** Default: false. Enable to parse/include per-API/endpoint rate limits in responses. */
parseAPIRateLimits?: boolean;

/** Default: false. Enable to throw error if rate limit parser fails */
throwOnFailedRateLimitParse?: boolean;
};

const API_KEY = 'xxx';
Expand Down
905 changes: 341 additions & 564 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bybit-api",
"version": "3.7.3",
"version": "3.7.4",
"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",
Expand Down
30 changes: 17 additions & 13 deletions src/account-asset-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import BaseRestClient from './util/BaseRestClient';

/**
* REST API client for Account Asset APIs
*
* @deprecated WARNING: V1/V2 private endpoints (Rest API & Websocket Stream) for mainnet
* will be switched off gradually from 30 Oct 2023 UTC, so they are not promised a stability.
* Please note that you are at your own risk of using old endpoints going forward, and please move to V5 ASAP.
*/
export class AccountAssetClient extends BaseRestClient {
getClientType() {
Expand All @@ -35,29 +39,29 @@ export class AccountAssetClient extends BaseRestClient {
*/

createInternalTransfer(
params: InternalTransferRequest
params: InternalTransferRequest,
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('/asset/v1/private/transfer', params);
}

createSubAccountTransfer(
params: SubAccountTransferRequest
params: SubAccountTransferRequest,
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('/asset/v1/private/sub-member/transfer', params);
}

getInternalTransfers(
params?: TransferQueryRequest
params?: TransferQueryRequest,
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('/asset/v1/private/transfer/list', params);
}

getSubAccountTransfers(
params?: TransferQueryRequest
params?: TransferQueryRequest,
): Promise<APIResponseWithTime<any>> {
return this.getPrivate(
'/asset/v1/private/sub-member/transfer/list',
params
params,
);
}

Expand All @@ -66,19 +70,19 @@ export class AccountAssetClient extends BaseRestClient {
}

enableUniversalTransfer(
params?: EnableUniversalTransferRequest
params?: EnableUniversalTransferRequest,
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('/asset/v1/private/transferable-subs/save', params);
}

createUniversalTransfer(
params: UniversalTransferRequest
params: UniversalTransferRequest,
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('/asset/v1/private/universal/transfer', params);
}

getUniversalTransfers(
params?: TransferQueryRequest
params?: TransferQueryRequest,
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('/asset/v1/private/universal/transfer/list', params);
}
Expand All @@ -90,19 +94,19 @@ export class AccountAssetClient extends BaseRestClient {
*/

getSupportedDepositList(
params?: SupportedDepositListRequest
params?: SupportedDepositListRequest,
): Promise<APIResponseWithTime<any>> {
return this.get('/asset/v1/public/deposit/allowed-deposit-list', params);
}

getDepositRecords(
params?: DepositRecordsRequest
params?: DepositRecordsRequest,
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('/asset/v1/private/deposit/record/query', params);
}

getWithdrawRecords(
params?: WithdrawalRecordsRequest
params?: WithdrawalRecordsRequest,
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('/asset/v1/private/withdraw/record/query', params);
}
Expand All @@ -112,13 +116,13 @@ export class AccountAssetClient extends BaseRestClient {
}

getAssetInformation(
params?: AccountAssetInformationRequest
params?: AccountAssetInformationRequest,
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('/asset/v1/private/asset-info/query', params);
}

submitWithdrawal(
params: WithdrawalRequest
params: WithdrawalRequest,
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('/asset/v1/private/withdraw', params);
}
Expand Down
68 changes: 36 additions & 32 deletions src/inverse-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import BaseRestClient from './util/BaseRestClient';

/**
* REST API client for Inverse Perpetual Futures APIs (v2)
*
* @deprecated WARNING: V1/V2 private endpoints (Rest API & Websocket Stream) for mainnet
* will be switched off gradually from 30 Oct 2023 UTC, so they are not promised a stability.
* Please note that you are at your own risk of using old endpoints going forward, and please move to V5 ASAP.
*/
export class InverseClient extends BaseRestClient {
getClientType() {
Expand All @@ -54,7 +58,7 @@ export class InverseClient extends BaseRestClient {
}

getKline(
params: SymbolIntervalFromLimitParam
params: SymbolIntervalFromLimitParam,
): Promise<APIResponseWithTime<any[]>> {
return this.get('v2/public/kline/list', params);
}
Expand All @@ -63,7 +67,7 @@ export class InverseClient extends BaseRestClient {
* Get latest information for symbol
*/
getTickers(
params?: Partial<SymbolParam>
params?: Partial<SymbolParam>,
): Promise<APIResponseWithTime<any[]>> {
return this.get('v2/public/tickers', params);
}
Expand All @@ -77,19 +81,19 @@ export class InverseClient extends BaseRestClient {
}

getMarkPriceKline(
params: SymbolIntervalFromLimitParam
params: SymbolIntervalFromLimitParam,
): Promise<APIResponseWithTime<any[]>> {
return this.get('v2/public/mark-price-kline', params);
}

getIndexPriceKline(
params: SymbolIntervalFromLimitParam
params: SymbolIntervalFromLimitParam,
): Promise<APIResponseWithTime<any[]>> {
return this.get('v2/public/index-price-kline', params);
}

getPremiumIndexKline(
params: SymbolIntervalFromLimitParam
params: SymbolIntervalFromLimitParam,
): Promise<APIResponseWithTime<any[]>> {
return this.get('v2/public/premium-index-kline', params);
}
Expand All @@ -101,19 +105,19 @@ export class InverseClient extends BaseRestClient {
*/

getOpenInterest(
params: SymbolPeriodLimitParam
params: SymbolPeriodLimitParam,
): Promise<APIResponseWithTime<any[]>> {
return this.get('v2/public/open-interest', params);
}

getLatestBigDeal(
params: SymbolLimitParam
params: SymbolLimitParam,
): Promise<APIResponseWithTime<any[]>> {
return this.get('v2/public/big-deal', params);
}

getLongShortRatio(
params: SymbolPeriodLimitParam
params: SymbolPeriodLimitParam,
): Promise<APIResponseWithTime<any[]>> {
return this.get('v2/public/account-ratio', params);
}
Expand All @@ -135,25 +139,25 @@ export class InverseClient extends BaseRestClient {
*/

getWalletBalance(
params?: Partial<CoinParam>
params?: Partial<CoinParam>,
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/wallet/balance', params);
}

getWalletFundRecords(
params?: WalletFundRecordsReq
params?: WalletFundRecordsReq,
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/wallet/fund/records', params);
}

getWithdrawRecords(
params?: WithdrawRecordsReq
params?: WithdrawRecordsReq,
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/wallet/withdraw/list', params);
}

getAssetExchangeRecords(
params?: AssetExchangeRecordsReq
params?: AssetExchangeRecordsReq,
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/exchange-order/list', params);
}
Expand Down Expand Up @@ -183,37 +187,37 @@ export class InverseClient extends BaseRestClient {
*/

placeActiveOrder(
orderRequest: InverseOrderRequest
orderRequest: InverseOrderRequest,
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/order/create', orderRequest);
}

getActiveOrderList(
params: InverseActiveOrdersRequest
params: InverseActiveOrdersRequest,
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/order/list', params);
}

cancelActiveOrder(
params: InverseCancelOrderRequest
params: InverseCancelOrderRequest,
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/order/cancel', params);
}

cancelAllActiveOrders(
params: SymbolParam
params: SymbolParam,
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/order/cancelAll', params);
}

replaceActiveOrder(
params: InverseReplaceOrderRequest
params: InverseReplaceOrderRequest,
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/order/replace', params);
}

queryActiveOrder(
params: InverseGetOrderRequest
params: InverseGetOrderRequest,
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/order', params);
}
Expand All @@ -223,38 +227,38 @@ export class InverseClient extends BaseRestClient {
*/

placeConditionalOrder(
params: InverseConditionalOrderRequest
params: InverseConditionalOrderRequest,
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/stop-order/create', params);
}

/** get conditional order list. This may see delays, use queryConditionalOrder() for real-time queries */
getConditionalOrder(
params: InverseActiveConditionalOrderRequest
params: InverseActiveConditionalOrderRequest,
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/stop-order/list', params);
}

cancelConditionalOrder(
params: InverseCancelConditionalOrderRequest
params: InverseCancelConditionalOrderRequest,
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/stop-order/cancel', params);
}

cancelAllConditionalOrders(
params: SymbolParam
params: SymbolParam,
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/stop-order/cancelAll', params);
}

replaceConditionalOrder(
params: InverseReplaceConditionalOrderRequest
params: InverseReplaceConditionalOrderRequest,
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/stop-order/replace', params);
}

queryConditionalOrder(
params: InverseGetOrderRequest
params: InverseGetOrderRequest,
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/stop-order', params);
}
Expand All @@ -264,49 +268,49 @@ export class InverseClient extends BaseRestClient {
*/

getPosition(
params?: Partial<SymbolParam>
params?: Partial<SymbolParam>,
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/position/list', params);
}

changePositionMargin(
params: InverseChangePositionMarginRequest
params: InverseChangePositionMarginRequest,
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('position/change-position-margin', params);
}

setTradingStop(
params: InverseSetTradingStopRequest
params: InverseSetTradingStopRequest,
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/position/trading-stop', params);
}

setUserLeverage(
params: InverseSetLeverageRequest
params: InverseSetLeverageRequest,
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/position/leverage/save', params);
}

getTradeRecords(
params: InverseGetTradeRecordsRequest
params: InverseGetTradeRecordsRequest,
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/execution/list', params);
}

getClosedPnl(
params: InverseGetClosedPnlRequest
params: InverseGetClosedPnlRequest,
): Promise<APIResponseWithTime<any>> {
return this.getPrivate('v2/private/trade/closed-pnl/list', params);
}

setSlTpPositionMode(
params: InverseSetSlTpPositionModeRequest
params: InverseSetSlTpPositionModeRequest,
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/tpsl/switch-mode', params);
}

setMarginType(
params: InverseSetMarginTypeRequest
params: InverseSetMarginTypeRequest,
): Promise<APIResponseWithTime<any>> {
return this.postPrivate('v2/private/position/switch-isolated', params);
}
Expand Down
Loading

0 comments on commit a64b2ca

Please sign in to comment.