bitmart-api
Version:
Complete & robust Node.js SDK for BitMart's REST APIs and WebSockets, with TypeScript declarations.
532 lines • 17.7 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RestClient = void 0;
const BaseRestClient_js_1 = require("./lib/BaseRestClient.js");
/**
* Unified REST API client for all of Bitmart's REST APIs
*
* Note: for futures V2 APIs, use the `FuturesClientV2` class instead (which maps to a different base URL)
*/
class RestClient extends BaseRestClient_js_1.BaseRestClient {
constructor(restClientOptions = {}, requestOptions = {}) {
super(restClientOptions, requestOptions);
return this;
}
getClientType() {
return BaseRestClient_js_1.REST_CLIENT_TYPE_ENUM.mainV1;
}
/**
*
* Custom SDK functions
*
*/
/**
* This method is used to get the latency and time sync between the client and the server.
* This is not official API endpoint and is only used for internal testing purposes.
* Use this method to check the latency and time sync between the client and the server.
* Final values might vary slightly, but it should be within few ms difference.
* If you have any suggestions or improvements to this measurement, please create an issue or pull request on GitHub.
*/
async fetchLatencySummary() {
const clientTimeReqStart = Date.now();
const serverTime = await this.getSystemTime();
const clientTimeReqEnd = Date.now();
console.log('serverTime', serverTime);
const serverTimeMs = Number(serverTime.data.server_time);
const roundTripTime = clientTimeReqEnd - clientTimeReqStart;
const estimatedOneWayLatency = Math.floor(roundTripTime / 2);
// Adjust server time by adding estimated one-way latency
const adjustedServerTime = serverTimeMs + estimatedOneWayLatency;
// Calculate time difference between adjusted server time and local time
const timeDifference = adjustedServerTime - clientTimeReqEnd;
const result = {
localTime: clientTimeReqEnd,
serverTime: serverTimeMs,
roundTripTime,
estimatedOneWayLatency,
adjustedServerTime,
timeDifference,
};
console.log('Time synchronization results:');
console.log(result);
console.log(`Your approximate latency to exchange server:
One way: ${estimatedOneWayLatency}ms.
Round trip: ${roundTripTime}ms.
`);
if (Math.abs(timeDifference) > 500) {
console.warn(`WARNING! Time difference between server and client clock is greater than 500ms. It is currently ${timeDifference}ms.
Consider adjusting your system clock to avoid unwanted clock sync errors!
Visit https://github.com/tiagosiebler/awesome-crypto-examples/wiki/Timestamp-for-this-request-is-outside-of-the-recvWindow for more information`);
}
else {
console.log(`Time difference between server and client clock is within acceptable range of 500ms. It is currently ${timeDifference}ms.`);
}
return result;
}
/**
*
* System Status Endpoints
*
**/
getSystemTime() {
return this.get('system/time');
}
getSystemStatus() {
return this.get('system/service');
}
/**
*
* Public Market Data Endpoints
*
**/
getSpotCurrenciesV1() {
return this.get('spot/v1/currencies');
}
getSpotTradingPairsV1() {
return this.get('spot/v1/symbols');
}
getSpotTradingPairDetailsV1() {
return this.get('spot/v1/symbols/details');
}
getSpotTickersV3() {
return this.get('spot/quotation/v3/tickers');
}
getSpotTickerV3(params) {
return this.get('spot/quotation/v3/ticker', params);
}
getSpotLatestKlineV3(params) {
return this.get('spot/quotation/v3/lite-klines', params);
}
getSpotHistoryKlineV3(params) {
return this.get('spot/quotation/v3/klines', params);
}
getSpotOrderBookDepthV3(params) {
return this.get('spot/quotation/v3/books', params);
}
getSpotRecentTrades(params) {
return this.get('spot/quotation/v3/trades', params);
}
/**
*
* Public Market Data Endpoints (History Version)
*
**/
/**
* @deprecated , use V3 or V4 instead
*/
getSpotTickersV2() {
return this.get('spot/v2/ticker');
}
/**
* @deprecated , use V3 or V4 instead
*/
getSpotTickerV1(params) {
return this.get('spot/v1/ticker_detail', params);
}
/**
* @deprecated , use V3 or V4 instead
*/
getSpotKLineStepsV1() {
return this.get('spot/v1/steps');
}
/**
* @deprecated , use V3 or V4 instead
*/
getSpotKlinesV1(params) {
return this.get('spot/v1/symbols/kline', params);
}
/**
* @deprecated , use V3 or V4 instead
*/
getSpotOrderBookDepthV1(params) {
return this.get('spot/v1/symbols/book', params);
}
/**
*
* Funding Account Endpoints
*
**/
getAccountBalancesV1(params) {
return this.getPrivate('account/v1/wallet', params);
}
getAccountCurrenciesV1(params) {
return this.get('account/v1/currencies', params);
}
getSpotWalletBalanceV1() {
return this.getPrivate('spot/v1/wallet');
}
getAccountDepositAddressV1(params) {
return this.getPrivate('account/v1/deposit/address', params);
}
getAccountWithdrawQuotaV1(params) {
return this.getPrivate('account/v1/withdraw/charge', params);
}
submitWithdrawalV1(params) {
return this.postPrivate('account/v1/withdraw/apply', params);
}
getWithdrawAddressList() {
return this.getPrivate('account/v1/withdraw/address/list');
}
getDepositWithdrawHistoryV2(params) {
return this.getPrivate('account/v2/deposit-withdraw/history', params);
}
getDepositWithdrawDetailV1(params) {
return this.getPrivate('account/v1/deposit-withdraw/detail', params);
}
getMarginAccountDetailsV1(params) {
return this.getPrivate('spot/v1/margin/isolated/account', params);
}
submitMarginAssetTransferV1(params) {
return this.postPrivate('spot/v1/margin/isolated/transfer', params);
}
getBasicSpotFeeRateV1() {
return this.getPrivate('spot/v1/user_fee');
}
getActualSpotTradeFeeRateV1(params) {
return this.getPrivate('spot/v1/trade_fee', params);
}
/**
*
* Spot/Margin Trading Endpoints
*
**/
submitSpotOrderV2(params) {
return this.postPrivate('spot/v2/submit_order', params);
}
submitMarginOrderV1(params) {
return this.postPrivate('spot/v1/margin/submit_order', params);
}
/**
* @deprecated , use V3 or V4 instead
*/
submitSpotBatchOrdersV2(params) {
return this.postPrivate('spot/v2/batch_orders', params);
}
cancelSpotOrderV3(params) {
return this.postPrivate('spot/v3/cancel_order', params);
}
submitSpotBatchOrdersV4(params) {
return this.postPrivate('spot/v4/batch_orders', params);
}
/**
* Cancel batch orders (v4)
*/
cancelSpotBatchOrdersV4(params) {
return this.postPrivate('spot/v4/cancel_orders', params);
}
cancelAllSpotOrders(params) {
return this.postPrivate('spot/v4/cancel_all', params);
}
/**
* @deprecated , use V3 or V4 instead
*/
cancelSpotOrdersV1(params) {
return this.postPrivate('spot/v1/cancel_orders', params);
}
/**
* Query a spot order by order ID
*/
getSpotOrderByIdV4(params) {
return this.postPrivate('spot/v4/query/order', params);
}
/**
* Query a spot order by client order ID
*/
getSpotOrderByClientOrderIdV4(params) {
return this.postPrivate('spot/v4/query/client-order', params);
}
getSpotOpenOrdersV4(params) {
return this.postPrivate('spot/v4/query/open-orders', params);
}
getSpotHistoricOrdersV4(params) {
return this.postPrivate('spot/v4/query/history-orders', params);
}
/**
* Account Trade List(v4)
*/
getSpotAccountTradesV4(params) {
return this.postPrivate('spot/v4/query/trades', params);
}
/**
* Get all transaction records for a single order
*/
getSpotAccountOrderTradesV4(params) {
return this.postPrivate('spot/v4/query/order-trades', params);
}
/**
*
* Margin Loan Endpoints (History versions)
*
**/
marginBorrowV1(params) {
return this.postPrivate('spot/v1/margin/isolated/borrow', params);
}
marginRepayV1(params) {
return this.postPrivate('spot/v1/margin/isolated/repay', params);
}
getMarginBorrowRecordV1(params) {
return this.getPrivate('spot/v1/margin/isolated/borrow_record', params);
}
getMarginRepayRecordV1(params) {
return this.getPrivate('spot/v1/margin/isolated/repay_record', params);
}
/**
* Get Trading Pair Borrowing Rate and Amount
*/
getMarginBorrowingRatesV1(params) {
return this.getPrivate('spot/v1/margin/isolated/pairs', params);
}
/**
*
* Subaccount Endpoints
*
**/
/**
* Sub-Account to Main-Account (For Main Account)
*/
submitMainTransferSubToMainV1(params) {
return this.postPrivate('account/sub-account/main/v1/sub-to-main', params);
}
/**
* Sub-Account to Main-Account (For Sub-Account)
*/
submitSubTransferSubToMainV1(params) {
return this.postPrivate('account/sub-account/sub/v1/sub-to-main', params);
}
submitMainTransferMainToSubV1(params) {
return this.postPrivate('account/sub-account/main/v1/main-to-sub', params);
}
submitMainTransferSubToSubV1(params) {
return this.postPrivate('account/sub-account/main/v1/sub-to-sub', params);
}
submitSubTransferSubToSubV1(params) {
return this.postPrivate('account/sub-account/sub/v1/sub-to-sub', params);
}
getSubTransfersV1(params) {
return this.getPrivate('account/sub-account/main/v1/transfer-list', params);
}
getAccountSubTransfersV1(params) {
return this.getPrivate('account/sub-account/v1/transfer-history', params);
}
getSubSpotWalletBalancesV1(params) {
return this.getPrivate('account/sub-account/main/v1/wallet', params);
}
getSubAccountsV1() {
return this.getPrivate('account/sub-account/main/v1/subaccount-list');
}
/**
*
*****************
* USD-M Futures *
*****************
*
*/
/**
*
* Futures Market Data
*
*/
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
getFuturesContractDetails(params) {
return this.get('contract/public/details', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
getFuturesContractDepth(params) {
return this.get('contract/public/depth', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
getFuturesOpenInterest(params) {
return this.get('contract/public/open-interest', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
getFuturesFundingRate(params) {
return this.get('contract/public/funding-rate', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
getFuturesKlines(params) {
return this.get('contract/public/kline', params);
}
/**
*
* Futures Account Data
*
*/
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
getFuturesAccountAssets() {
return this.getPrivate('contract/private/assets-detail');
}
/**
*
* Futures Trading
*
*/
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
getFuturesAccountOrder(params) {
return this.getPrivate('contract/private/order', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
getFuturesAccountOrderHistory(params) {
return this.getPrivate('contract/private/order-history', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
getFuturesAccountOpenOrders(params) {
return this.getPrivate('contract/private/get-open-orders', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
getFuturesAccountPlanOrders(params) {
return this.getPrivate('contract/private/current-plan-order', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
getFuturesAccountPositions(params) {
return this.getPrivate('contract/private/position', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
getPositionRiskDetails(params) {
return this.getPrivate('contract/private/position-risk', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
getFuturesAccountTrades(params) {
return this.getPrivate('contract/private/trades', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
getFuturesTransfers(params) {
return this.getPrivate('account/v1/transfer-contract-list', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
submitFuturesOrder(params) {
return this.postPrivate('contract/private/submit-order', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/ cancelFuturesOrder(params) {
return this.postPrivate('contract/private/cancel-order', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
cancelAllFuturesOrders(params) {
return this.postPrivate('contract/private/cancel-orders', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
submitFuturesPlanOrder(params) {
return this.postPrivate('contract/private/submit-plan-order', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
cancelFuturesPlanOrder(params) {
return this.postPrivate('contract/private/cancel-plan-order', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
submitFuturesTransfer(params) {
return this.postPrivate('account/v1/transfer-contract', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
setFuturesLeverage(params) {
return this.postPrivate('contract/private/submit-leverage', params);
}
/**
*
* Futures Sub-Account Endpoints
*
*/
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
submitFuturesSubToMainTransferFromMain(params) {
return this.postPrivate('account/contract/sub-account/main/v1/sub-to-main', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
submitFuturesMainToSubTransferFromMain(params) {
return this.postPrivate('account/contract/sub-account/main/v1/main-to-sub', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
submitFuturesSubToMainSubFromSub(params) {
return this.postPrivate('account/contract/sub-account/sub/v1/sub-to-main', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
getFuturesSubWallet(params) {
return this.getPrivate('account/contract/sub-account/main/v1/wallet', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
getFuturesSubTransfers(params) {
return this.getPrivate('account/contract/sub-account/main/v1/transfer-list', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
getFuturesSubTransferHistory(params) {
return this.getPrivate('account/contract/sub-account/v1/transfer-history', params);
}
/**
*
* Futures Affiliate Endpoints
*
*/
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
getFuturesAffiliateRebates(params) {
return this.getPrivate('contract/private/affiliate/rebate-list', params);
}
/**
* @deprecated Use the FuturesClientV2 instead, it uses the new V2 domain & endpoint
*/
getFuturesAffiliateTrades(params) {
return this.getPrivate('contract/private/affiliate/trade-list', params);
}
/**
*
* API Broker Endpoints
*
**/
getBrokerRebate(params) {
return this.getPrivate('spot/v1/broker/rebate', params);
}
}
exports.RestClient = RestClient;
//# sourceMappingURL=RestClient.js.map