UNPKG

bitget-api

Version:

Complete Node.js & JavaScript SDK for Bitget V1-V3 REST APIs & WebSockets, with TypeScript & end-to-end tests.

906 lines 26.2 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RestClientV3 = void 0; const BaseRestClient_js_1 = __importDefault(require("./util/BaseRestClient.js")); const requestUtils_js_1 = require("./util/requestUtils.js"); /** * REST API client for all V3 endpoints */ class RestClientV3 extends BaseRestClient_js_1.default { getClientType() { return requestUtils_js_1.REST_CLIENT_TYPE_ENUM.v3; } /** * * 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.getServerTime(); const clientTimeReqEnd = Date.now(); console.log('serverTime', serverTime); const serverTimeMs = Number(serverTime.data.serverTime); 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 (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; } async fetchServerTime() { const res = await this.getServerTime(); return Number(res.data.serverTime); } /** * * Public endpoints * */ getServerTime() { return this.get('/api/v3/public/time'); } /** * * =====Market======= endpoints * */ /** * Get Instruments */ getInstruments(params) { return this.get('/api/v3/market/instruments', params); } /** * Get Market Maker Fee Group - Query fee rate tiers and grouping */ getMarketFeeGroup(params) { return this.get('/api/v3/market/fee-group', params); } /** * Get Market Maker Score Weight - Query score weights per symbol */ getMarketScoreWeights(params) { return this.get('/api/v3/market/score-weights', params); } /** * Get Tickers */ getTickers(params) { return this.get('/api/v3/market/tickers', params); } /** * Get OrderBook */ getOrderBook(params) { return this.get('/api/v3/market/orderbook', params); } /** * Get Recent Public Fills */ getFills(params) { return this.get('/api/v3/market/fills', params); } /** * Get Proof Of Reserves */ getProofOfReserves() { return this.get('/api/v3/market/proof-of-reserves'); } /** * Get Open Interest */ getOpenInterest(params) { return this.get('/api/v3/market/open-interest', params); } /** * Get Kline/Candlestick * Maximum number of returned entries: 1,000 */ getCandles(params) { return this.get('/api/v3/market/candles', params); } /** * Get Kline/Candlestick History */ getHistoryCandles(params) { return this.get('/api/v3/market/history-candles', params); } /** * Get Current Funding Rate */ getCurrentFundingRate(params) { return this.get('/api/v3/market/current-fund-rate', params); } /** * Get Funding Rate History */ getHistoryFundingRate(params) { return this.get('/api/v3/market/history-fund-rate', params); } /** * Get Risk Reserve */ getRiskReserve(params) { return this.get('/api/v3/market/risk-reserve', params); } /** * Get Risk Reserve (Hourly) */ getRiskReserveHour(params) { return this.get('/api/v3/market/risk-reserve-hour', params); } /** * Get Risk Reserve All — current insurance funds */ getRiskReserveAll(params) { return this.get('/api/v3/market/risk-reserve-all', params); } /** * Get Discount Rate */ getDiscountRate() { return this.get('/api/v3/market/discount-rate'); } /** * Get Margin Loan */ getMarginLoans(params) { return this.get('/api/v3/market/margin-loans', params); } /** * Get Position Tier */ getPositionTier(params) { return this.get('/api/v3/market/position-tier', params); } /** * Get Open Interest Limit */ getContractsOi(params) { return this.get('/api/v3/market/oi-limit', params); } /** * Get Index Price Components */ getIndexComponents(params) { return this.get('/api/v3/market/index-components', params); } /** * * =====Copy Trading | Futures===== * */ /** * Get copy-trading trading pair information * * Rate limit: 5/sec/UID. Permission: Unified Account — Futures Copy-Trading Orders — Read-only. */ getCopyFuturesTradingPairs() { return this.getPrivate('/api/v3/copy/futures/trading-pairs'); } /** * Get copy-trading position summary * * Rate limit: 5/sec/UID. Permission: Unified Account — Futures Copy-Trading Positions — Read-only. */ getCopyFuturesPositionSummary() { return this.getPrivate('/api/v3/copy/futures/position-summary'); } /** * * =====Account======= endpoints * */ /** * Get Account Assets */ getBalances() { return this.getPrivate('/api/v3/account/assets'); } /** * Get Fund Account Assets */ getFundingAssets(params) { return this.getPrivate('/api/v3/account/funding-assets', params); } /** * Get Account Info */ getAccountSettings() { return this.getPrivate('/api/v3/account/settings'); } /** * Set Leverage */ setLeverage(params) { return this.postPrivate('/api/v3/account/set-leverage', params); } /** * Set Holding Mode */ setHoldMode(params) { return this.postPrivate('/api/v3/account/set-hold-mode', params); } /** * Get Financial Records */ getFinancialRecords(params) { return this.getPrivate('/api/v3/account/financial-records', params); } /** * Get Repayable Coins */ getRepayableCoins() { return this.getPrivate('/api/v3/account/repayable-coins'); } /** * Get Payment Coins */ getPaymentCoins() { return this.getPrivate('/api/v3/account/payment-coins'); } /** * Repay */ submitRepay(params) { return this.postPrivate('/api/v3/account/repay', params); } /** * Get Convert Records */ getConvertRecords(params) { return this.getPrivate('/api/v3/account/convert-records', params); } /** * Set up deposit account - Configure default recharge account for a certain symbol * This configuration item remains valid for a long time. That is, once a user sets a default * recharge account for a certain symbol, it will be retained permanently, and there is no need to reconfigure it. * Permission: UTA mgt. (read & write) */ setDepositAccount(params) { return this.postPrivate('/api/v3/account/deposit-account', params); } /** * Switch Deduct - Set BGB deduction */ switchDeduct(params) { return this.postPrivate('/api/v3/account/switch-deduct', params); } /** * Get Deduct Info - Get BGB deduction status */ getDeductInfo() { return this.getPrivate('/api/v3/account/deduct-info'); } /** * Get Trading Fee Rate */ getFeeRate(params) { return this.getPrivate('/api/v3/account/fee-rate', params); } /** * Get Max Transferable * * - Rate limit: 3 req/sec/UID * - Permission: UTA mgt. (read) * - Get the maximum transferable amount for the unified account. */ getMaxTransferable(params) { return this.getPrivate('/api/v3/account/max-transferable', params); } /** * Get Open Interest Limit * * - Rate limit: 5/sec/UID * - Get open interest limit for a symbol */ getOpenInterestLimit(params) { return this.getPrivate('/api/v3/account/open-interest-limit', params); } /** * Switch Account - Switch to classic account mode * Only supports parent accounts. * This endpoint is only used for switching to classic account mode. * Please note that since the account switching process takes approximately 1 minute, * the successful response you receive only indicates that the request has been received, * and does not mean that the account has been successfully switched to the classic account. * Please use the query switching status interface to confirm whether the account switching is successful. */ downgradeAccountToClassic() { return this.postPrivate('/api/v3/account/switch'); } /** * Get Switch Status - Get account switching status * Only supports parent accounts. */ getUnifiedAccountSwitchStatus() { return this.getPrivate('/api/v3/account/switch-status'); } /** * Get Tax Records * * - Rate limit: 1/sec/UID * - Data query range: 366 days * - Please use the tax API Key to request Creation Portal * - Get Unified Account Tax Records */ getTaxRecords(params) { return this.getPrivate('/api/v3/tax/records', params); } /** * * =====SubAccount======= endpoints * */ /** * Create Sub-account */ createSubAccount(params) { return this.postPrivate('/api/v3/user/create-sub', params); } /** * Freeze/Unfreeze Sub-account */ freezeSubAccount(params) { return this.postPrivate('/api/v3/user/freeze-sub', params); } /** * Get Sub-account Unified Account Assets */ getSubUnifiedAssets(params) { return this.getPrivate('/api/v3/account/sub-unified-assets', params); } /** * Get Sub-account List */ getSubAccountList(params) { return this.getPrivate('/api/v3/user/sub-list', params); } /** * Create Sub-account API Key */ createSubAccountApiKey(params) { return this.postPrivate('/api/v3/user/create-sub-api', params); } /** * Modify Sub-account API Key */ updateSubAccountApiKey(params) { return this.postPrivate('/api/v3/user/update-sub-api', params); } /** * Delete Sub-account API Key */ deleteSubAccountApiKey(params) { return this.postPrivate('/api/v3/user/delete-sub-api', params); } /** * Get Sub-account API Keys */ getSubAccountApiKeys(params) { return this.getPrivate('/api/v3/user/sub-api-list', params); } /** * * =====Transfer======= endpoints * */ /** * Get Transferable Coins */ getTransferableCoins(params) { return this.getPrivate('/api/v3/account/transferable-coins', params); } /** * Transfer */ submitTransfer(params) { return this.postPrivate('/api/v3/account/transfer', params); } /** * Main-Sub Account Transfer */ subAccountTransfer(params) { return this.postPrivate('/api/v3/account/sub-transfer', params); } /** * Get Main-Sub Transfer Records */ getSubTransferRecords(params) { return this.getPrivate('/api/v3/account/sub-transfer-record', params); } /** * * =====Deposit======= endpoints * */ /** * Get Deposit Address */ getDepositAddress(params) { return this.getPrivate('/api/v3/account/deposit-address', params); } /** * Get Sub Deposit Address */ getSubDepositAddress(params) { return this.getPrivate('/api/v3/account/sub-deposit-address', params); } /** * Get Deposit Records */ getDepositRecords(params) { return this.getPrivate('/api/v3/account/deposit-records', params); } /** * Get Sub Deposit Records */ getSubDepositRecords(params) { return this.postPrivate('/api/v3/account/sub-deposit-records', params); } /** * * =====Withdraw======= endpoints * */ /** * Withdraw - Includes on-chain withdrawals and internal transfers */ submitWithdraw(params) { return this.postPrivate('/api/v3/account/withdraw', params); } /** * Get Withdraw Records */ getWithdrawRecords(params) { return this.getPrivate('/api/v3/account/withdrawal-records', params); } /** * * =====Trade======= endpoints * */ /** * Place Order */ submitNewOrder(params) { return this.postPrivate('/api/v3/trade/place-order', params); } /** * Modify Order */ modifyOrder(params) { return this.postPrivate('/api/v3/trade/modify-order', params); } /** * Cancel Order */ cancelOrder(params) { return this.postPrivate('/api/v3/trade/cancel-order', params); } /** * Batch Order */ placeBatchOrders(params) { return this.postPrivate('/api/v3/trade/place-batch', params); } /** * Batch Modify Orders */ batchModifyOrders(params) { return this.postPrivate('/api/v3/trade/batch-modify-order', params); } /** * Batch Cancel */ cancelBatchOrders(params) { return this.postPrivate('/api/v3/trade/cancel-batch', params); } /** * Cancel All Orders */ cancelAllOrders(params) { return this.postPrivate('/api/v3/trade/cancel-symbol-order', params); } /** * Close All Positions */ closeAllPositions(params) { return this.postPrivate('/api/v3/trade/close-positions', params); } /** * Get Order Details */ getOrderInfo(params) { return this.getPrivate('/api/v3/trade/order-info', params); } /** * Get Open Orders */ getUnfilledOrders(params) { return this.getPrivate('/api/v3/trade/unfilled-orders', params); } /** * Get Order History */ getHistoryOrders(params) { return this.getPrivate('/api/v3/trade/history-orders', params); } /** * Get Fill History */ getTradeFills(params) { return this.getPrivate('/api/v3/trade/fills', params); } /** * Get Position Info */ getCurrentPosition(params) { return this.getPrivate('/api/v3/position/current-position', params); } /** * Get Positions History */ getPositionHistory(params) { return this.getPrivate('/api/v3/position/history-position', params); } /** * Get Max Open Available */ getMaxOpenAvailable(params) { return this.postPrivate('/api/v3/account/max-open-available', params); } /** * Get Position ADL Rank - Get position auto-deleveraging ranking */ getPositionAdlRank() { return this.getPrivate('/api/v3/position/adlRank'); } /** * CountDown Cancel All */ countdownCancelAll(params) { return this.postPrivate('/api/v3/trade/countdown-cancel-all', params); } /** * * =====Inst Loan======= endpoints * */ /** * Get Transferred Quantity */ getLoanTransfered(params) { return this.getPrivate('/api/v3/ins-loan/transfered', params); } /** * Get Trade Symbols */ getLoanSymbols(params) { return this.getPrivate('/api/v3/ins-loan/symbols', params); } /** * Get Risk Unit */ getLoanRiskUnit() { return this.getPrivate('/api/v3/ins-loan/risk-unit'); } /** * Get Repayment Orders */ getLoanRepaidHistory(params) { return this.getPrivate('/api/v3/ins-loan/repaid-history', params); } /** * Get Product Info */ getLoanProductInfo(params) { return this.getPrivate('/api/v3/ins-loan/product-infos', params); } /** * Get Loan Orders */ getLoanOrder(params) { return this.getPrivate('/api/v3/ins-loan/loan-order', params); } /** * Get LTV */ getLoanLTVConvert(params) { return this.getPrivate('/api/v3/ins-loan/ltv-convert', params); } /** * Get Margin Coin Info */ getLoanMarginCoinInfo(params) { return this.getPrivate('/api/v3/ins-loan/ensure-coins-convert', params); } /** * Bind/Unbind UID to Risk Unit */ bindLoanUid(params) { return this.postPrivate('/api/v3/ins-loan/bind-uid', params); } /** * * =====Unified Account Staking & Lending (Crypto Loans)===== /api/v3/loan/* * */ /** * Get Loan Coins - Query supported collateral currencies and borrowable coins */ getLoanCoins(params) { return this.getPrivate('/api/v3/loan/coins', params); } /** * Get Loan Interest - Query estimated interest and borrowable amount */ getLoanInterest(params) { return this.getPrivate('/api/v3/loan/interest', params); } /** * Borrow - Borrow coins */ loanBorrow(params) { return this.postPrivate('/api/v3/loan/borrow', params); } /** * Get Borrow Ongoing - Query current borrowings */ getLoanBorrowOngoing(params) { return this.getPrivate('/api/v3/loan/borrow-ongoing', params); } /** * Get Borrow History - Query borrowing history */ getLoanBorrowHistory(params) { return this.getPrivate('/api/v3/loan/borrow-history', params); } /** * Repay - Repay coins */ loanRepay(params) { return this.postPrivate('/api/v3/loan/repay', params); } /** * Get Repay History - Query repayment history */ getLoanRepayHistory(params) { return this.getPrivate('/api/v3/loan/repay-history', params); } /** * Revise Pledge - Adjust collateral ratio */ loanRevisePledge(params) { return this.postPrivate('/api/v3/loan/revise-pledge', params); } /** * Get Pledge Rate History - Query collateral ratio history */ getLoanPledgeRateHistory(params) { return this.getPrivate('/api/v3/loan/pledge-rate-history', params); } /** * Get Loan Debts - Query assets and liabilities */ getLoanDebts() { return this.getPrivate('/api/v3/loan/debts'); } /** * Get Loan Reduces - Query liquidation records */ getLoanReduces(params) { return this.getPrivate('/api/v3/loan/reduces', params); } /** * * =====Strategy======= endpoints * */ /** * Place Strategy Order */ submitStrategyOrder(params) { return this.postPrivate('/api/v3/trade/place-strategy-order', params); } /** * Modify Strategy Order */ modifyStrategyOrder(params) { return this.postPrivate('/api/v3/trade/modify-strategy-order', params); } /** * Cancel Strategy Order */ cancelStrategyOrder(params) { return this.postPrivate('/api/v3/trade/cancel-strategy-order', params); } /** * Get Unfilled Strategy Orders */ getUnfilledStrategyOrders(params) { return this.getPrivate('/api/v3/trade/unfilled-strategy-orders', params); } /** * Get Strategy Order History */ getHistoryStrategyOrders(params) { return this.getPrivate('/api/v3/trade/history-strategy-orders', params); } /** * * =====Broker======= endpoints * */ /** * Create Broker Sub-Account * * Rate limit: 20/sec/UID * Only the master account with a user type of ND Broker can call this API endpoint. */ createBrokerSubAccount(params) { return this.postPrivate('/api/v3/broker/create-sub', params); } /** * Get Broker Sub-Account List * * Rate limit: 20/sec/UID * Only the master account with a user type of ND Broker can call this API endpoint. */ getBrokerSubAccountList(params) { return this.getPrivate('/api/v3/broker/sub-list', params); } /** * Modify Broker Sub-Account * * Rate limit: 20/sec/UID * Only the master account with a user type of ND Broker can call this API endpoint. */ modifyBrokerSubAccount(params) { return this.postPrivate('/api/v3/broker/modify-sub', params); } /** * Broker Subaccount Withdrawal * * Broker sub-account withdrawal API has restrictions and currently supports only the following currencies: * BTC, ETH, USDT, USDC, TRX, XRP, LTC, SOL, BNB, FTM, DOGE, ADA, SHIB, UNI, SEI, SUI, POL, FIL, LINK, TON, ARB, OP, DOT, AVAX * * Rate limit: 20/sec/UID * Only the master account with a user type of ND Broker can call this API endpoint. */ brokerSubWithdrawal(params) { return this.postPrivate('/api/v3/broker/sub-withdrawal', params); } /** * Get Broker Subaccount Deposit Address * * Rate limit: 20/sec/UID * Only the master account with a user type of ND Broker can call this API endpoint. */ getBrokerSubDepositAddress(params) { return this.postPrivate('/api/v3/broker/sub-deposit-address', params); } /** * Get All Broker Subaccount Deposit Withdrawal * * Rate limit: 20/sec/UID * Only the master account with a user type of ND Broker can call this API endpoint. */ getBrokerAllSubDepositWithdrawal(params) { return this.getPrivate('/api/v3/broker/all-sub-deposit-withdrawal', params); } /** * Get Broker Commission * * Rate limit: 20/sec/UID * Only the master account with a user type of ND Broker can call this API endpoint. */ getBrokerCommission(params) { return this.getPrivate('/api/v3/broker/commission', params); } /** * Create Broker Sub-Account API Key * * Rate limit: 20/sec/UID * Only the master account with a user type of ND Broker can call this API endpoint. */ createBrokerSubApiKey(params) { return this.postPrivate('/api/v3/broker/create-sub-apikey', params); } /** * Modify Broker Sub-Account API Key * * Rate limit: 20/sec/UID * Only the master account with a user type of ND Broker can call this API endpoint. */ modifyBrokerSubApiKey(params) { return this.postPrivate('/api/v3/broker/modify-sub-apikey', params); } /** * Delete Broker Subaccount Apikey * * This endpoint has no response parameters. * It returns the deletion result synchronously. * Determine whether the deletion succeeded or failed (and the failure reason) based on the returned code and msg. * * Rate limit: 20/sec/UID * Only the master account with a user type of ND Broker can call this API endpoint. */ deleteBrokerSubApiKey(params) { return this.postPrivate('/api/v3/broker/delete-sub-apikey', params); } /** * Get Broker Sub-Account API Key * * Rate limit: 20/sec/UID * Only the master account with a user type of ND Broker can call this API endpoint. */ getBrokerSubApiKey(params) { return this.getPrivate('/api/v3/broker/query-sub-apikey', params); } /** * * =====Earn | On-Chain Elite (UTA)===== * */ getEarnEliteProducts() { return this.getPrivate('/api/v3/earn/elite-product'); } getEarnEliteAssets() { return this.getPrivate('/api/v3/earn/elite-assets'); } getEarnEliteRecords(params) { return this.getPrivate('/api/v3/earn/elite-records', params); } getEarnEliteSubscribeInfo(params) { return this.getPrivate('/api/v3/earn/elite-subscribe-info', params); } subscribeEarnElite(params) { return this.postPrivate('/api/v3/earn/elite-subscribe', params); } getEarnEliteSubscribeResult(params) { return this.getPrivate('/api/v3/earn/elite-subscribe-result', params); } getEarnEliteRedeemInfo(params) { return this.getPrivate('/api/v3/earn/elite-redeem-info', params); } redeemEarnElite(params) { return this.postPrivate('/api/v3/earn/elite-redeem', params); } } exports.RestClientV3 = RestClientV3; //# sourceMappingURL=rest-client-v3.js.map