diff --git a/docs/endpointFunctionList.md b/docs/endpointFunctionList.md index 6c0b7aa..929acee 100644 --- a/docs/endpointFunctionList.md +++ b/docs/endpointFunctionList.md @@ -331,102 +331,115 @@ This table includes all endpoints from the official Exchange API docs and corres | Function | AUTH | HTTP Method | Endpoint | | -------- | :------: | :------: | -------- | -| [getServerTime()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L269) | | GET | `/api/v3/public/time` | -| [getInstruments()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L286) | | GET | `/api/v3/market/instruments` | -| [getTickers()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L295) | | GET | `/api/v3/market/tickers` | -| [getOrderBook()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L302) | | GET | `/api/v3/market/orderbook` | -| [getFills()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L311) | | GET | `/api/v3/market/fills` | -| [getProofOfReserves()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L320) | | GET | `/api/v3/market/proof-of-reserves` | -| [getOpenInterest()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L327) | | GET | `/api/v3/market/open-interest` | -| [getCandles()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L337) | | GET | `/api/v3/market/candles` | -| [getHistoryCandles()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L346) | | GET | `/api/v3/market/history-candles` | -| [getCurrentFundingRate()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L355) | | GET | `/api/v3/market/current-fund-rate` | -| [getHistoryFundingRate()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L364) | | GET | `/api/v3/market/history-fund-rate` | -| [getRiskReserve()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L373) | | GET | `/api/v3/market/risk-reserve` | -| [getDiscountRate()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L382) | | GET | `/api/v3/market/discount-rate` | -| [getMarginLoans()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L389) | | GET | `/api/v3/market/margin-loans` | -| [getPositionTier()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L398) | | GET | `/api/v3/market/position-tier` | -| [getContractsOi()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L407) | | GET | `/api/v3/market/oi-limit` | -| [getIndexComponents()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L416) | | GET | `/api/v3/market/index-components` | -| [getBalances()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L431) | :closed_lock_with_key: | GET | `/api/v3/account/assets` | -| [getFundingAssets()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L438) | :closed_lock_with_key: | GET | `/api/v3/account/funding-assets` | -| [getAccountSettings()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L447) | :closed_lock_with_key: | GET | `/api/v3/account/settings` | -| [setLeverage()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L454) | :closed_lock_with_key: | POST | `/api/v3/account/set-leverage` | -| [setHoldMode()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L461) | :closed_lock_with_key: | POST | `/api/v3/account/set-hold-mode` | -| [getFinancialRecords()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L470) | :closed_lock_with_key: | GET | `/api/v3/account/financial-records` | -| [getRepayableCoins()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L482) | :closed_lock_with_key: | GET | `/api/v3/account/repayable-coins` | -| [getPaymentCoins()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L494) | :closed_lock_with_key: | GET | `/api/v3/account/payment-coins` | -| [submitRepay()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L506) | :closed_lock_with_key: | POST | `/api/v3/account/repay` | -| [getConvertRecords()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L513) | :closed_lock_with_key: | GET | `/api/v3/account/convert-records` | -| [setDepositAccount()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L528) | :closed_lock_with_key: | POST | `/api/v3/account/deposit-account` | -| [switchDeduct()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L537) | :closed_lock_with_key: | POST | `/api/v3/account/switch-deduct` | -| [getDeductInfo()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L544) | :closed_lock_with_key: | GET | `/api/v3/account/deduct-info` | -| [getFeeRate()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L555) | :closed_lock_with_key: | GET | `/api/v3/account/fee-rate` | -| [getMaxTransferable()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L571) | :closed_lock_with_key: | GET | `/api/v3/account/max-transferable` | -| [getOpenInterestLimit()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L583) | :closed_lock_with_key: | GET | `/api/v3/account/open-interest-limit` | -| [downgradeAccountToClassic()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L598) | :closed_lock_with_key: | POST | `/api/v3/account/switch` | -| [getUnifiedAccountSwitchStatus()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L606) | :closed_lock_with_key: | GET | `/api/v3/account/switch-status` | -| [getTaxRecords()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L622) | :closed_lock_with_key: | GET | `/api/v3/tax/records` | -| [createSubAccount()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L637) | :closed_lock_with_key: | POST | `/api/v3/user/create-sub` | -| [freezeSubAccount()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L646) | :closed_lock_with_key: | POST | `/api/v3/user/freeze-sub` | -| [getSubUnifiedAssets()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L655) | :closed_lock_with_key: | GET | `/api/v3/account/sub-unified-assets` | -| [getSubAccountList()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L664) | :closed_lock_with_key: | GET | `/api/v3/user/sub-list` | -| [createSubAccountApiKey()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L677) | :closed_lock_with_key: | POST | `/api/v3/user/create-sub-api` | -| [updateSubAccountApiKey()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L686) | :closed_lock_with_key: | POST | `/api/v3/user/update-sub-api` | -| [deleteSubAccountApiKey()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L695) | :closed_lock_with_key: | POST | `/api/v3/user/delete-sub-api` | -| [getSubAccountApiKeys()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L704) | :closed_lock_with_key: | GET | `/api/v3/user/sub-api-list` | -| [getTransferableCoins()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L723) | :closed_lock_with_key: | GET | `/api/v3/account/transferable-coins` | -| [submitTransfer()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L732) | :closed_lock_with_key: | POST | `/api/v3/account/transfer` | -| [subAccountTransfer()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L741) | :closed_lock_with_key: | POST | `/api/v3/account/sub-transfer` | -| [getSubTransferRecords()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L753) | :closed_lock_with_key: | GET | `/api/v3/account/sub-transfer-record` | -| [getDepositAddress()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L771) | :closed_lock_with_key: | GET | `/api/v3/account/deposit-address` | -| [getSubDepositAddress()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L780) | :closed_lock_with_key: | GET | `/api/v3/account/sub-deposit-address` | -| [getDepositRecords()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L789) | :closed_lock_with_key: | GET | `/api/v3/account/deposit-records` | -| [getSubDepositRecords()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L798) | :closed_lock_with_key: | POST | `/api/v3/account/sub-deposit-records` | -| [submitWithdraw()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L813) | :closed_lock_with_key: | POST | `/api/v3/account/withdraw` | -| [getWithdrawRecords()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L822) | :closed_lock_with_key: | GET | `/api/v3/account/withdrawal-records` | -| [submitNewOrder()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L837) | :closed_lock_with_key: | POST | `/api/v3/trade/place-order` | -| [modifyOrder()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L846) | :closed_lock_with_key: | POST | `/api/v3/trade/modify-order` | -| [cancelOrder()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L855) | :closed_lock_with_key: | POST | `/api/v3/trade/cancel-order` | -| [placeBatchOrders()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L864) | :closed_lock_with_key: | POST | `/api/v3/trade/place-batch` | -| [batchModifyOrders()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L873) | :closed_lock_with_key: | POST | `/api/v3/trade/batch-modify-order` | -| [cancelBatchOrders()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L882) | :closed_lock_with_key: | POST | `/api/v3/trade/cancel-batch` | -| [cancelAllOrders()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L891) | :closed_lock_with_key: | POST | `/api/v3/trade/cancel-symbol-order` | -| [closeAllPositions()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L900) | :closed_lock_with_key: | POST | `/api/v3/trade/close-positions` | -| [getOrderInfo()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L909) | :closed_lock_with_key: | GET | `/api/v3/trade/order-info` | -| [getUnfilledOrders()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L918) | :closed_lock_with_key: | GET | `/api/v3/trade/unfilled-orders` | -| [getHistoryOrders()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L930) | :closed_lock_with_key: | GET | `/api/v3/trade/history-orders` | -| [getTradeFills()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L942) | :closed_lock_with_key: | GET | `/api/v3/trade/fills` | -| [getCurrentPosition()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L954) | :closed_lock_with_key: | GET | `/api/v3/position/current-position` | -| [getPositionHistory()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L965) | :closed_lock_with_key: | GET | `/api/v3/position/history-position` | -| [getMaxOpenAvailable()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L977) | :closed_lock_with_key: | POST | `/api/v3/account/max-open-available` | -| [getPositionAdlRank()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L986) | :closed_lock_with_key: | GET | `/api/v3/position/adlRank` | -| [countdownCancelAll()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L993) | :closed_lock_with_key: | POST | `/api/v3/trade/countdown-cancel-all` | -| [getLoanTransfered()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1008) | :closed_lock_with_key: | GET | `/api/v3/ins-loan/transfered` | -| [getLoanSymbols()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1017) | :closed_lock_with_key: | GET | `/api/v3/ins-loan/symbols` | -| [getLoanRiskUnit()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1026) | :closed_lock_with_key: | GET | `/api/v3/ins-loan/risk-unit` | -| [getLoanRepaidHistory()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1037) | :closed_lock_with_key: | GET | `/api/v3/ins-loan/repaid-history` | -| [getLoanProductInfo()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1046) | :closed_lock_with_key: | GET | `/api/v3/ins-loan/product-infos` | -| [getLoanOrder()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1055) | :closed_lock_with_key: | GET | `/api/v3/ins-loan/loan-order` | -| [getLoanLTVConvert()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1064) | :closed_lock_with_key: | GET | `/api/v3/ins-loan/ltv-convert` | -| [getLoanMarginCoinInfo()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1073) | :closed_lock_with_key: | GET | `/api/v3/ins-loan/ensure-coins-convert` | -| [bindLoanUid()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1085) | :closed_lock_with_key: | POST | `/api/v3/ins-loan/bind-uid` | -| [submitStrategyOrder()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1100) | :closed_lock_with_key: | POST | `/api/v3/trade/place-strategy-order` | -| [modifyStrategyOrder()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1109) | :closed_lock_with_key: | POST | `/api/v3/trade/modify-strategy-order` | -| [cancelStrategyOrder()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1118) | :closed_lock_with_key: | POST | `/api/v3/trade/cancel-strategy-order` | -| [getUnfilledStrategyOrders()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1127) | :closed_lock_with_key: | GET | `/api/v3/trade/unfilled-strategy-orders` | -| [getHistoryStrategyOrders()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1136) | :closed_lock_with_key: | GET | `/api/v3/trade/history-strategy-orders` | -| [createBrokerSubAccount()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1157) | :closed_lock_with_key: | POST | `/api/v3/broker/create-sub` | -| [getBrokerSubAccountList()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1169) | :closed_lock_with_key: | GET | `/api/v3/broker/sub-list` | -| [modifyBrokerSubAccount()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1181) | :closed_lock_with_key: | POST | `/api/v3/broker/modify-sub` | -| [brokerSubWithdrawal()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1196) | :closed_lock_with_key: | POST | `/api/v3/broker/sub-withdrawal` | -| [getBrokerSubDepositAddress()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1208) | :closed_lock_with_key: | POST | `/api/v3/broker/sub-deposit-address` | -| [getBrokerAllSubDepositWithdrawal()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1220) | :closed_lock_with_key: | GET | `/api/v3/broker/all-sub-deposit-withdrawal` | -| [getBrokerCommission()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1232) | :closed_lock_with_key: | GET | `/api/v3/broker/commission` | -| [createBrokerSubApiKey()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1244) | :closed_lock_with_key: | POST | `/api/v3/broker/create-sub-apikey` | -| [modifyBrokerSubApiKey()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1256) | :closed_lock_with_key: | POST | `/api/v3/broker/modify-sub-apikey` | -| [deleteBrokerSubApiKey()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1272) | :closed_lock_with_key: | POST | `/api/v3/broker/delete-sub-apikey` | -| [getBrokerSubApiKey()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1284) | :closed_lock_with_key: | GET | `/api/v3/broker/query-sub-apikey` | +| [getServerTime()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L294) | | GET | `/api/v3/public/time` | +| [getInstruments()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L311) | | GET | `/api/v3/market/instruments` | +| [getMarketFeeGroup()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L320) | | GET | `/api/v3/market/fee-group` | +| [getMarketScoreWeights()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L329) | | GET | `/api/v3/market/score-weights` | +| [getTickers()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L338) | | GET | `/api/v3/market/tickers` | +| [getOrderBook()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L345) | | GET | `/api/v3/market/orderbook` | +| [getFills()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L354) | | GET | `/api/v3/market/fills` | +| [getProofOfReserves()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L363) | | GET | `/api/v3/market/proof-of-reserves` | +| [getOpenInterest()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L370) | | GET | `/api/v3/market/open-interest` | +| [getCandles()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L380) | | GET | `/api/v3/market/candles` | +| [getHistoryCandles()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L389) | | GET | `/api/v3/market/history-candles` | +| [getCurrentFundingRate()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L398) | | GET | `/api/v3/market/current-fund-rate` | +| [getHistoryFundingRate()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L407) | | GET | `/api/v3/market/history-fund-rate` | +| [getRiskReserve()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L416) | | GET | `/api/v3/market/risk-reserve` | +| [getDiscountRate()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L425) | | GET | `/api/v3/market/discount-rate` | +| [getMarginLoans()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L432) | | GET | `/api/v3/market/margin-loans` | +| [getPositionTier()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L441) | | GET | `/api/v3/market/position-tier` | +| [getContractsOi()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L450) | | GET | `/api/v3/market/oi-limit` | +| [getIndexComponents()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L459) | | GET | `/api/v3/market/index-components` | +| [getBalances()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L474) | :closed_lock_with_key: | GET | `/api/v3/account/assets` | +| [getFundingAssets()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L481) | :closed_lock_with_key: | GET | `/api/v3/account/funding-assets` | +| [getAccountSettings()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L490) | :closed_lock_with_key: | GET | `/api/v3/account/settings` | +| [setLeverage()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L497) | :closed_lock_with_key: | POST | `/api/v3/account/set-leverage` | +| [setHoldMode()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L504) | :closed_lock_with_key: | POST | `/api/v3/account/set-hold-mode` | +| [getFinancialRecords()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L513) | :closed_lock_with_key: | GET | `/api/v3/account/financial-records` | +| [getRepayableCoins()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L525) | :closed_lock_with_key: | GET | `/api/v3/account/repayable-coins` | +| [getPaymentCoins()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L537) | :closed_lock_with_key: | GET | `/api/v3/account/payment-coins` | +| [submitRepay()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L549) | :closed_lock_with_key: | POST | `/api/v3/account/repay` | +| [getConvertRecords()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L556) | :closed_lock_with_key: | GET | `/api/v3/account/convert-records` | +| [setDepositAccount()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L571) | :closed_lock_with_key: | POST | `/api/v3/account/deposit-account` | +| [switchDeduct()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L580) | :closed_lock_with_key: | POST | `/api/v3/account/switch-deduct` | +| [getDeductInfo()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L587) | :closed_lock_with_key: | GET | `/api/v3/account/deduct-info` | +| [getFeeRate()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L598) | :closed_lock_with_key: | GET | `/api/v3/account/fee-rate` | +| [getMaxTransferable()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L614) | :closed_lock_with_key: | GET | `/api/v3/account/max-transferable` | +| [getOpenInterestLimit()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L626) | :closed_lock_with_key: | GET | `/api/v3/account/open-interest-limit` | +| [downgradeAccountToClassic()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L641) | :closed_lock_with_key: | POST | `/api/v3/account/switch` | +| [getUnifiedAccountSwitchStatus()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L649) | :closed_lock_with_key: | GET | `/api/v3/account/switch-status` | +| [getTaxRecords()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L665) | :closed_lock_with_key: | GET | `/api/v3/tax/records` | +| [createSubAccount()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L680) | :closed_lock_with_key: | POST | `/api/v3/user/create-sub` | +| [freezeSubAccount()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L689) | :closed_lock_with_key: | POST | `/api/v3/user/freeze-sub` | +| [getSubUnifiedAssets()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L698) | :closed_lock_with_key: | GET | `/api/v3/account/sub-unified-assets` | +| [getSubAccountList()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L707) | :closed_lock_with_key: | GET | `/api/v3/user/sub-list` | +| [createSubAccountApiKey()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L720) | :closed_lock_with_key: | POST | `/api/v3/user/create-sub-api` | +| [updateSubAccountApiKey()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L729) | :closed_lock_with_key: | POST | `/api/v3/user/update-sub-api` | +| [deleteSubAccountApiKey()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L738) | :closed_lock_with_key: | POST | `/api/v3/user/delete-sub-api` | +| [getSubAccountApiKeys()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L747) | :closed_lock_with_key: | GET | `/api/v3/user/sub-api-list` | +| [getTransferableCoins()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L766) | :closed_lock_with_key: | GET | `/api/v3/account/transferable-coins` | +| [submitTransfer()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L775) | :closed_lock_with_key: | POST | `/api/v3/account/transfer` | +| [subAccountTransfer()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L784) | :closed_lock_with_key: | POST | `/api/v3/account/sub-transfer` | +| [getSubTransferRecords()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L796) | :closed_lock_with_key: | GET | `/api/v3/account/sub-transfer-record` | +| [getDepositAddress()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L814) | :closed_lock_with_key: | GET | `/api/v3/account/deposit-address` | +| [getSubDepositAddress()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L823) | :closed_lock_with_key: | GET | `/api/v3/account/sub-deposit-address` | +| [getDepositRecords()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L832) | :closed_lock_with_key: | GET | `/api/v3/account/deposit-records` | +| [getSubDepositRecords()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L841) | :closed_lock_with_key: | POST | `/api/v3/account/sub-deposit-records` | +| [submitWithdraw()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L856) | :closed_lock_with_key: | POST | `/api/v3/account/withdraw` | +| [getWithdrawRecords()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L865) | :closed_lock_with_key: | GET | `/api/v3/account/withdrawal-records` | +| [submitNewOrder()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L880) | :closed_lock_with_key: | POST | `/api/v3/trade/place-order` | +| [modifyOrder()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L889) | :closed_lock_with_key: | POST | `/api/v3/trade/modify-order` | +| [cancelOrder()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L898) | :closed_lock_with_key: | POST | `/api/v3/trade/cancel-order` | +| [placeBatchOrders()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L907) | :closed_lock_with_key: | POST | `/api/v3/trade/place-batch` | +| [batchModifyOrders()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L916) | :closed_lock_with_key: | POST | `/api/v3/trade/batch-modify-order` | +| [cancelBatchOrders()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L925) | :closed_lock_with_key: | POST | `/api/v3/trade/cancel-batch` | +| [cancelAllOrders()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L934) | :closed_lock_with_key: | POST | `/api/v3/trade/cancel-symbol-order` | +| [closeAllPositions()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L943) | :closed_lock_with_key: | POST | `/api/v3/trade/close-positions` | +| [getOrderInfo()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L952) | :closed_lock_with_key: | GET | `/api/v3/trade/order-info` | +| [getUnfilledOrders()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L961) | :closed_lock_with_key: | GET | `/api/v3/trade/unfilled-orders` | +| [getHistoryOrders()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L973) | :closed_lock_with_key: | GET | `/api/v3/trade/history-orders` | +| [getTradeFills()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L985) | :closed_lock_with_key: | GET | `/api/v3/trade/fills` | +| [getCurrentPosition()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L997) | :closed_lock_with_key: | GET | `/api/v3/position/current-position` | +| [getPositionHistory()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1008) | :closed_lock_with_key: | GET | `/api/v3/position/history-position` | +| [getMaxOpenAvailable()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1020) | :closed_lock_with_key: | POST | `/api/v3/account/max-open-available` | +| [getPositionAdlRank()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1029) | :closed_lock_with_key: | GET | `/api/v3/position/adlRank` | +| [countdownCancelAll()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1036) | :closed_lock_with_key: | POST | `/api/v3/trade/countdown-cancel-all` | +| [getLoanTransfered()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1051) | :closed_lock_with_key: | GET | `/api/v3/ins-loan/transfered` | +| [getLoanSymbols()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1060) | :closed_lock_with_key: | GET | `/api/v3/ins-loan/symbols` | +| [getLoanRiskUnit()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1069) | :closed_lock_with_key: | GET | `/api/v3/ins-loan/risk-unit` | +| [getLoanRepaidHistory()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1080) | :closed_lock_with_key: | GET | `/api/v3/ins-loan/repaid-history` | +| [getLoanProductInfo()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1089) | :closed_lock_with_key: | GET | `/api/v3/ins-loan/product-infos` | +| [getLoanOrder()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1098) | :closed_lock_with_key: | GET | `/api/v3/ins-loan/loan-order` | +| [getLoanLTVConvert()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1107) | :closed_lock_with_key: | GET | `/api/v3/ins-loan/ltv-convert` | +| [getLoanMarginCoinInfo()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1116) | :closed_lock_with_key: | GET | `/api/v3/ins-loan/ensure-coins-convert` | +| [bindLoanUid()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1128) | :closed_lock_with_key: | POST | `/api/v3/ins-loan/bind-uid` | +| [getLoanCoins()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1143) | :closed_lock_with_key: | GET | `/api/v3/loan/coins` | +| [getLoanInterest()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1152) | :closed_lock_with_key: | GET | `/api/v3/loan/interest` | +| [loanBorrow()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1161) | :closed_lock_with_key: | POST | `/api/v3/loan/borrow` | +| [getLoanBorrowOngoing()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1170) | :closed_lock_with_key: | GET | `/api/v3/loan/borrow-ongoing` | +| [getLoanBorrowHistory()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1179) | :closed_lock_with_key: | GET | `/api/v3/loan/borrow-history` | +| [loanRepay()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1188) | :closed_lock_with_key: | POST | `/api/v3/loan/repay` | +| [getLoanRepayHistory()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1197) | :closed_lock_with_key: | GET | `/api/v3/loan/repay-history` | +| [loanRevisePledge()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1206) | :closed_lock_with_key: | POST | `/api/v3/loan/revise-pledge` | +| [getLoanPledgeRateHistory()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1215) | :closed_lock_with_key: | GET | `/api/v3/loan/pledge-rate-history` | +| [getLoanDebts()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1224) | :closed_lock_with_key: | GET | `/api/v3/loan/debts` | +| [getLoanReduces()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1231) | :closed_lock_with_key: | GET | `/api/v3/loan/reduces` | +| [submitStrategyOrder()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1246) | :closed_lock_with_key: | POST | `/api/v3/trade/place-strategy-order` | +| [modifyStrategyOrder()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1255) | :closed_lock_with_key: | POST | `/api/v3/trade/modify-strategy-order` | +| [cancelStrategyOrder()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1264) | :closed_lock_with_key: | POST | `/api/v3/trade/cancel-strategy-order` | +| [getUnfilledStrategyOrders()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1273) | :closed_lock_with_key: | GET | `/api/v3/trade/unfilled-strategy-orders` | +| [getHistoryStrategyOrders()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1282) | :closed_lock_with_key: | GET | `/api/v3/trade/history-strategy-orders` | +| [createBrokerSubAccount()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1303) | :closed_lock_with_key: | POST | `/api/v3/broker/create-sub` | +| [getBrokerSubAccountList()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1315) | :closed_lock_with_key: | GET | `/api/v3/broker/sub-list` | +| [modifyBrokerSubAccount()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1327) | :closed_lock_with_key: | POST | `/api/v3/broker/modify-sub` | +| [brokerSubWithdrawal()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1342) | :closed_lock_with_key: | POST | `/api/v3/broker/sub-withdrawal` | +| [getBrokerSubDepositAddress()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1354) | :closed_lock_with_key: | POST | `/api/v3/broker/sub-deposit-address` | +| [getBrokerAllSubDepositWithdrawal()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1366) | :closed_lock_with_key: | GET | `/api/v3/broker/all-sub-deposit-withdrawal` | +| [getBrokerCommission()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1378) | :closed_lock_with_key: | GET | `/api/v3/broker/commission` | +| [createBrokerSubApiKey()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1390) | :closed_lock_with_key: | POST | `/api/v3/broker/create-sub-apikey` | +| [modifyBrokerSubApiKey()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1402) | :closed_lock_with_key: | POST | `/api/v3/broker/modify-sub-apikey` | +| [deleteBrokerSubApiKey()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1418) | :closed_lock_with_key: | POST | `/api/v3/broker/delete-sub-apikey` | +| [getBrokerSubApiKey()](https://github.com/tiagosiebler/bitget-api/blob/master/src/rest-client-v3.ts#L1430) | :closed_lock_with_key: | GET | `/api/v3/broker/query-sub-apikey` | # websocket-api-client.ts diff --git a/examples/apidoc/RestClientV3/getLoanBorrowHistory.js b/examples/apidoc/RestClientV3/getLoanBorrowHistory.js new file mode 100644 index 0000000..bfab209 --- /dev/null +++ b/examples/apidoc/RestClientV3/getLoanBorrowHistory.js @@ -0,0 +1,24 @@ +import { RestClientV3 } from 'bitget-api'; +// or if you want to use the require syntax +// const { RestClientV3 } = require('bitget-api'); + + +// This example shows how to call this Bitget API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "bitget-api" for Bitget exchange +// This Bitget API SDK is available on npm via "npm install bitget-api" +// ENDPOINT: /api/v3/loan/borrow-history +// METHOD: GET +// PUBLIC: NO + +const client = new RestClientV3({ + apiKey: 'insert_api_key_here', + apiSecret: 'insert_api_secret_here', + apiPass: 'insert_api_pass_here', +}); + +client.getLoanBorrowHistory(params) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/RestClientV3/getLoanBorrowOngoing.js b/examples/apidoc/RestClientV3/getLoanBorrowOngoing.js new file mode 100644 index 0000000..5732fff --- /dev/null +++ b/examples/apidoc/RestClientV3/getLoanBorrowOngoing.js @@ -0,0 +1,24 @@ +import { RestClientV3 } from 'bitget-api'; +// or if you want to use the require syntax +// const { RestClientV3 } = require('bitget-api'); + + +// This example shows how to call this Bitget API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "bitget-api" for Bitget exchange +// This Bitget API SDK is available on npm via "npm install bitget-api" +// ENDPOINT: /api/v3/loan/borrow-ongoing +// METHOD: GET +// PUBLIC: NO + +const client = new RestClientV3({ + apiKey: 'insert_api_key_here', + apiSecret: 'insert_api_secret_here', + apiPass: 'insert_api_pass_here', +}); + +client.getLoanBorrowOngoing(params) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/RestClientV3/getLoanCoins.js b/examples/apidoc/RestClientV3/getLoanCoins.js new file mode 100644 index 0000000..916c04a --- /dev/null +++ b/examples/apidoc/RestClientV3/getLoanCoins.js @@ -0,0 +1,24 @@ +import { RestClientV3 } from 'bitget-api'; +// or if you want to use the require syntax +// const { RestClientV3 } = require('bitget-api'); + + +// This example shows how to call this Bitget API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "bitget-api" for Bitget exchange +// This Bitget API SDK is available on npm via "npm install bitget-api" +// ENDPOINT: /api/v3/loan/coins +// METHOD: GET +// PUBLIC: NO + +const client = new RestClientV3({ + apiKey: 'insert_api_key_here', + apiSecret: 'insert_api_secret_here', + apiPass: 'insert_api_pass_here', +}); + +client.getLoanCoins(params) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/RestClientV3/getLoanDebts.js b/examples/apidoc/RestClientV3/getLoanDebts.js new file mode 100644 index 0000000..a7d72d3 --- /dev/null +++ b/examples/apidoc/RestClientV3/getLoanDebts.js @@ -0,0 +1,24 @@ +import { RestClientV3 } from 'bitget-api'; +// or if you want to use the require syntax +// const { RestClientV3 } = require('bitget-api'); + + +// This example shows how to call this Bitget API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "bitget-api" for Bitget exchange +// This Bitget API SDK is available on npm via "npm install bitget-api" +// ENDPOINT: /api/v3/loan/debts +// METHOD: GET +// PUBLIC: NO + +const client = new RestClientV3({ + apiKey: 'insert_api_key_here', + apiSecret: 'insert_api_secret_here', + apiPass: 'insert_api_pass_here', +}); + +client.getLoanDebts(params) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/RestClientV3/getLoanInterest.js b/examples/apidoc/RestClientV3/getLoanInterest.js new file mode 100644 index 0000000..58c4c82 --- /dev/null +++ b/examples/apidoc/RestClientV3/getLoanInterest.js @@ -0,0 +1,24 @@ +import { RestClientV3 } from 'bitget-api'; +// or if you want to use the require syntax +// const { RestClientV3 } = require('bitget-api'); + + +// This example shows how to call this Bitget API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "bitget-api" for Bitget exchange +// This Bitget API SDK is available on npm via "npm install bitget-api" +// ENDPOINT: /api/v3/loan/interest +// METHOD: GET +// PUBLIC: NO + +const client = new RestClientV3({ + apiKey: 'insert_api_key_here', + apiSecret: 'insert_api_secret_here', + apiPass: 'insert_api_pass_here', +}); + +client.getLoanInterest(params) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/RestClientV3/getLoanPledgeRateHistory.js b/examples/apidoc/RestClientV3/getLoanPledgeRateHistory.js new file mode 100644 index 0000000..7114fd7 --- /dev/null +++ b/examples/apidoc/RestClientV3/getLoanPledgeRateHistory.js @@ -0,0 +1,24 @@ +import { RestClientV3 } from 'bitget-api'; +// or if you want to use the require syntax +// const { RestClientV3 } = require('bitget-api'); + + +// This example shows how to call this Bitget API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "bitget-api" for Bitget exchange +// This Bitget API SDK is available on npm via "npm install bitget-api" +// ENDPOINT: /api/v3/loan/pledge-rate-history +// METHOD: GET +// PUBLIC: NO + +const client = new RestClientV3({ + apiKey: 'insert_api_key_here', + apiSecret: 'insert_api_secret_here', + apiPass: 'insert_api_pass_here', +}); + +client.getLoanPledgeRateHistory(params) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/RestClientV3/getLoanReduces.js b/examples/apidoc/RestClientV3/getLoanReduces.js new file mode 100644 index 0000000..f1486a5 --- /dev/null +++ b/examples/apidoc/RestClientV3/getLoanReduces.js @@ -0,0 +1,24 @@ +import { RestClientV3 } from 'bitget-api'; +// or if you want to use the require syntax +// const { RestClientV3 } = require('bitget-api'); + + +// This example shows how to call this Bitget API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "bitget-api" for Bitget exchange +// This Bitget API SDK is available on npm via "npm install bitget-api" +// ENDPOINT: /api/v3/loan/reduces +// METHOD: GET +// PUBLIC: NO + +const client = new RestClientV3({ + apiKey: 'insert_api_key_here', + apiSecret: 'insert_api_secret_here', + apiPass: 'insert_api_pass_here', +}); + +client.getLoanReduces(params) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/RestClientV3/getLoanRepayHistory.js b/examples/apidoc/RestClientV3/getLoanRepayHistory.js new file mode 100644 index 0000000..91b0d71 --- /dev/null +++ b/examples/apidoc/RestClientV3/getLoanRepayHistory.js @@ -0,0 +1,24 @@ +import { RestClientV3 } from 'bitget-api'; +// or if you want to use the require syntax +// const { RestClientV3 } = require('bitget-api'); + + +// This example shows how to call this Bitget API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "bitget-api" for Bitget exchange +// This Bitget API SDK is available on npm via "npm install bitget-api" +// ENDPOINT: /api/v3/loan/repay-history +// METHOD: GET +// PUBLIC: NO + +const client = new RestClientV3({ + apiKey: 'insert_api_key_here', + apiSecret: 'insert_api_secret_here', + apiPass: 'insert_api_pass_here', +}); + +client.getLoanRepayHistory(params) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/RestClientV3/getMarketFeeGroup.js b/examples/apidoc/RestClientV3/getMarketFeeGroup.js new file mode 100644 index 0000000..b0fba37 --- /dev/null +++ b/examples/apidoc/RestClientV3/getMarketFeeGroup.js @@ -0,0 +1,24 @@ +import { RestClientV3 } from 'bitget-api'; +// or if you want to use the require syntax +// const { RestClientV3 } = require('bitget-api'); + + +// This example shows how to call this Bitget API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "bitget-api" for Bitget exchange +// This Bitget API SDK is available on npm via "npm install bitget-api" +// ENDPOINT: /api/v3/market/fee-group +// METHOD: GET +// PUBLIC: YES + +const client = new RestClientV3({ + apiKey: 'insert_api_key_here', + apiSecret: 'insert_api_secret_here', + apiPass: 'insert_api_pass_here', +}); + +client.getMarketFeeGroup(params) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/RestClientV3/getMarketScoreWeights.js b/examples/apidoc/RestClientV3/getMarketScoreWeights.js new file mode 100644 index 0000000..3436407 --- /dev/null +++ b/examples/apidoc/RestClientV3/getMarketScoreWeights.js @@ -0,0 +1,24 @@ +import { RestClientV3 } from 'bitget-api'; +// or if you want to use the require syntax +// const { RestClientV3 } = require('bitget-api'); + + +// This example shows how to call this Bitget API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "bitget-api" for Bitget exchange +// This Bitget API SDK is available on npm via "npm install bitget-api" +// ENDPOINT: /api/v3/market/score-weights +// METHOD: GET +// PUBLIC: YES + +const client = new RestClientV3({ + apiKey: 'insert_api_key_here', + apiSecret: 'insert_api_secret_here', + apiPass: 'insert_api_pass_here', +}); + +client.getMarketScoreWeights(params) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/RestClientV3/loanBorrow.js b/examples/apidoc/RestClientV3/loanBorrow.js new file mode 100644 index 0000000..266a5fa --- /dev/null +++ b/examples/apidoc/RestClientV3/loanBorrow.js @@ -0,0 +1,24 @@ +import { RestClientV3 } from 'bitget-api'; +// or if you want to use the require syntax +// const { RestClientV3 } = require('bitget-api'); + + +// This example shows how to call this Bitget API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "bitget-api" for Bitget exchange +// This Bitget API SDK is available on npm via "npm install bitget-api" +// ENDPOINT: /api/v3/loan/borrow +// METHOD: POST +// PUBLIC: NO + +const client = new RestClientV3({ + apiKey: 'insert_api_key_here', + apiSecret: 'insert_api_secret_here', + apiPass: 'insert_api_pass_here', +}); + +client.loanBorrow(params) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/RestClientV3/loanRepay.js b/examples/apidoc/RestClientV3/loanRepay.js new file mode 100644 index 0000000..846f80f --- /dev/null +++ b/examples/apidoc/RestClientV3/loanRepay.js @@ -0,0 +1,24 @@ +import { RestClientV3 } from 'bitget-api'; +// or if you want to use the require syntax +// const { RestClientV3 } = require('bitget-api'); + + +// This example shows how to call this Bitget API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "bitget-api" for Bitget exchange +// This Bitget API SDK is available on npm via "npm install bitget-api" +// ENDPOINT: /api/v3/loan/repay +// METHOD: POST +// PUBLIC: NO + +const client = new RestClientV3({ + apiKey: 'insert_api_key_here', + apiSecret: 'insert_api_secret_here', + apiPass: 'insert_api_pass_here', +}); + +client.loanRepay(params) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/examples/apidoc/RestClientV3/loanRevisePledge.js b/examples/apidoc/RestClientV3/loanRevisePledge.js new file mode 100644 index 0000000..3ca8b48 --- /dev/null +++ b/examples/apidoc/RestClientV3/loanRevisePledge.js @@ -0,0 +1,24 @@ +import { RestClientV3 } from 'bitget-api'; +// or if you want to use the require syntax +// const { RestClientV3 } = require('bitget-api'); + + +// This example shows how to call this Bitget API endpoint with either node.js, javascript (js) or typescript (ts) with the npm module "bitget-api" for Bitget exchange +// This Bitget API SDK is available on npm via "npm install bitget-api" +// ENDPOINT: /api/v3/loan/revise-pledge +// METHOD: POST +// PUBLIC: NO + +const client = new RestClientV3({ + apiKey: 'insert_api_key_here', + apiSecret: 'insert_api_secret_here', + apiPass: 'insert_api_pass_here', +}); + +client.loanRevisePledge(params) + .then((response) => { + console.log(response); + }) + .catch((error) => { + console.error(error); + }); diff --git a/llms.txt b/llms.txt index c43526b..02c5488 100644 --- a/llms.txt +++ b/llms.txt @@ -141,7 +141,6 @@ LICENSE.md package.json postBuild.sh README.md -tea.yaml tsconfig.cjs.json tsconfig.esm.json tsconfig.json @@ -1462,6 +1461,90 @@ export interface BindUidRequestV3 { export interface GetLTVConvertRequestV3 { riskUnitId?: string; } +⋮---- +/* Unified Account Staking & Lending (Crypto Loans) - /api/v3/loan/* */ +⋮---- +export interface GetLoanCoinsRequestV3 { + coin?: string; +} +⋮---- +export interface GetLoanInterestRequestV3 { + loanCoin: string; + pledgeCoin: string; + daily: 'SEVEN' | 'THIRTY' | 'FLEXIBLE'; + pledgeAmount: string; +} +⋮---- +export interface LoanBorrowRequestV3 { + loanCoin: string; + pledgeCoin: string; + daily: 'SEVEN' | 'THIRTY' | 'FLEXIBLE'; + pledgeAmount?: string; + loanAmount?: string; +} +⋮---- +export interface GetLoanBorrowOngoingRequestV3 { + orderId?: string; + loanCoin?: string; + pledgeCoin?: string; +} +⋮---- +export interface GetLoanBorrowHistoryRequestV3 { + orderId?: string; + loanCoin?: string; + pledgeCoin?: string; + status?: 'ROLLBACK' | 'FORCE' | 'REPAY'; + startTime: string; + endTime: string; + pageNum?: string; + pageSize?: string; +} +⋮---- +export interface LoanRepayRequestV3 { + orderId: string; + method: 'borrowed_coin' | 'collateral'; + repayAll: 'yes' | 'no'; + amount?: string; + repayUnlock?: 'yes' | 'no'; +} +⋮---- +export interface GetLoanRepayHistoryRequestV3 { + orderId?: string; + loanCoin?: string; + pledgeCoin?: string; + startTime: string; + endTime: string; + pageNum?: string; + pageSize?: string; +} +⋮---- +export interface LoanRevisePledgeRequestV3 { + orderId: string; + amount: string; + pledgeCoin: string; + reviseType?: 'OUT' | 'IN'; +} +⋮---- +export interface GetLoanPledgeRateHistoryRequestV3 { + orderId?: string; + reviseSide?: 'down' | 'up'; + pledgeCoin?: string; + startTime: string; + endTime: string; + pageNum?: string; + pageSize?: string; +} +⋮---- +export interface GetLoanReducesRequestV3 { + orderId?: string; + loanCoin?: string; + pledgeCoin?: string; + status?: 'COMPLETE' | 'WAIT'; + startTime: string; + endTime: string; + pageNum?: string; + pageSize?: string; +} ================ File: src/types/request/v3/strategy.ts @@ -4379,6 +4462,8 @@ protected resolveEmittableEvents( // messageType: typeof msg, // messageString: JSON.stringify(msg), ⋮---- +// Service upgrade (30033): Bitget sends this ~60s before disconnect. Proactively close to trigger reconnect. +⋮---- // messageType: typeof msg, // messageString: JSON.stringify(msg), ⋮---- @@ -4422,6 +4507,11 @@ async sendWSAPIRequest< ⋮---- // Return deferred promise, so caller can await this call +================ +File: .eslintrc.cjs +================ +// 'no-unused-vars': ['warn'], + ================ File: .jshintrc ================ @@ -4446,6 +4536,194 @@ File: .prettierrc "trailingComma": "all" } +================ +File: jest.config.ts +================ +/** + * For a detailed explanation regarding each configuration property, visit: + * https://jestjs.io/docs/configuration + */ +⋮---- +import type { Config } from 'jest'; +⋮---- +// All imported modules in your tests should be mocked automatically +// automock: false, +⋮---- +// Stop running tests after `n` failures +// bail: 0, +bail: false, // enable to stop test when an error occur, +⋮---- +// The directory where Jest should store its cached dependency information +// cacheDirectory: "/private/var/folders/kf/2k3sz4px6c9cbyzj1h_b192h0000gn/T/jest_dx", +⋮---- +// Automatically clear mock calls, instances, contexts and results before every test +⋮---- +// Indicates whether the coverage information should be collected while executing the test +⋮---- +// An array of glob patterns indicating a set of files for which coverage information should be collected +⋮---- +// The directory where Jest should output its coverage files +⋮---- +// An array of regexp pattern strings used to skip coverage collection +// coveragePathIgnorePatterns: [ +// "/node_modules/" +// ], +⋮---- +// Indicates which provider should be used to instrument code for coverage +⋮---- +// A list of reporter names that Jest uses when writing coverage reports +// coverageReporters: [ +// "json", +// "text", +// "lcov", +// "clover" +// ], +⋮---- +// An object that configures minimum threshold enforcement for coverage results +// coverageThreshold: undefined, +⋮---- +// A path to a custom dependency extractor +// dependencyExtractor: undefined, +⋮---- +// Make calling deprecated APIs throw helpful error messages +// errorOnDeprecated: false, +⋮---- +// The default configuration for fake timers +// fakeTimers: { +// "enableGlobally": false +// }, +⋮---- +// Force coverage collection from ignored files using an array of glob patterns +// forceCoverageMatch: [], +⋮---- +// A path to a module which exports an async function that is triggered once before all test suites +// globalSetup: undefined, +⋮---- +// A path to a module which exports an async function that is triggered once after all test suites +// globalTeardown: undefined, +⋮---- +// A set of global variables that need to be available in all test environments +// globals: {}, +⋮---- +// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers. +// maxWorkers: "50%", +⋮---- +// An array of directory names to be searched recursively up from the requiring module's location +// moduleDirectories: [ +// "node_modules" +// ], +⋮---- +// An array of file extensions your modules use +⋮---- +// modulePaths: ['src'], +⋮---- +// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module +// moduleNameMapper: {}, +⋮---- +// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader +// modulePathIgnorePatterns: [], +⋮---- +// Activates notifications for test results +// notify: false, +⋮---- +// An enum that specifies notification mode. Requires { notify: true } +// notifyMode: "failure-change", +⋮---- +// A preset that is used as a base for Jest's configuration +// preset: undefined, +⋮---- +// Run tests from one or more projects +// projects: undefined, +⋮---- +// Use this configuration option to add custom reporters to Jest +// reporters: undefined, +⋮---- +// Automatically reset mock state before every test +// resetMocks: false, +⋮---- +// Reset the module registry before running each individual test +// resetModules: false, +⋮---- +// A path to a custom resolver +// resolver: undefined, +⋮---- +// Automatically restore mock state and implementation before every test +// restoreMocks: false, +⋮---- +// The root directory that Jest should scan for tests and modules within +// rootDir: undefined, +⋮---- +// A list of paths to directories that Jest should use to search for files in +// roots: [ +// "" +// ], +⋮---- +// Allows you to use a custom runner instead of Jest's default test runner +// runner: "jest-runner", +⋮---- +// The paths to modules that run some code to configure or set up the testing environment before each test +// setupFiles: [], +⋮---- +// A list of paths to modules that run some code to configure or set up the testing framework before each test +// setupFilesAfterEnv: [], +⋮---- +// The number of seconds after which a test is considered as slow and reported as such in the results. +// slowTestThreshold: 5, +⋮---- +// A list of paths to snapshot serializer modules Jest should use for snapshot testing +// snapshotSerializers: [], +⋮---- +// The test environment that will be used for testing +// testEnvironment: "jest-environment-node", +⋮---- +// Options that will be passed to the testEnvironment +// testEnvironmentOptions: {}, +⋮---- +// Adds a location field to test results +// testLocationInResults: false, +⋮---- +// The glob patterns Jest uses to detect test files +⋮---- +// "**/__tests__/**/*.[jt]s?(x)", +⋮---- +// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped +// testPathIgnorePatterns: [ +// "/node_modules/" +// ], +⋮---- +// The regexp pattern or array of patterns that Jest uses to detect test files +// testRegex: [], +⋮---- +// This option allows the use of a custom results processor +// testResultsProcessor: undefined, +⋮---- +// This option allows use of a custom test runner +// testRunner: "jest-circus/runner", +⋮---- +// A map from regular expressions to paths to transformers +// transform: undefined, +⋮---- +// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation +// transformIgnorePatterns: [ +// "/node_modules/", +// "\\.pnp\\.[^\\/]+$" +// ], +⋮---- +// Prevents import esm module error from v1 axios release, issue #5026 +⋮---- +// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them +// unmockedModulePathPatterns: undefined, +⋮---- +// Indicates whether each individual test should be reported during the run +// verbose: undefined, +verbose: true, // report individual test +⋮---- +// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode +// watchPathIgnorePatterns: [], +⋮---- +// Whether to use watchman for file crawling +// watchman: true, + ================ File: LICENSE.md ================ @@ -4593,248 +4871,7 @@ import { RestClientV2 } from '../../../src/index.js'; // import { RestClientV2 } from 'bitget-api'; ================ -File: examples/V2 - Classic/Rest/rest-trade-futures.ts -================ -import { - FuturesPlaceOrderRequestV2, - RestClientV2, - WebsocketClientV2, -} from '../../../src/index.js'; -⋮---- -// or -// import { FuturesPlaceOrderRequestV2, RestClientV2, WebsocketClientV2 } from '../src'; -⋮---- -// read from environmental variables -⋮---- -// If running from CLI in unix, you can pass env vars as such: -// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/rest-trade-futures.ts -⋮---- -// note the single quotes, preventing special characters such as $ from being incorrectly passed -⋮---- -// apiKey: 'apiKeyHere', -// apiSecret: 'apiSecretHere', -// apiPass: 'apiPassHere', -⋮---- -function logWSEvent(type: string, data: any) -⋮---- -// simple sleep function -function promiseSleep(milliseconds: number) -⋮---- -/** - * This is a simple script wrapped in a immediately invoked function expression (to execute the below workflow immediately). - * - * It is designed to: - * - open a private websocket channel to log account events - * - check for any available USDT balance in the futures account - * - immediately open a minimum sized long position on BTCUSDT - * - check active positions - * - immediately send closing orders for any active futures positions - * - check positions again - * - */ -⋮---- -// Add event listeners to log websocket events on account -⋮---- -// futures private -// : account updates -⋮---- -// : position updates -⋮---- -// : order updates -⋮---- -// wait briefly for ws to be ready (could also use the response or authenticated events, to make sure topics are subscribed to before starting) -⋮---- -// const balances = allBalances.filter((bal) => Number(bal.available) != 0); -⋮---- -// Loop through any active positions and send a closing market order on each position - -================ -File: examples/V2 - Classic/Rest/rest-trade-spot.ts -================ -import { - RestClientV2, - SpotOrderRequestV2, - WebsocketClientV2, -} from '../../../src/index.js'; -⋮---- -// import { RestClientV2, WebsocketClient } from '../src/index'; -⋮---- -// read from environmental variables -⋮---- -// If running from CLI in unix, you can pass env vars as such: -// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/rest-trade-spot.ts -⋮---- -// note the single quotes, preventing special characters such as $ from being incorrectly passed -⋮---- -// apiKey: 'apiKeyHere', -// apiSecret: 'apiSecretHere', -// apiPass: 'apiPassHere', -⋮---- -function logWSEvent(type: string, data: any) -⋮---- -// simple sleep function -function promiseSleep(milliseconds: number) -⋮---- -/** This is a simple script wrapped in a immediately invoked function expression, designed to check for any available BTC balance and immediately sell the full amount for USDT */ -⋮---- -// Add event listeners to log websocket events on account -⋮---- -// Subscribe to private account topics -// spot private -// : account updates -⋮---- -// : order updates (note: symbol is required) -⋮---- -// wait briefly for ws to be ready (could also use the response or authenticated events, to make sure topics are subscribed to before starting) -⋮---- -// console.log('balance: ', JSON.stringify(balances, null, 2)); - -================ -File: examples/V2 - Classic/Websocket/ws-demo-trading.ts -================ -import { DefaultLogger, WebsocketClientV2 } from '../../../src/index.js'; -⋮---- -// or -// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV2 } from 'bitget-api'; -⋮---- -// If running from CLI in unix, you can pass env vars as such: -// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/ws-private.ts -⋮---- -// restOptions: { -// optionally provide rest options, e.g. to pass through a proxy -// }, -⋮---- -// Set demoTrading to true, to route all connections to the demo trading wss URLs: -⋮---- -// If using private topics, make sure to include API keys -⋮---- -// console.log('WS raw message received ', JSON.stringify(data, null, 2)); -⋮---- -/** - * Public events - */ - -================ -File: examples/V2 - Classic/Websocket/ws-private.ts -================ -import { DefaultLogger, WebsocketClientV2 } from '../../../src/index.js'; -⋮---- -// or -// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV2 } from 'bitget-api'; -⋮---- -// If running from CLI in unix, you can pass env vars as such: -// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/ws-private.ts -⋮---- -// note the single quotes, preventing special characters such as $ from being incorrectly passed -⋮---- -// restOptions: { -// optionally provide rest options, e.g. to pass through a proxy -// }, -⋮---- -// console.log('WS raw message received ', JSON.stringify(data, null, 2)); -⋮---- -// auth happens async after the ws connection opens -⋮---- -// wsClient.subscribePublicSpotTickers(['BTCUSDT', 'LTCUSDT']); -⋮---- -/** - * Private account updates - */ -⋮---- -// spot private -// : account updates -⋮---- -// : order updates (note: symbol is required) -// wsClient.subscribeTopic('SPOT', 'orders', 'BTCUSDT'); -⋮---- -// futures private -// : account updates -⋮---- -// : position updates -// wsClient.subscribeTopic('USDT-FUTURES', 'positions'); -⋮---- -// : order updates -// wsClient.subscribeTopic('USDT-FUTURES', 'orders'); -⋮---- -// : plan order updates -// wsClient.subscribeTopic('USDT-FUTURES', 'orders-algo'); -⋮---- -// wsClient -// .getWsStore() -// .getKeys() -// .forEach((wsKey) => { -// const state = wsClient.getWsStore().get(wsKey); -// console.log(`${wsKey} state: `, state.subscribedTopics.values()); -// }); -⋮---- -// setTimeout(() => { -// wsClient.unsubscribeTopic('USDT-FUTURES', 'account'); -// }, 1000 * 2); -⋮---- -// setTimeout(() => { -// wsClient -// .getWsStore() -// .getKeys() -// .forEach((wsKey) => { -// const state = wsClient.getWsStore().get(wsKey); -// console.log(`${wsKey} state: `, state.subscribedTopics.values()); -// }); -// }, 1000 * 5); - -================ -File: examples/V2 - Classic/Websocket/ws-public.ts -================ -import { - DefaultLogger, - WebsocketClientV2, - WS_KEY_MAP, -} from '../../../src/index.js'; -⋮---- -// or -// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV2 } from 'bitget-api'; -⋮---- -// restOptions: { -// optionally provide rest options, e.g. to pass through a proxy -// }, -⋮---- -// console.log('WS raw message received ', JSON.stringify(data, null, 2)); -⋮---- -/** - * Public events - */ -⋮---- -// Spot public -⋮---- -// tickers -⋮---- -// candles -// wsClient.subscribeTopic('SPOT', 'candle1m', symbol); -⋮---- -// orderbook updates -// wsClient.subscribeTopic('SPOT', 'books', symbol); -⋮---- -// trades -// wsClient.subscribeTopic('SPOT', 'trade', symbol); -⋮---- -// Futures public -⋮---- -// tickers -// wsClient.subscribeTopic('USDT-FUTURES', 'ticker', symbol); -⋮---- -// candles -// wsClient.subscribeTopic('USDT-FUTURES', 'candle1m', symbol); -⋮---- -// orderbook updates -// wsClient.subscribeTopic('USDT-FUTURES', 'books', symbol); -⋮---- -// trades -// wsClient.subscribeTopic('USDT-FUTURES', 'trade', symbol); -⋮---- -// Topics are tracked per websocket type -// Get a list of subscribed topics (e.g. all public topics) (after a 5 second delay) - -================ -File: examples/V3 - UTA/Rest/rest-private.ts +File: examples/V3 - UTA/Rest/rest-private.ts ================ import { RestClientV3 } from '../../../src/index.js'; ⋮---- @@ -4871,1157 +4908,1175 @@ import { RestClientV3 } from '../../../src/index.js'; // import { RestClientV3 } from 'bitget-api'; ================ -File: examples/V3 - UTA/Rest/rest-trade-UTA-futures.ts +File: examples/README.md ================ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { - PlaceOrderRequestV3, - RestClientV3, - WebsocketClientV3, -} from '../../../src/index.js'; -⋮---- -// or -// import { PlaceOrderRequestV3, RestClientV3, WebsocketClientV3 } from '../src'; -⋮---- -// read from environmental variables -⋮---- -// If running from CLI in unix, you can pass env vars as such: -// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/V3/rest-trade-futures.ts -⋮---- -// note the single quotes, preventing special characters such as $ from being incorrectly passed -⋮---- -// apiKey: 'apiKeyHere', -// apiSecret: 'apiSecretHere', -// apiPass: 'apiPassHere', -⋮---- -function logWSEvent(type: string, data: any) -⋮---- -// simple sleep function -function promiseSleep(milliseconds: number) -⋮---- -/** - * This is a simple script wrapped in a immediately invoked function expression (to execute the below workflow immediately). - * - * It is designed to: - * - open a private websocket channel to log account events - * - check for any available USDT balance in the account - * - immediately open a minimum sized long position on BTCUSDT - * - check active positions - * - immediately send closing orders for any active futures positions - * - check positions again - * - */ -⋮---- -// Add event listeners to log websocket events on account -⋮---- -// Subscribe to private topics for UTA account -⋮---- -// Subscribe to position updates -⋮---- -// Subscribe to order updates -⋮---- -// wait briefly for ws to be ready (could also use the response or authenticated events, to make sure topics are subscribed to before starting) -⋮---- -// Loop through any active positions and send a closing market order on each position +# Examples + +These samples can be executed using `ts-node`: + +``` +ts-node ./examples/rest-spot-public.ts +``` + +Samples that require authentication can be edited directly but also support environmental variables. E.g. on mac/unix: + +``` +API_KEY_COM='yourkeyhere' API_SECRET_COM='yoursecrethere' API_PASS_COM='yourapipasshere' ts-node examples/rest-trade-futures.ts +``` + +They can also be converted to JavaScript by changing the imports to require & removing any type annotations. + +## V3 / Unified Trading Account (UTA) + +These newer examples are for Bitget's V3 APIs and WebSockets. They can be found in the examples/V3 folder. + +Refer to the V3 / UTA API documentation for more information on the V3 APIs: +https://www.bitget.com/api-doc/uta/intro + +These APIs require your account to be upgraded to the Unified Trading Account, if you plan on using the account-level REST APIs and WebSockets. Once upgraded, the V2 APIs are no longer available to you, unless you revert back to Classic Account mode. + +### WebSocket API (WS API) + +The V3/UTA API introduces order placement via a persisted WebSocket connection. This Bitget Node.js, JavaScript & TypeScript SDK supports Bitget's full V3 API offering, including the WebSocket API. + +There are two approaches to placing orders via the Bitget WebSocket APIs + +#### WebsocketAPIClient (recommended) + +This integration looks & feels like a REST API client, but uses WebSockets, via the WebsocketClient's sendWSAPIRequest method. It returns promises and has end to end types. + +This is the recommended approach to easily start sending orders via an automatically persisted WebSocket connection. A simple example is below, but for a more thorough example, check the example here: [./V3/ws-api-client-trade.ts](./V3/ws-api-client-trade.ts) + +```typescript +import { WebsocketAPIClient } from 'bitget-api'; +// or if you prefer require: +// const { WebsocketAPIClient } = require("bitget-api"); + +// Make an instance of the WS API Client class with your API keys +const wsClient = new WebsocketAPIClient({ + apiKey: API_KEY, + apiSecret: API_SECRET, + apiPass: API_PASS, + + // Whether to use the demo trading wss connection + // demoTrading: true, +}); + +async function start() { + // Start using it like a REST API. All actions are sent via a persisted WebSocket connection. + + /** + * Place Order + * https://www.bitget.com/api-doc/uta/websocket/private/Place-Order-Channel#request-parameters + */ + try { + const res = await wsClient.submitNewOrder('spot', { + orderType: 'limit', + price: '100', + qty: '0.1', + side: 'buy', + symbol: 'BTCUSDT', + timeInForce: 'gtc', + }); + + console.log(new Date(), 'WS API "submitNewOrder()" result: ', res); + } catch (e) { + console.error(new Date(), 'Exception with WS API "submitNewOrder()": ', e); + } +} + +start().catch((e) => console.error('Exception in example: '.e)); +``` + +#### ws.sendWSAPIRequest(wsKey, command, category, operation) + +This is the "raw" integration within the existing WebSocket client. It uses an automatically persisted & authenticated connection to send events through Bitget's WebSocket API. It automatically tracks and connects outgoing requests with incoming responses, and returns promises that resolve/reject when a matching response is received. + +Refer to [V3/ws-api-trade-raw.ts](./V3/ws-api-trade-raw.ts) to see an example. + +Note: The WebsocketClient is built around this. For a more user friendly experience, it is recommended to use the WebsocketClient for WS API requests. It uses this method but has the convenience of behaving similar to a REST API (while all communication automatically happens over a persisted WebSocket connection). + +## V2 + +These examples are for Bitget's V2 APIs and WebSockets. They can be found in the examples/V2 folder. + +Refer to the V2 API documentation for more information on the V2 APIs: +https://www.bitget.com/api-doc/common/intro ================ -File: examples/V3 - UTA/Rest/rest-trade-UTA-spot.ts +File: src/constants/enum.ts ================ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { - PlaceOrderRequestV3, - RestClientV3, - WebsocketClientV3, -} from '../../../src/index.js'; -⋮---- -// import { RestClientV3, WebsocketClientV3 } from '../src/index'; -⋮---- -// read from environmental variables +/** Parameter verification exception margin mode == FIXED */ + +================ +File: src/types/request/v3/broker.ts +================ +export interface CreateBrokerSubAccountRequestV3 { + subaccountName: string; + label: string; +} ⋮---- -// If running from CLI in unix, you can pass env vars as such: -// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/V3/rest-trade-spot.ts +export interface GetBrokerSubAccountListRequestV3 { + limit?: string; + cursor?: string; + status?: 'normal' | 'freeze'; +} ⋮---- -// note the single quotes, preventing special characters such as $ from being incorrectly passed +export interface ModifyBrokerSubAccountRequestV3 { + subUid: string; + status?: 'normal' | 'freeze'; + permList?: string[]; +} ⋮---- -// apiKey: 'apiKeyHere', -// apiSecret: 'apiSecretHere', -// apiPass: 'apiPassHere', +export interface BrokerSubWithdrawalRequestV3 { + subUid: string; + coin: string; + dest: 'on_chain' | 'internal_transfer'; + address: string; + amount: string; + chain?: string; + tag?: string; + clientOid?: string; +} ⋮---- -function logWSEvent(type: string, data: any) +export interface GetBrokerSubDepositAddressRequestV3 { + subUid: string; + coin: string; + chain?: string; +} ⋮---- -// simple sleep function -function promiseSleep(milliseconds: number) +export interface GetBrokerAllSubDepositWithdrawalRequestV3 { + startTime?: string; + endTime?: string; + limit?: string; + cursor?: string; + status?: 'pending' | 'fail' | 'success'; +} ⋮---- -/** This is a simple script wrapped in a immediately invoked function expression, designed to check for any available BTC balance and immediately sell the full amount for USDT */ +export interface GetBrokerCommissionRequestV3 { + startTime?: string; + endTime?: string; + pageSize?: string; + pageNo?: string; + bizType?: 'spot' | 'futures'; + subBizType?: + | 'spot_trade' + | 'spot_margin' + | 'usdt_futures' + | 'usdc_futures' + | 'coin_futures'; +} ⋮---- -// Add event listeners to log websocket events on account +export interface CreateBrokerSubApiKeyRequestV3 { + subUid: string; + passphrase: string; + label: string; + ipList?: string[]; + permType: 'read_and_write' | 'readonly'; + permList: string[]; +} ⋮---- -// Subscribe to private account topics -// Account updates for UTA (unified trading account) +export interface ModifyBrokerSubApiKeyRequestV3 { + subUid: string; + passphrase: string; + apiKey: string; + label?: string; + ipList?: string[]; + permType?: 'read_and_write' | 'readonly'; + permList?: string[]; +} ⋮---- -// Order updates for spot +export interface DeleteBrokerSubApiKeyRequestV3 { + subUid: string; + apiKey: string; +} ⋮---- -// wait briefly for ws to be ready (could also use the response or authenticated events, to make sure topics are subscribed to before starting) +export interface GetBrokerSubApiKeyRequestV3 { + subUid: string; +} ================ -File: examples/V3 - UTA/Websocket/ws-private.ts +File: src/types/request/v3/public.ts ================ -import { - DefaultLogger, - WebsocketClientV3, - WS_KEY_MAP, -} from '../../../src/index.js'; -⋮---- -// or -// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV2 } from 'bitget-api'; +export interface GetPublicFillsRequestV3 { + category: + | 'SPOT' + | 'MARGIN' + | 'USDT-FUTURES' + | 'COIN-FUTURES' + | 'USDC-FUTURES'; + symbol?: string; + limit?: string; +} ⋮---- -// If running from CLI in unix, you can pass env vars as such: -// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/ws-private.ts +export interface GetCandlesRequestV3 { + category: 'SPOT' | 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES'; + symbol: string; + interval: + | '1m' + | '3m' + | '5m' + | '15m' + | '30m' + | '1H' + | '4H' + | '6H' + | '12H' + | '1D'; + startTime?: string; + endTime?: string; + type?: 'MARKET' | 'MARK' | 'INDEX'; + limit?: string; +} ⋮---- -// console.log('WS raw message received ', JSON.stringify(data, null, 2)); +export interface GetHistoryCandlesRequestV3 { + category: 'SPOT' | 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES'; + symbol: string; + interval: + | '1m' + | '3m' + | '5m' + | '15m' + | '30m' + | '1H' + | '4H' + | '6H' + | '12H' + | '1D'; + startTime?: string; + endTime?: string; + type?: 'MARKET' | 'MARK' | 'INDEX'; + limit?: string; +} ⋮---- -// You can subscribe to one topic at a time +export interface GetContractsOiRequestV3 { + symbol?: string; + category: 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES'; +} ⋮---- -instType: 'UTA', // Note: all account events go on the UTA instType +export interface GetCurrentFundingRateRequestV3 { + symbol: string; +} ⋮---- -WS_KEY_MAP.v3Private, // This parameter points to private or public +export interface GetHistoryFundingRateRequestV3 { + category: 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES'; + symbol: string; + cursor?: string; + limit?: string; +} ⋮---- -// Note: all account events go on the UTA instType +export interface GetMarginLoansRequestV3 { + coin: string; +} ⋮---- -// Or multiple at once: +export interface GetOpenInterestRequestV3 { + category: 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES'; + symbol?: string; +} ⋮---- -// Topics are tracked per websocket type -// The below example will pull a list of subscribed topics on that connection (e.g. all private topics), after a 5 second delay: - -================ -File: examples/V3 - UTA/Websocket/ws-public.ts -================ -import { - DefaultLogger, - WebsocketClientV3, - WS_KEY_MAP, -} from '../../../src/index.js'; +export interface GetPositionTierRequestV3 { + category: 'MARGIN' | 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES'; + symbol?: string; + coin?: string; +} ⋮---- -// or -// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV2 } from 'bitget-api'; +export interface GetRiskReserveRequestV3 { + category: 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES'; + symbol: string; +} ⋮---- -// console.log('WS raw message received ', JSON.stringify(data, null, 2)); +export interface GetInstrumentsRequestV3 { + category: + | 'SPOT' + | 'MARGIN' + | 'USDT-FUTURES' + | 'COIN-FUTURES' + | 'USDC-FUTURES'; + symbol?: string; +} ⋮---- -/** - * Public events - */ +export interface GetMarketFeeGroupRequestV3 { + category: 'SPOT' | 'FUTURES'; + group?: 'GROUP_A' | 'GROUP_B' | 'GROUP_C'; +} ⋮---- -// You can subscribe to one topic at a time +export interface GetMarketScoreWeightsRequestV3 { + category?: 'SPOT' | 'FUTURES'; +} ⋮---- -WS_KEY_MAP.v3Public, // This parameter points to private or public +export interface GetOrderBookRequestV3 { + category: 'SPOT' | 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES'; + symbol: string; + limit?: string; +} ⋮---- -// Or multiple at once: +export interface GetTickersRequestV3 { + category: 'SPOT' | 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES'; + symbol?: string; +} ⋮---- -// Topics are tracked per websocket type -// The below example will pull a list of subscribed topics on that connection (e.g. all public topics), after a 5 second delay: +export interface GetIndexComponentsRequestV3 { + symbol: string; +} ================ -File: examples/V3 - UTA/WS-API/ws-api-trade-raw.ts +File: src/types/response/v3/broker.ts ================ -import { - DefaultLogger, - WebsocketClientV3, - WS_KEY_MAP, -} from '../../../src/index.js'; +export interface CreateBrokerSubAccountResponseV3 { + subUid: string; + subaccountName: string; + subaccountEmail: string; + status: 'normal' | 'freeze'; + permList: string[]; + label: string; + cTime: string; +} ⋮---- -// or -// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV3 } from 'bitget-api'; +export interface BrokerSubAccountV3 { + subUid: string; + subaccountName: string; + subaccountEmail: string | null; + status: 'normal' | 'freeze'; + permList: string[]; + label: string; + language: string; + cTime: string; + uTime: string; +} ⋮---- -// If running from CLI in unix, you can pass env vars as such: -// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/ws-private.ts +export interface GetBrokerSubAccountListResponseV3 { + subList: BrokerSubAccountV3[]; +} ⋮---- -// console.log('WS raw message received ', JSON.stringify(data, null, 2)); +export interface ModifyBrokerSubAccountResponseV3 { + subUid: string; + subaccountName: string; + status: 'normal' | 'freeze'; + permList: string[]; + label: string; + cTime: string; + uTime: string; +} ⋮---- -/** - * Bitget's WebSocket API can be used via the sendWSAPIRequest() method. - * - * Use the `WS_KEY_MAP.v3Private` connection key for any requests. - * - * Note: this requires V3/UTA API keys! - * Note: for a better user experience, it is recommended to use the WebsocketAPIClient. - */ +export interface BrokerSubWithdrawalResponseV3 { + orderId: string; + clientOid: string; +} ⋮---- -// Use the V3 private wss connection URL +export interface BrokerSubDepositAddressV3 { + subUid: string; + coin: string; + address: string; + chain: string; + tag: string | null; + url: string; + cTime: string; +} ⋮---- -/** - * Place Order - * https://www.bitget.com/api-doc/uta/websocket/private/Place-Order-Channel#request-parameters - */ +export interface BrokerSubDepositWithdrawalRecordV3 { + uid: string; + txId: string; + type: 'deposit' | 'withdrawal'; + subType: 'onchain' | 'internal' | 'fast'; + coin: string; + amount: string; + status: 'pending' | 'fail' | 'success'; + ts: string; +} ⋮---- -/** - const res = { - "event": "trade", - "id": "1750034396082", - "category": "spot", - "topic": "place-order", - "args": [ - { - "symbol": "BTCUSDT", - "orderId": "xxxxxxxx", - "clientOid": "xxxxxxxx", - "cTime": "1750034397008" - } - ], - "code": "0", - "msg": "success", - "ts": "1750034397076" - }; - */ +export interface GetBrokerAllSubDepositWithdrawalResponseV3 { + list: BrokerSubDepositWithdrawalRecordV3[]; + endId: string; +} ⋮---- -/** - * Batch Place Order Channel - * https://www.bitget.com/api-doc/uta/websocket/private/Batch-Place-Order-Channel - */ +export interface BrokerCommissionRecordV3 { + uid: string; + coin: string; + symbol: string; + dealtAmount: string; + totalFee: string; + deductedFee: string; + paidFee: string; + markUpFee: string; + totalCommission: string; +} ⋮---- -/** - * Note: batch place will never reject the request, even if all orders were rejected. Check the "code" and "msg" properties for individual orders in the response, to detect batch place errors. - */ +export interface CreateBrokerSubApiKeyResponseV3 { + subUid: string; + label: string; + apiKey: string; + secretKey: string; + permType: 'read_and_write' | 'readonly'; + permList: string[]; + ipList: string[] | null; +} ⋮---- -/** - const res = { - "event": "trade", - "id": "1750035029506", - "category": "spot", - "topic": "batch-place", - "args": [ - { - "code": "0", - "msg": "Success", - "symbol": "BTCUSDT", - "orderId": "xxxxxxxx", - "clientOid": "xxxxxxxx" - }, - { - "code": "0", - "msg": "Success", - "symbol": "BTCUSDT", - "orderId": "xxxxxxxx", - "clientOid": "xxxxxxxx" - } - ], - "code": "0", - "msg": "Success", - "ts": "1750035029925" - } - */ -⋮---- -/** - * Cancel Order - * https://www.bitget.com/api-doc/uta/websocket/private/Cancel-Order-Channel - */ -⋮---- -/** - const res = { - "event": "trade", - "id": "1750034870205", - "topic": "cancel-order", - "args": [ - { - "orderId": "xxxxxxxx", - "clientOid": "xxxxxxxx" - } - ], - "code": "0", - "msg": "Success", - "ts": "1750034870597" - } - */ -⋮---- -/** - * Batch Cancel Order - * https://www.bitget.com/api-doc/uta/websocket/private/Batch-Cancel-Order-Channel - */ +export interface ModifyBrokerSubApiKeyResponseV3 { + subUid: string; + label: string; + apiKey: string; + permType: 'read_and_write' | 'readonly'; + permList: string[]; + ipList: string[]; +} ⋮---- -/** - const res = { - "event": "trade", - "id": "bb553cc0-c1fa-454e-956d-c96c8d715760", - "topic": "batch-cancel", - "args": [ - { - "code": "0", - "msg": "Success", - "orderId": "xxxxxxxxxxxxx" - }, - { - "code": "25204", - "msg": "Order does not exist", - "orderId": "xxxxxxxxxxxxx" - } - ], - "code": "0", - "msg": "Success", - "ts": "1751980011084" - } - */ - -================ -File: examples/README.md -================ -# Examples - -These samples can be executed using `ts-node`: - -``` -ts-node ./examples/rest-spot-public.ts -``` - -Samples that require authentication can be edited directly but also support environmental variables. E.g. on mac/unix: - -``` -API_KEY_COM='yourkeyhere' API_SECRET_COM='yoursecrethere' API_PASS_COM='yourapipasshere' ts-node examples/rest-trade-futures.ts -``` - -They can also be converted to JavaScript by changing the imports to require & removing any type annotations. - -## V3 / Unified Trading Account (UTA) - -These newer examples are for Bitget's V3 APIs and WebSockets. They can be found in the examples/V3 folder. - -Refer to the V3 / UTA API documentation for more information on the V3 APIs: -https://www.bitget.com/api-doc/uta/intro - -These APIs require your account to be upgraded to the Unified Trading Account, if you plan on using the account-level REST APIs and WebSockets. Once upgraded, the V2 APIs are no longer available to you, unless you revert back to Classic Account mode. - -### WebSocket API (WS API) - -The V3/UTA API introduces order placement via a persisted WebSocket connection. This Bitget Node.js, JavaScript & TypeScript SDK supports Bitget's full V3 API offering, including the WebSocket API. - -There are two approaches to placing orders via the Bitget WebSocket APIs - -#### WebsocketAPIClient (recommended) - -This integration looks & feels like a REST API client, but uses WebSockets, via the WebsocketClient's sendWSAPIRequest method. It returns promises and has end to end types. - -This is the recommended approach to easily start sending orders via an automatically persisted WebSocket connection. A simple example is below, but for a more thorough example, check the example here: [./V3/ws-api-client-trade.ts](./V3/ws-api-client-trade.ts) - -```typescript -import { WebsocketAPIClient } from 'bitget-api'; -// or if you prefer require: -// const { WebsocketAPIClient } = require("bitget-api"); - -// Make an instance of the WS API Client class with your API keys -const wsClient = new WebsocketAPIClient({ - apiKey: API_KEY, - apiSecret: API_SECRET, - apiPass: API_PASS, - - // Whether to use the demo trading wss connection - // demoTrading: true, -}); - -async function start() { - // Start using it like a REST API. All actions are sent via a persisted WebSocket connection. - - /** - * Place Order - * https://www.bitget.com/api-doc/uta/websocket/private/Place-Order-Channel#request-parameters - */ - try { - const res = await wsClient.submitNewOrder('spot', { - orderType: 'limit', - price: '100', - qty: '0.1', - side: 'buy', - symbol: 'BTCUSDT', - timeInForce: 'gtc', - }); - - console.log(new Date(), 'WS API "submitNewOrder()" result: ', res); - } catch (e) { - console.error(new Date(), 'Exception with WS API "submitNewOrder()": ', e); - } +export interface GetBrokerSubApiKeyResponseV3 { + subUid: string; + label: string; + apiKey: string; + secretKey: string; + permType: 'read_and_write' | 'readonly'; + permList: string[]; + ipList: string[] | null; } -start().catch((e) => console.error('Exception in example: '.e)); -``` - -#### ws.sendWSAPIRequest(wsKey, command, category, operation) - -This is the "raw" integration within the existing WebSocket client. It uses an automatically persisted & authenticated connection to send events through Bitget's WebSocket API. It automatically tracks and connects outgoing requests with incoming responses, and returns promises that resolve/reject when a matching response is received. - -Refer to [V3/ws-api-trade-raw.ts](./V3/ws-api-trade-raw.ts) to see an example. - -Note: The WebsocketClient is built around this. For a more user friendly experience, it is recommended to use the WebsocketClient for WS API requests. It uses this method but has the convenience of behaving similar to a REST API (while all communication automatically happens over a persisted WebSocket connection). - -## V2 - -These examples are for Bitget's V2 APIs and WebSockets. They can be found in the examples/V2 folder. - -Refer to the V2 API documentation for more information on the V2 APIs: -https://www.bitget.com/api-doc/common/intro - -================ -File: src/constants/enum.ts ================ -/** Parameter verification exception margin mode == FIXED */ - -================ -File: src/types/request/v3/broker.ts +File: src/types/response/v3/loan.ts ================ -export interface CreateBrokerSubAccountRequestV3 { - subaccountName: string; - label: string; +export interface LoanTransfersV3 { + coin: string; + transfered: string; + userId: string; } ⋮---- -export interface GetBrokerSubAccountListRequestV3 { - limit?: string; - cursor?: string; - status?: 'normal' | 'freeze'; +export interface LoanSymbolSettingV3 { + symbol: string; + leverage: string; } ⋮---- -export interface ModifyBrokerSubAccountRequestV3 { - subUid: string; - status?: 'normal' | 'freeze'; - permList?: string[]; +export interface LoanSymbolsV3 { + productId: string; + spotSymbols: string[]; + marginLeverage: string; + usdtContractLeverage: string; + coinContractLeverage: string; + usdcContractLeverage: string; + usdtContractSymbols: LoanSymbolSettingV3[]; + coinContractSymbols: LoanSymbolSettingV3[]; + usdcContractSymbols: LoanSymbolSettingV3[]; +} +⋮---- +export interface RepaidHistoryItemV3 { + repayOrderId: string; + businessType: 'normal' | 'liquidation'; + repayType: 'all' | 'part'; + repaidTime: string; + coin: string; + repayAmount: string; + repayInterest: string; +} +⋮---- +export interface LoanProductInfoV3 { + productId: string; + leverage: string; + supportUsdtContract: 'YES' | 'NO'; + supportCoinContract: 'YES' | 'NO'; + supportUsdcContract: 'YES' | 'NO'; + transferLine: string; + spotBuyLine: string; + usdtContractOpenLine: string; + coinContractOpenLine: string; + usdcContractOpenLine: string; + liquidationLine: string; + stopLiquidationLine: string; +} +⋮---- +export interface LoanOrderV3 { + orderId: string; + orderProductId: string; + uid: string; + loanTime: string; + loanCoin: string; + loanAmount: string; + unpaidAmount: string; + unpaidInterest: string; + repaidAmount: string; + repaidInterest: string; + reserve: string; + status: 'not_paid_off' | 'paid_off'; +} +⋮---- +/** Tiered conversion rate item (when Tiered Discount Rate Model is enabled) */ +export interface ConvertRatioListItemV3 { + ladder: string; + convertRatio: string; +} +⋮---- +export interface CoinInfoV3 { + coin: string; + convertRatio: string; + maxConvertValue: string; + /** Tiered conversion rate (when margin mode is Tiered Discount Rate Model) */ + convertRatioList?: ConvertRatioListItemV3[]; +} +⋮---- +/** Tiered conversion rate (when margin mode is Tiered Discount Rate Model) */ +⋮---- +export interface BindUidResponseV3 { + riskUnitId: string; + uid: string; + operate: 'bind' | 'unbind'; +} +⋮---- +export interface UnpaidInfoV3 { + coin: string; + unpaidQty: string; + unpaidInterest: string; } ⋮---- -export interface BrokerSubWithdrawalRequestV3 { - subUid: string; +export interface BalanceInfoV3 { coin: string; - dest: 'on_chain' | 'internal_transfer'; - address: string; + price: string; amount: string; - chain?: string; - tag?: string; - clientOid?: string; + convertedUsdtAmount: string; } ⋮---- -export interface GetBrokerSubDepositAddressRequestV3 { - subUid: string; - coin: string; - chain?: string; +export interface LTVConvertResponseV3 { + ltv: string; + subAccountUids: string[]; + unpaidUsdtAmount: string; + usdtBalance: string; + unpaidInfo: UnpaidInfoV3[]; + balanceInfo: BalanceInfoV3[]; } ⋮---- -export interface GetBrokerAllSubDepositWithdrawalRequestV3 { - startTime?: string; - endTime?: string; - limit?: string; - cursor?: string; - status?: 'pending' | 'fail' | 'success'; -} +/* Unified Account Staking & Lending (Crypto Loans) - /api/v3/loan/* */ ⋮---- -export interface GetBrokerCommissionRequestV3 { - startTime?: string; - endTime?: string; - pageSize?: string; - pageNo?: string; - bizType?: 'spot' | 'futures'; - subBizType?: - | 'spot_trade' - | 'spot_margin' - | 'usdt_futures' - | 'usdc_futures' - | 'coin_futures'; +export interface LoanCoinInfoV3 { + coin: string; + hourRateFlexible: string; + rateFlexible: string; + hourRate7D: string; + rate7D: string; + hourRate30D: string; + rate30D: string; + minBorrowAmount: string; + maxBorrowAmount: string; + minBorrowLimit: string; + maxBorrowLimit: string; } ⋮---- -export interface CreateBrokerSubApiKeyRequestV3 { - subUid: string; - passphrase: string; - label: string; - ipList?: string[]; - permType: 'read_and_write' | 'readonly'; - permList: string[]; +export interface LoanPledgeInfoV3 { + coin: string; + initRate: string; + supRate: string; + forceRate: string; + minPledgeAmount: string; + maxPledgeAmount: string; } ⋮---- -export interface ModifyBrokerSubApiKeyRequestV3 { - subUid: string; - passphrase: string; - apiKey: string; - label?: string; - ipList?: string[]; - permType?: 'read_and_write' | 'readonly'; - permList?: string[]; +export interface GetLoanCoinsResponseV3 { + loanInfos: LoanCoinInfoV3[]; + pledgeInfos: LoanPledgeInfoV3[]; } ⋮---- -export interface DeleteBrokerSubApiKeyRequestV3 { - subUid: string; - apiKey: string; +export interface GetLoanInterestResponseV3 { + hourInterest: string; + loanAmount: string; } ⋮---- -export interface GetBrokerSubApiKeyRequestV3 { - subUid: string; +export interface LoanBorrowResponseV3 { + orderId: string; } - -================ -File: src/types/request/v3/public.ts -================ -export interface GetPublicFillsRequestV3 { - category: - | 'SPOT' - | 'MARGIN' - | 'USDT-FUTURES' - | 'COIN-FUTURES' - | 'USDC-FUTURES'; - symbol?: string; - limit?: string; +⋮---- +export interface LoanBorrowOngoingItemV3 { + orderId: string; + loanCoin: string; + loanAmount: string; + interestAmount: string; + hourInterestRate: string; + pledgeCoin: string; + pledgeAmount: string; + pledgeRate: string; + supRate: string; + forceRate: string; + borrowTime: string; + expireTime: string; } ⋮---- -export interface GetCandlesRequestV3 { - category: 'SPOT' | 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES'; - symbol: string; - interval: - | '1m' - | '3m' - | '5m' - | '15m' - | '30m' - | '1H' - | '4H' - | '6H' - | '12H' - | '1D'; - startTime?: string; - endTime?: string; - type?: 'MARKET' | 'MARK' | 'INDEX'; - limit?: string; +export interface LoanBorrowHistoryItemV3 { + orderId: string; + loanCoin: string; + pledgeCoin: string; + initPledgeAmount: string; + initLoanAmount: string; + hourRate: string; + daily: string; + borrowTime: string; + status: string; } ⋮---- -export interface GetHistoryCandlesRequestV3 { - category: 'SPOT' | 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES'; - symbol: string; - interval: - | '1m' - | '3m' - | '5m' - | '15m' - | '30m' - | '1H' - | '4H' - | '6H' - | '12H' - | '1D'; - startTime?: string; - endTime?: string; - type?: 'MARKET' | 'MARK' | 'INDEX'; - limit?: string; +export interface LoanRepayResponseV3 { + loanCoin: string; + pledgeCoin: string; + repayAmount: string; + payInterest: string; + repayLoanAmount: string; + repayUnlockAmount: string; } ⋮---- -export interface GetContractsOiRequestV3 { - symbol?: string; - category: 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES'; +export interface LoanRepayHistoryItemV3 { + orderId: string; + loanCoin: string; + pledgeCoin: string; + repayAmount: string; + payInterest: string; + repayLoanAmount: string; + repayUnlockAmount: string; + repayTime: string; } ⋮---- -export interface GetCurrentFundingRateRequestV3 { - symbol: string; +export interface LoanRevisePledgeResponseV3 { + loanCoin: string; + pledgeCoin: string; + afterPledgeRate: string; } ⋮---- -export interface GetHistoryFundingRateRequestV3 { - category: 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES'; - symbol: string; - cursor?: string; - limit?: string; +export interface LoanPledgeRateHistoryItemV3 { + loanCoin: string; + pledgeCoin: string; + orderId: string; + reviseTime: string; + reviseSide: string; + reviseAmount: string; + afterPledgeRate: string; + beforePledgeRate: string; } ⋮---- -export interface GetMarginLoansRequestV3 { +export interface LoanDebtInfoV3 { coin: string; + amount: string; + amountUsdt: string; } ⋮---- -export interface GetOpenInterestRequestV3 { - category: 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES'; - symbol?: string; +export interface GetLoanDebtsResponseV3 { + pledgeInfos: LoanDebtInfoV3[]; + loanInfos: LoanDebtInfoV3[]; } ⋮---- -export interface GetPositionTierRequestV3 { - category: 'MARGIN' | 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES'; - symbol?: string; - coin?: string; +export interface LoanReduceItemV3 { + orderId: string; + loanCoin: string; + pledgeCoin: string; + reduceTime: string; + pledgeRate: string; + pledgePrice: string; + status: string; + pledgeAmount: string; + reduceFee: string; + residueAmount: string; + runlockAmount: string; + repayLoanAmount: string; } + +================ +File: src/types/shared.ts +================ +import { REST_CLIENT_TYPE_ENUM } from '../util/requestUtils.js'; ⋮---- -export interface GetRiskReserveRequestV3 { - category: 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES'; - symbol: string; -} +export type numberInString = string; ⋮---- -export interface GetInstrumentsRequestV3 { - category: - | 'SPOT' - | 'MARGIN' - | 'USDT-FUTURES' - | 'COIN-FUTURES' - | 'USDC-FUTURES'; - symbol?: string; -} +export type OrderSide = 'Buy' | 'Sell'; ⋮---- -export interface GetOrderBookRequestV3 { - category: 'SPOT' | 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES'; - symbol: string; - limit?: string; -} +/** + * @deprecated use SpotKlineInterval or FuturesKlineInterval, depending on which API group you're using + */ +export type KlineInterval = + | '1min' + | '5min' + | '15min' + | '30min' + | '1h' + | '4h' + | '6h' + | '12h' + | '1M' + | '1W' + | '1week' + | '6Hutc' + | '12Hutc' + | '1Dutc' + | '3Dutc' + | '1Wutc' + | '1Mutc'; ⋮---- -export interface GetTickersRequestV3 { - category: 'SPOT' | 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES'; - symbol?: string; +export type RestClientType = + (typeof REST_CLIENT_TYPE_ENUM)[keyof typeof REST_CLIENT_TYPE_ENUM]; +⋮---- +export interface APIResponse { + code: string; + requestTime: number; + msg: 'success' | string; + data: T; } + +================ +File: webpack/webpack.config.cjs +================ +function generateConfig(name) ⋮---- -export interface GetIndexComponentsRequestV3 { - symbol: string; -} +// Add '.ts' and '.tsx' as resolvable extensions. +⋮---- +// Node.js core modules not available in browsers +// The REST client's https.Agent (for keepAlive) is Node.js-only and won't work in browsers +⋮---- +// Code is already transpiled from TypeScript, no additional loaders needed ================ -File: src/types/response/v3/broker.ts +File: tsconfig.json ================ -export interface CreateBrokerSubAccountResponseV3 { - subUid: string; - subaccountName: string; - subaccountEmail: string; - status: 'normal' | 'freeze'; - permList: string[]; - label: string; - cTime: string; +{ + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "baseUrl": ".", + "noEmitOnError": true, + "declaration": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": false, + "inlineSourceMap": false, + "lib": ["esnext", "DOM"], + "listEmittedFiles": false, + "listFiles": false, + "moduleResolution": "node", + "noFallthroughCasesInSwitch": true, + "noImplicitAny": true, + "noUnusedParameters": true, + "pretty": true, + "removeComments": false, + "resolveJsonModule": true, + "skipLibCheck": false, + "sourceMap": true, + "strict": true, + "strictNullChecks": true, + "types": ["node", "jest"], + "module": "commonjs", + "outDir": "dist/cjs", + "target": "esnext" + }, + "compileOnSave": true, + "exclude": ["node_modules", "dist"], + "include": ["src/**/*.*", "test/**/*.*", ".eslintrc.cjs"] } + +================ +File: examples/V2 - Classic/Rest/rest-trade-futures.ts +================ +import { + FuturesPlaceOrderRequestV2, + RestClientV2, + WebsocketClientV2, +} from '../../../src/index.js'; ⋮---- -export interface BrokerSubAccountV3 { - subUid: string; - subaccountName: string; - subaccountEmail: string | null; - status: 'normal' | 'freeze'; - permList: string[]; - label: string; - language: string; - cTime: string; - uTime: string; -} +// or +// import { FuturesPlaceOrderRequestV2, RestClientV2, WebsocketClientV2 } from '../src'; ⋮---- -export interface GetBrokerSubAccountListResponseV3 { - subList: BrokerSubAccountV3[]; -} +// read from environmental variables ⋮---- -export interface ModifyBrokerSubAccountResponseV3 { - subUid: string; - subaccountName: string; - status: 'normal' | 'freeze'; - permList: string[]; - label: string; - cTime: string; - uTime: string; -} +// If running from CLI in unix, you can pass env vars as such: +// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/rest-trade-futures.ts ⋮---- -export interface BrokerSubWithdrawalResponseV3 { - orderId: string; - clientOid: string; -} +// note the single quotes, preventing special characters such as $ from being incorrectly passed ⋮---- -export interface BrokerSubDepositAddressV3 { - subUid: string; - coin: string; - address: string; - chain: string; - tag: string | null; - url: string; - cTime: string; -} +// apiKey: 'apiKeyHere', +// apiSecret: 'apiSecretHere', +// apiPass: 'apiPassHere', ⋮---- -export interface BrokerSubDepositWithdrawalRecordV3 { - uid: string; - txId: string; - type: 'deposit' | 'withdrawal'; - subType: 'onchain' | 'internal' | 'fast'; - coin: string; - amount: string; - status: 'pending' | 'fail' | 'success'; - ts: string; -} +function logWSEvent(type: string, data: any) ⋮---- -export interface GetBrokerAllSubDepositWithdrawalResponseV3 { - list: BrokerSubDepositWithdrawalRecordV3[]; - endId: string; -} +// simple sleep function +function promiseSleep(milliseconds: number) ⋮---- -export interface BrokerCommissionRecordV3 { - uid: string; - coin: string; - symbol: string; - dealtAmount: string; - totalFee: string; - deductedFee: string; - paidFee: string; - markUpFee: string; - totalCommission: string; -} +/** + * This is a simple script wrapped in a immediately invoked function expression (to execute the below workflow immediately). + * + * It is designed to: + * - open a private websocket channel to log account events + * - check for any available USDT balance in the futures account + * - immediately open a minimum sized long position on BTCUSDT + * - check active positions + * - immediately send closing orders for any active futures positions + * - check positions again + * + */ ⋮---- -export interface CreateBrokerSubApiKeyResponseV3 { - subUid: string; - label: string; - apiKey: string; - secretKey: string; - permType: 'read_and_write' | 'readonly'; - permList: string[]; - ipList: string[] | null; -} +// Add event listeners to log websocket events on account ⋮---- -export interface ModifyBrokerSubApiKeyResponseV3 { - subUid: string; - label: string; - apiKey: string; - permType: 'read_and_write' | 'readonly'; - permList: string[]; - ipList: string[]; -} +// futures private +// : account updates ⋮---- -export interface GetBrokerSubApiKeyResponseV3 { - subUid: string; - label: string; - apiKey: string; - secretKey: string; - permType: 'read_and_write' | 'readonly'; - permList: string[]; - ipList: string[] | null; -} +// : position updates +⋮---- +// : order updates +⋮---- +// wait briefly for ws to be ready (could also use the response or authenticated events, to make sure topics are subscribed to before starting) +⋮---- +// const balances = allBalances.filter((bal) => Number(bal.available) != 0); +⋮---- +// Loop through any active positions and send a closing market order on each position ================ -File: src/types/response/v3/loan.ts +File: examples/V2 - Classic/Rest/rest-trade-spot.ts ================ -export interface LoanTransfersV3 { - coin: string; - transfered: string; - userId: string; -} -⋮---- -export interface LoanSymbolSettingV3 { - symbol: string; - leverage: string; -} -⋮---- -export interface LoanSymbolsV3 { - productId: string; - spotSymbols: string[]; - marginLeverage: string; - usdtContractLeverage: string; - coinContractLeverage: string; - usdcContractLeverage: string; - usdtContractSymbols: LoanSymbolSettingV3[]; - coinContractSymbols: LoanSymbolSettingV3[]; - usdcContractSymbols: LoanSymbolSettingV3[]; -} +import { + RestClientV2, + SpotOrderRequestV2, + WebsocketClientV2, +} from '../../../src/index.js'; ⋮---- -export interface RepaidHistoryItemV3 { - repayOrderId: string; - businessType: 'normal' | 'liquidation'; - repayType: 'all' | 'part'; - repaidTime: string; - coin: string; - repayAmount: string; - repayInterest: string; -} +// import { RestClientV2, WebsocketClient } from '../src/index'; ⋮---- -export interface LoanProductInfoV3 { - productId: string; - leverage: string; - supportUsdtContract: 'YES' | 'NO'; - supportCoinContract: 'YES' | 'NO'; - supportUsdcContract: 'YES' | 'NO'; - transferLine: string; - spotBuyLine: string; - usdtContractOpenLine: string; - coinContractOpenLine: string; - usdcContractOpenLine: string; - liquidationLine: string; - stopLiquidationLine: string; -} +// read from environmental variables ⋮---- -export interface LoanOrderV3 { - orderId: string; - orderProductId: string; - uid: string; - loanTime: string; - loanCoin: string; - loanAmount: string; - unpaidAmount: string; - unpaidInterest: string; - repaidAmount: string; - repaidInterest: string; - reserve: string; - status: 'not_paid_off' | 'paid_off'; -} +// If running from CLI in unix, you can pass env vars as such: +// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/rest-trade-spot.ts ⋮---- -export interface CoinInfoV3 { - coin: string; - convertRatio: string; - maxConvertValue: string; -} +// note the single quotes, preventing special characters such as $ from being incorrectly passed ⋮---- -export interface BindUidResponseV3 { - riskUnitId: string; - uid: string; - operate: 'bind' | 'unbind'; -} +// apiKey: 'apiKeyHere', +// apiSecret: 'apiSecretHere', +// apiPass: 'apiPassHere', ⋮---- -export interface UnpaidInfoV3 { - coin: string; - unpaidQty: string; - unpaidInterest: string; -} +function logWSEvent(type: string, data: any) ⋮---- -export interface BalanceInfoV3 { - coin: string; - price: string; - amount: string; - convertedUsdtAmount: string; -} +// simple sleep function +function promiseSleep(milliseconds: number) ⋮---- -export interface LTVConvertResponseV3 { - ltv: string; - subAccountUids: string[]; - unpaidUsdtAmount: string; - usdtBalance: string; - unpaidInfo: UnpaidInfoV3[]; - balanceInfo: BalanceInfoV3[]; -} - -================ -File: src/types/shared.ts -================ -import { REST_CLIENT_TYPE_ENUM } from '../util/requestUtils.js'; +/** This is a simple script wrapped in a immediately invoked function expression, designed to check for any available BTC balance and immediately sell the full amount for USDT */ ⋮---- -export type numberInString = string; +// Add event listeners to log websocket events on account ⋮---- -export type OrderSide = 'Buy' | 'Sell'; +// Subscribe to private account topics +// spot private +// : account updates ⋮---- -/** - * @deprecated use SpotKlineInterval or FuturesKlineInterval, depending on which API group you're using - */ -export type KlineInterval = - | '1min' - | '5min' - | '15min' - | '30min' - | '1h' - | '4h' - | '6h' - | '12h' - | '1M' - | '1W' - | '1week' - | '6Hutc' - | '12Hutc' - | '1Dutc' - | '3Dutc' - | '1Wutc' - | '1Mutc'; +// : order updates (note: symbol is required) ⋮---- -export type RestClientType = - (typeof REST_CLIENT_TYPE_ENUM)[keyof typeof REST_CLIENT_TYPE_ENUM]; +// wait briefly for ws to be ready (could also use the response or authenticated events, to make sure topics are subscribed to before starting) ⋮---- -export interface APIResponse { - code: string; - requestTime: number; - msg: 'success' | string; - data: T; -} +// console.log('balance: ', JSON.stringify(balances, null, 2)); ================ -File: webpack/webpack.config.cjs +File: examples/V2 - Classic/Websocket/ws-demo-trading.ts ================ -function generateConfig(name) +import { DefaultLogger, WebsocketClientV2 } from '../../../src/index.js'; ⋮---- -// Add '.ts' and '.tsx' as resolvable extensions. +// or +// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV2 } from 'bitget-api'; ⋮---- -// Node.js core modules not available in browsers -// The REST client's https.Agent (for keepAlive) is Node.js-only and won't work in browsers +// If running from CLI in unix, you can pass env vars as such: +// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/ws-private.ts ⋮---- -// Code is already transpiled from TypeScript, no additional loaders needed - -================ -File: .eslintrc.cjs -================ -// 'no-unused-vars': ['warn'], +// restOptions: { +// optionally provide rest options, e.g. to pass through a proxy +// }, +⋮---- +// Set demoTrading to true, to route all connections to the demo trading wss URLs: +⋮---- +// If using private topics, make sure to include API keys +⋮---- +// console.log('WS raw message received ', JSON.stringify(data, null, 2)); +⋮---- +/** + * Public events + */ ================ -File: jest.config.ts +File: examples/V2 - Classic/Websocket/ws-private.ts ================ -/** - * For a detailed explanation regarding each configuration property, visit: - * https://jestjs.io/docs/configuration - */ +import { DefaultLogger, WebsocketClientV2 } from '../../../src/index.js'; ⋮---- -import type { Config } from 'jest'; +// or +// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV2 } from 'bitget-api'; ⋮---- -// All imported modules in your tests should be mocked automatically -// automock: false, +// If running from CLI in unix, you can pass env vars as such: +// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/ws-private.ts ⋮---- -// Stop running tests after `n` failures -// bail: 0, -bail: false, // enable to stop test when an error occur, +// note the single quotes, preventing special characters such as $ from being incorrectly passed ⋮---- -// The directory where Jest should store its cached dependency information -// cacheDirectory: "/private/var/folders/kf/2k3sz4px6c9cbyzj1h_b192h0000gn/T/jest_dx", +// restOptions: { +// optionally provide rest options, e.g. to pass through a proxy +// }, ⋮---- -// Automatically clear mock calls, instances, contexts and results before every test +// console.log('WS raw message received ', JSON.stringify(data, null, 2)); ⋮---- -// Indicates whether the coverage information should be collected while executing the test +// auth happens async after the ws connection opens ⋮---- -// An array of glob patterns indicating a set of files for which coverage information should be collected +// wsClient.subscribePublicSpotTickers(['BTCUSDT', 'LTCUSDT']); ⋮---- -// The directory where Jest should output its coverage files +/** + * Private account updates + */ ⋮---- -// An array of regexp pattern strings used to skip coverage collection -// coveragePathIgnorePatterns: [ -// "/node_modules/" -// ], +// spot private +// : account updates ⋮---- -// Indicates which provider should be used to instrument code for coverage +// : order updates (note: symbol is required) +// wsClient.subscribeTopic('SPOT', 'orders', 'BTCUSDT'); ⋮---- -// A list of reporter names that Jest uses when writing coverage reports -// coverageReporters: [ -// "json", -// "text", -// "lcov", -// "clover" -// ], +// futures private +// : account updates ⋮---- -// An object that configures minimum threshold enforcement for coverage results -// coverageThreshold: undefined, +// : position updates +// wsClient.subscribeTopic('USDT-FUTURES', 'positions'); ⋮---- -// A path to a custom dependency extractor -// dependencyExtractor: undefined, +// : order updates +// wsClient.subscribeTopic('USDT-FUTURES', 'orders'); ⋮---- -// Make calling deprecated APIs throw helpful error messages -// errorOnDeprecated: false, +// : plan order updates +// wsClient.subscribeTopic('USDT-FUTURES', 'orders-algo'); ⋮---- -// The default configuration for fake timers -// fakeTimers: { -// "enableGlobally": false +// wsClient +// .getWsStore() +// .getKeys() +// .forEach((wsKey) => { +// const state = wsClient.getWsStore().get(wsKey); +// console.log(`${wsKey} state: `, state.subscribedTopics.values()); +// }); +⋮---- +// setTimeout(() => { +// wsClient.unsubscribeTopic('USDT-FUTURES', 'account'); +// }, 1000 * 2); +⋮---- +// setTimeout(() => { +// wsClient +// .getWsStore() +// .getKeys() +// .forEach((wsKey) => { +// const state = wsClient.getWsStore().get(wsKey); +// console.log(`${wsKey} state: `, state.subscribedTopics.values()); +// }); +// }, 1000 * 5); + +================ +File: examples/V2 - Classic/Websocket/ws-public.ts +================ +import { + DefaultLogger, + WebsocketClientV2, + WS_KEY_MAP, +} from '../../../src/index.js'; +⋮---- +// or +// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV2 } from 'bitget-api'; +⋮---- +// restOptions: { +// optionally provide rest options, e.g. to pass through a proxy // }, ⋮---- -// Force coverage collection from ignored files using an array of glob patterns -// forceCoverageMatch: [], +// console.log('WS raw message received ', JSON.stringify(data, null, 2)); ⋮---- -// A path to a module which exports an async function that is triggered once before all test suites -// globalSetup: undefined, +/** + * Public events + */ ⋮---- -// A path to a module which exports an async function that is triggered once after all test suites -// globalTeardown: undefined, +// Spot public ⋮---- -// A set of global variables that need to be available in all test environments -// globals: {}, +// tickers ⋮---- -// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers. -// maxWorkers: "50%", +// candles +// wsClient.subscribeTopic('SPOT', 'candle1m', symbol); ⋮---- -// An array of directory names to be searched recursively up from the requiring module's location -// moduleDirectories: [ -// "node_modules" -// ], +// orderbook updates +// wsClient.subscribeTopic('SPOT', 'books', symbol); ⋮---- -// An array of file extensions your modules use +// trades +// wsClient.subscribeTopic('SPOT', 'trade', symbol); +⋮---- +// Futures public +⋮---- +// tickers +// wsClient.subscribeTopic('USDT-FUTURES', 'ticker', symbol); +⋮---- +// candles +// wsClient.subscribeTopic('USDT-FUTURES', 'candle1m', symbol); +⋮---- +// orderbook updates +// wsClient.subscribeTopic('USDT-FUTURES', 'books', symbol); +⋮---- +// trades +// wsClient.subscribeTopic('USDT-FUTURES', 'trade', symbol); +⋮---- +// Topics are tracked per websocket type +// Get a list of subscribed topics (e.g. all public topics) (after a 5 second delay) + +================ +File: examples/V3 - UTA/Rest/rest-trade-UTA-futures.ts +================ +/* eslint-disable @typescript-eslint/no-unused-vars */ +import { + PlaceOrderRequestV3, + RestClientV3, + WebsocketClientV3, +} from '../../../src/index.js'; ⋮---- -// modulePaths: ['src'], +// or +// import { PlaceOrderRequestV3, RestClientV3, WebsocketClientV3 } from '../src'; ⋮---- -// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module -// moduleNameMapper: {}, +// read from environmental variables ⋮---- -// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader -// modulePathIgnorePatterns: [], +// If running from CLI in unix, you can pass env vars as such: +// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/V3/rest-trade-futures.ts ⋮---- -// Activates notifications for test results -// notify: false, +// note the single quotes, preventing special characters such as $ from being incorrectly passed ⋮---- -// An enum that specifies notification mode. Requires { notify: true } -// notifyMode: "failure-change", +// apiKey: 'apiKeyHere', +// apiSecret: 'apiSecretHere', +// apiPass: 'apiPassHere', ⋮---- -// A preset that is used as a base for Jest's configuration -// preset: undefined, +function logWSEvent(type: string, data: any) ⋮---- -// Run tests from one or more projects -// projects: undefined, +// simple sleep function +function promiseSleep(milliseconds: number) ⋮---- -// Use this configuration option to add custom reporters to Jest -// reporters: undefined, +/** + * This is a simple script wrapped in a immediately invoked function expression (to execute the below workflow immediately). + * + * It is designed to: + * - open a private websocket channel to log account events + * - check for any available USDT balance in the account + * - immediately open a minimum sized long position on BTCUSDT + * - check active positions + * - immediately send closing orders for any active futures positions + * - check positions again + * + */ ⋮---- -// Automatically reset mock state before every test -// resetMocks: false, +// Add event listeners to log websocket events on account ⋮---- -// Reset the module registry before running each individual test -// resetModules: false, +// Subscribe to private topics for UTA account ⋮---- -// A path to a custom resolver -// resolver: undefined, +// Subscribe to position updates ⋮---- -// Automatically restore mock state and implementation before every test -// restoreMocks: false, +// Subscribe to order updates ⋮---- -// The root directory that Jest should scan for tests and modules within -// rootDir: undefined, +// wait briefly for ws to be ready (could also use the response or authenticated events, to make sure topics are subscribed to before starting) ⋮---- -// A list of paths to directories that Jest should use to search for files in -// roots: [ -// "" -// ], +// Loop through any active positions and send a closing market order on each position + +================ +File: examples/V3 - UTA/Rest/rest-trade-UTA-spot.ts +================ +/* eslint-disable @typescript-eslint/no-unused-vars */ +import { + PlaceOrderRequestV3, + RestClientV3, + WebsocketClientV3, +} from '../../../src/index.js'; ⋮---- -// Allows you to use a custom runner instead of Jest's default test runner -// runner: "jest-runner", +// import { RestClientV3, WebsocketClientV3 } from '../src/index'; ⋮---- -// The paths to modules that run some code to configure or set up the testing environment before each test -// setupFiles: [], +// read from environmental variables ⋮---- -// A list of paths to modules that run some code to configure or set up the testing framework before each test -// setupFilesAfterEnv: [], +// If running from CLI in unix, you can pass env vars as such: +// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/V3/rest-trade-spot.ts ⋮---- -// The number of seconds after which a test is considered as slow and reported as such in the results. -// slowTestThreshold: 5, +// note the single quotes, preventing special characters such as $ from being incorrectly passed ⋮---- -// A list of paths to snapshot serializer modules Jest should use for snapshot testing -// snapshotSerializers: [], +// apiKey: 'apiKeyHere', +// apiSecret: 'apiSecretHere', +// apiPass: 'apiPassHere', ⋮---- -// The test environment that will be used for testing -// testEnvironment: "jest-environment-node", +function logWSEvent(type: string, data: any) ⋮---- -// Options that will be passed to the testEnvironment -// testEnvironmentOptions: {}, +// simple sleep function +function promiseSleep(milliseconds: number) ⋮---- -// Adds a location field to test results -// testLocationInResults: false, +/** This is a simple script wrapped in a immediately invoked function expression, designed to check for any available BTC balance and immediately sell the full amount for USDT */ ⋮---- -// The glob patterns Jest uses to detect test files +// Add event listeners to log websocket events on account ⋮---- -// "**/__tests__/**/*.[jt]s?(x)", +// Subscribe to private account topics +// Account updates for UTA (unified trading account) ⋮---- -// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped -// testPathIgnorePatterns: [ -// "/node_modules/" -// ], +// Order updates for spot ⋮---- -// The regexp pattern or array of patterns that Jest uses to detect test files -// testRegex: [], +// wait briefly for ws to be ready (could also use the response or authenticated events, to make sure topics are subscribed to before starting) + +================ +File: examples/V3 - UTA/Websocket/ws-private.ts +================ +import { + DefaultLogger, + WebsocketClientV3, + WS_KEY_MAP, +} from '../../../src/index.js'; ⋮---- -// This option allows the use of a custom results processor -// testResultsProcessor: undefined, +// or +// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV2 } from 'bitget-api'; ⋮---- -// This option allows use of a custom test runner -// testRunner: "jest-circus/runner", +// If running from CLI in unix, you can pass env vars as such: +// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/ws-private.ts ⋮---- -// A map from regular expressions to paths to transformers -// transform: undefined, +// console.log('WS raw message received ', JSON.stringify(data, null, 2)); ⋮---- -// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation -// transformIgnorePatterns: [ -// "/node_modules/", -// "\\.pnp\\.[^\\/]+$" -// ], +// You can subscribe to one topic at a time ⋮---- -// Prevents import esm module error from v1 axios release, issue #5026 +instType: 'UTA', // Note: all account events go on the UTA instType ⋮---- -// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them -// unmockedModulePathPatterns: undefined, +WS_KEY_MAP.v3Private, // This parameter points to private or public ⋮---- -// Indicates whether each individual test should be reported during the run -// verbose: undefined, -verbose: true, // report individual test +// Note: all account events go on the UTA instType ⋮---- -// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode -// watchPathIgnorePatterns: [], +// Or multiple at once: ⋮---- -// Whether to use watchman for file crawling -// watchman: true, - -================ -File: tea.yaml -================ -# https://tea.xyz/what-is-this-file ---- -version: 1.0.0 -codeOwners: - - '0xeb1a7BF44a801e33a339705A266Afc0Cba3D6D54' -quorum: 1 - -================ -File: tsconfig.json -================ -{ - "compilerOptions": { - "allowSyntheticDefaultImports": true, - "baseUrl": ".", - "noEmitOnError": true, - "declaration": true, - "esModuleInterop": true, - "forceConsistentCasingInFileNames": false, - "inlineSourceMap": false, - "lib": ["esnext", "DOM"], - "listEmittedFiles": false, - "listFiles": false, - "moduleResolution": "node", - "noFallthroughCasesInSwitch": true, - "noImplicitAny": true, - "noUnusedParameters": true, - "pretty": true, - "removeComments": false, - "resolveJsonModule": true, - "skipLibCheck": false, - "sourceMap": true, - "strict": true, - "strictNullChecks": true, - "types": ["node", "jest"], - "module": "commonjs", - "outDir": "dist/cjs", - "target": "esnext" - }, - "compileOnSave": true, - "exclude": ["node_modules", "dist"], - "include": ["src/**/*.*", "test/**/*.*", ".eslintrc.cjs"] -} +// Topics are tracked per websocket type +// The below example will pull a list of subscribed topics on that connection (e.g. all private topics), after a 5 second delay: ================ -File: examples/V3 - UTA/WS-API/ws-api-client-trade.ts +File: examples/V3 - UTA/Websocket/ws-public.ts ================ -import { DefaultLogger, WebsocketAPIClient } from '../../../src/index.js'; +import { + DefaultLogger, + WebsocketClientV3, + WS_KEY_MAP, +} from '../../../src/index.js'; ⋮---- // or -// import { DefaultLogger, WS_KEY_MAP, WebsocketAPIClient } from 'bitget-api'; +// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV2 } from 'bitget-api'; ⋮---- -// function attachEventHandlers( -// wsClient: TWSClient, -// ): void { -// wsClient.on('update', (data) => { -// console.log('raw message received ', JSON.stringify(data)); -// }); -// wsClient.on('open', (data) => { -// console.log('ws connected', data.wsKey); -// }); -// wsClient.on('reconnect', ({ wsKey }) => { -// console.log('ws automatically reconnecting.... ', wsKey); -// }); -// wsClient.on('reconnected', (data) => { -// console.log('ws has reconnected ', data?.wsKey); -// }); -// wsClient.on('authenticated', (data) => { -// console.log('ws has authenticated ', data?.wsKey); -// }); -// } +// console.log('WS raw message received ', JSON.stringify(data, null, 2)); ⋮---- -// If running from CLI in unix, you can pass env vars as such: -// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/ws-private.ts +/** + * Public events + */ ⋮---- -// Whether to use the demo trading wss connection -// demoTrading: true, +// You can subscribe to one topic at a time ⋮---- -// If you want your own event handlers instead of the default ones with logs, -// disable this setting and see the `attachEventHandlers` example below: -// attachEventListeners: false +WS_KEY_MAP.v3Public, // This parameter points to private or public +⋮---- +// Or multiple at once: +⋮---- +// Topics are tracked per websocket type +// The below example will pull a list of subscribed topics on that connection (e.g. all public topics), after a 5 second delay: + +================ +File: examples/V3 - UTA/WS-API/ws-api-trade-raw.ts +================ +import { + DefaultLogger, + WebsocketClientV3, + WS_KEY_MAP, +} from '../../../src/index.js'; ⋮---- -logger, // Optional: inject a custom logger +// or +// import { DefaultLogger, WS_KEY_MAP, WebsocketClientV3 } from 'bitget-api'; ⋮---- -// Optional, see above "attachEventListeners". Attach basic event handlers, so nothing is left unhandled -// attachEventHandlers(wsClient.getWSClient()); +// If running from CLI in unix, you can pass env vars as such: +// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/ws-private.ts ⋮---- -// Optional: prepare the WebSocket API connection in advance. -// This happens automatically but you can do this early before making any API calls, to prevent delays from a cold start. +// console.log('WS raw message received ', JSON.stringify(data, null, 2)); ⋮---- /** - * Bitget's WebSocket API be used like a REST API, through this SDK's WebsocketAPIClient. The WebsocketAPIClient is a utility class wrapped around WebsocketClientV3's sendWSAPIRequest() capabilities. + * Bitget's WebSocket API can be used via the sendWSAPIRequest() method. * - * Each request sent via the WebsocketAPIClient will automatically: - * - route via the active WS API connection - * - return a Promise, which automatically resolves/rejects when a matching response is received + * Use the `WS_KEY_MAP.v3Private` connection key for any requests. * * Note: this requires V3/UTA API keys! + * Note: for a better user experience, it is recommended to use the WebsocketAPIClient. */ ⋮---- +// Use the V3 private wss connection URL +⋮---- /** * Place Order * https://www.bitget.com/api-doc/uta/websocket/private/Place-Order-Channel#request-parameters @@ -7026,6 +7081,174 @@ dist repomix.sh coverage +================ +File: examples/V3 - UTA/WS-API/ws-api-client-trade.ts +================ +import { DefaultLogger, WebsocketAPIClient } from '../../../src/index.js'; +⋮---- +// or +// import { DefaultLogger, WS_KEY_MAP, WebsocketAPIClient } from 'bitget-api'; +⋮---- +// function attachEventHandlers( +// wsClient: TWSClient, +// ): void { +// wsClient.on('update', (data) => { +// console.log('raw message received ', JSON.stringify(data)); +// }); +// wsClient.on('open', (data) => { +// console.log('ws connected', data.wsKey); +// }); +// wsClient.on('reconnect', ({ wsKey }) => { +// console.log('ws automatically reconnecting.... ', wsKey); +// }); +// wsClient.on('reconnected', (data) => { +// console.log('ws has reconnected ', data?.wsKey); +// }); +// wsClient.on('authenticated', (data) => { +// console.log('ws has authenticated ', data?.wsKey); +// }); +// } +⋮---- +// If running from CLI in unix, you can pass env vars as such: +// API_KEY_COM='lkm12n3-2ba3-1mxf-fn13-lkm12n3a' API_SECRET_COM='035B2B9637E1BDFFEE2646BFBDDB8CE4' API_PASSPHRASE_COM='ComplexPa$$!23$5^' ts-node examples/ws-private.ts +⋮---- +// Whether to use the demo trading wss connection +// demoTrading: true, +⋮---- +// If you want your own event handlers instead of the default ones with logs, +// disable this setting and see the `attachEventHandlers` example below: +// attachEventListeners: false +⋮---- +logger, // Optional: inject a custom logger +⋮---- +// Optional, see above "attachEventListeners". Attach basic event handlers, so nothing is left unhandled +// attachEventHandlers(wsClient.getWSClient()); +⋮---- +// Optional: prepare the WebSocket API connection in advance. +// This happens automatically but you can do this early before making any API calls, to prevent delays from a cold start. +⋮---- +/** + * Bitget's WebSocket API be used like a REST API, through this SDK's WebsocketAPIClient. The WebsocketAPIClient is a utility class wrapped around WebsocketClientV3's sendWSAPIRequest() capabilities. + * + * Each request sent via the WebsocketAPIClient will automatically: + * - route via the active WS API connection + * - return a Promise, which automatically resolves/rejects when a matching response is received + * + * Note: this requires V3/UTA API keys! + */ +⋮---- +/** + * Place Order + * https://www.bitget.com/api-doc/uta/websocket/private/Place-Order-Channel#request-parameters + */ +⋮---- +/** + const res = { + "event": "trade", + "id": "1750034396082", + "category": "spot", + "topic": "place-order", + "args": [ + { + "symbol": "BTCUSDT", + "orderId": "xxxxxxxx", + "clientOid": "xxxxxxxx", + "cTime": "1750034397008" + } + ], + "code": "0", + "msg": "success", + "ts": "1750034397076" + }; + */ +⋮---- +/** + * Batch Place Order Channel + * https://www.bitget.com/api-doc/uta/websocket/private/Batch-Place-Order-Channel + */ +⋮---- +/** + * Note: batch place will never reject the request, even if all orders were rejected. Check the "code" and "msg" properties for individual orders in the response, to detect batch place errors. + */ +⋮---- +/** + const res = { + "event": "trade", + "id": "1750035029506", + "category": "spot", + "topic": "batch-place", + "args": [ + { + "code": "0", + "msg": "Success", + "symbol": "BTCUSDT", + "orderId": "xxxxxxxx", + "clientOid": "xxxxxxxx" + }, + { + "code": "0", + "msg": "Success", + "symbol": "BTCUSDT", + "orderId": "xxxxxxxx", + "clientOid": "xxxxxxxx" + } + ], + "code": "0", + "msg": "Success", + "ts": "1750035029925" + } + */ +⋮---- +/** + * Cancel Order + * https://www.bitget.com/api-doc/uta/websocket/private/Cancel-Order-Channel + */ +⋮---- +/** + const res = { + "event": "trade", + "id": "1750034870205", + "topic": "cancel-order", + "args": [ + { + "orderId": "xxxxxxxx", + "clientOid": "xxxxxxxx" + } + ], + "code": "0", + "msg": "Success", + "ts": "1750034870597" + } + */ +⋮---- +/** + * Batch Cancel Order + * https://www.bitget.com/api-doc/uta/websocket/private/Batch-Cancel-Order-Channel + */ +⋮---- +/** + const res = { + "event": "trade", + "id": "bb553cc0-c1fa-454e-956d-c96c8d715760", + "topic": "batch-cancel", + "args": [ + { + "code": "0", + "msg": "Success", + "orderId": "xxxxxxxxxxxxx" + }, + { + "code": "25204", + "msg": "Order does not exist", + "orderId": "xxxxxxxxxxxxx" + } + ], + "code": "0", + "msg": "Success", + "ts": "1751980011084" + } + */ + ================ File: src/types/request/v2/futures.ts ================ @@ -7659,8 +7882,12 @@ export interface TransferRequestV3 { amount: string; coin: string; symbol?: string; + /** Enable automatic margin borrowing when balance insufficient. yes | no */ + allowBorrow?: 'yes' | 'no'; } ⋮---- +/** Enable automatic margin borrowing when balance insufficient. yes | no */ +⋮---- export interface GetTransferableCoinsRequestV3 { fromType: | 'spot' @@ -7715,8 +7942,12 @@ export interface SubAccountTransferRequestV3 { fromUserId: string; toUserId: string; clientOid: string; + /** Enable automatic margin borrowing when balance insufficient. yes | no */ + allowBorrow?: 'yes' | 'no'; } ⋮---- +/** Enable automatic margin borrowing when balance insufficient. yes | no */ +⋮---- export interface GetSubUnifiedAssetsRequestV3 { subUid?: string; cursor?: string; @@ -8631,7 +8862,8 @@ export interface InstrumentV3 { deliveryTime?: string; deliveryStartTime?: string; deliveryPeriod?: string; - launchTime?: string; + /** Launch time - Unix millisecond timestamp. Null for some margin pairs. */ + launchTime?: string | null; fundInterval?: string; minLeverage?: string; maxLeverage?: string; @@ -8648,8 +8880,37 @@ export interface InstrumentV3 { ⋮---- // Futures specific fields ⋮---- +/** Launch time - Unix millisecond timestamp. Null for some margin pairs. */ +⋮---- // Margin specific fields ⋮---- +export interface MarketFeeGroupLabelV3 { + weight: string; + label: string; + symbols: string[]; +} +⋮---- +export interface MarketFeeGroupTierV3 { + level: string; + makerFeeRate: string; +} +⋮---- +export interface MarketFeeGroupV3 { + category: string; + group: string; + labelList: MarketFeeGroupLabelV3[]; + tierList: MarketFeeGroupTierV3[]; +} +⋮---- +export interface MarketScoreWeightV3 { + category: string; + label: string; + symbol: string; + requiredSpread: string; + minMakerVolume: string; + weight: string; +} +⋮---- export interface OrderBookV3 { a: string[][]; // asks - [price, size] b: string[][]; // bids - [price, size] @@ -9258,6 +9519,9 @@ File: README.md [1]: https://www.npmjs.com/package/bitget-api +> [!TIP] +> Upcoming change: As part of the [Siebly.io](https://siebly.io/?ref=ghbitget) brand, this SDK will soon be hosted under the [Siebly.io GitHub organisation](https://github.com/sieblyio). The migration is seamless and requires no user changes. + Updated & performant JavaScript & Node.js SDK for the Bitget V2 REST APIs and WebSockets: - Professional, robust & performant Bitget SDK with extensive production use in live trading environments. @@ -12402,12 +12666,22 @@ import { import { BindUidRequestV3, GetEnsureCoinsRequestV3, + GetLoanBorrowHistoryRequestV3, + GetLoanBorrowOngoingRequestV3, + GetLoanCoinsRequestV3, + GetLoanInterestRequestV3, GetLoanOrderRequestV3, + GetLoanPledgeRateHistoryRequestV3, + GetLoanReducesRequestV3, + GetLoanRepayHistoryRequestV3, GetLTVConvertRequestV3, GetProductInfosRequestV3, GetRepaidHistoryRequestV3, GetSymbolsRequestV3, GetTransferedRequestV3, + LoanBorrowRequestV3, + LoanRepayRequestV3, + LoanRevisePledgeRequestV3, } from './types/request/v3/loan.js'; import { GetCandlesRequestV3, @@ -12418,6 +12692,8 @@ import { GetIndexComponentsRequestV3, GetInstrumentsRequestV3, GetMarginLoansRequestV3, + GetMarketFeeGroupRequestV3, + GetMarketScoreWeightsRequestV3, GetOpenInterestRequestV3, GetOrderBookRequestV3, GetPositionTierRequestV3, @@ -12490,8 +12766,19 @@ import { import { BindUidResponseV3, CoinInfoV3, + GetLoanCoinsResponseV3, + GetLoanDebtsResponseV3, + GetLoanInterestResponseV3, + LoanBorrowHistoryItemV3, + LoanBorrowOngoingItemV3, + LoanBorrowResponseV3, LoanOrderV3, + LoanPledgeRateHistoryItemV3, LoanProductInfoV3, + LoanReduceItemV3, + LoanRepayHistoryItemV3, + LoanRepayResponseV3, + LoanRevisePledgeResponseV3, LoanSymbolsV3, LoanTransfersV3, LTVConvertResponseV3, @@ -12506,6 +12793,8 @@ import { IndexPriceComponentsV3, InstrumentV3, MarginLoanV3, + MarketFeeGroupV3, + MarketScoreWeightV3, OpenInterestV3, OrderBookV3, PositionTierV3, @@ -12595,6 +12884,20 @@ getInstruments( params: GetInstrumentsRequestV3, ): Promise> ⋮---- +/** + * Get Market Maker Fee Group - Query fee rate tiers and grouping + */ +getMarketFeeGroup( + params: GetMarketFeeGroupRequestV3, +): Promise> +⋮---- +/** + * Get Market Maker Score Weight - Query score weights per symbol + */ +getMarketScoreWeights( + params?: GetMarketScoreWeightsRequestV3, +): Promise> +⋮---- /** * Get Tickers */ @@ -13256,6 +13559,87 @@ bindLoanUid( params: BindUidRequestV3, ): Promise> ⋮---- +/** + * + * =====Unified Account Staking & Lending (Crypto Loans)===== /api/v3/loan/* + * + */ +⋮---- +/** + * Get Loan Coins - Query supported collateral currencies and borrowable coins + */ +getLoanCoins( + params?: GetLoanCoinsRequestV3, +): Promise> +⋮---- +/** + * Get Loan Interest - Query estimated interest and borrowable amount + */ +getLoanInterest( + params: GetLoanInterestRequestV3, +): Promise> +⋮---- +/** + * Borrow - Borrow coins + */ +loanBorrow( + params: LoanBorrowRequestV3, +): Promise> +⋮---- +/** + * Get Borrow Ongoing - Query current borrowings + */ +getLoanBorrowOngoing( + params?: GetLoanBorrowOngoingRequestV3, +): Promise> +⋮---- +/** + * Get Borrow History - Query borrowing history + */ +getLoanBorrowHistory( + params: GetLoanBorrowHistoryRequestV3, +): Promise> +⋮---- +/** + * Repay - Repay coins + */ +loanRepay( + params: LoanRepayRequestV3, +): Promise> +⋮---- +/** + * Get Repay History - Query repayment history + */ +getLoanRepayHistory( + params: GetLoanRepayHistoryRequestV3, +): Promise> +⋮---- +/** + * Revise Pledge - Adjust collateral ratio + */ +loanRevisePledge( + params: LoanRevisePledgeRequestV3, +): Promise> +⋮---- +/** + * Get Pledge Rate History - Query collateral ratio history + */ +getLoanPledgeRateHistory( + params: GetLoanPledgeRateHistoryRequestV3, +): Promise> +⋮---- +/** + * Get Loan Debts - Query assets and liabilities + */ +getLoanDebts(): Promise> +⋮---- +/** + * Get Loan Reduces - Query liquidation records + */ +getLoanReduces( + params: GetLoanReducesRequestV3, +): Promise> +⋮---- /** * * =====Strategy======= endpoints @@ -13429,7 +13813,7 @@ File: package.json ================ { "name": "bitget-api", - "version": "3.1.2", + "version": "3.1.5", "description": "Complete Node.js & JavaScript SDK for Bitget V1-V3 REST APIs & WebSockets, with TypeScript & end-to-end tests.", "scripts": { "test": "jest", @@ -13460,7 +13844,7 @@ File: package.json "llms.txt" ], "type": "module", - "author": "Tiago Siebler (https://github.com/tiagosiebler)", + "author": "Tiago Siebler (https://siebly.io)", "contributors": [], "dependencies": { "axios": "^1.13.2", diff --git a/package-lock.json b/package-lock.json index 0cc86f9..8fb80a8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bitget-api", - "version": "3.1.4", + "version": "3.1.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "bitget-api", - "version": "3.1.4", + "version": "3.1.5", "license": "MIT", "dependencies": { "axios": "^1.13.2", diff --git a/package.json b/package.json index baa8a62..11aa397 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bitget-api", - "version": "3.1.4", + "version": "3.1.5", "description": "Complete Node.js & JavaScript SDK for Bitget V1-V3 REST APIs & WebSockets, with TypeScript & end-to-end tests.", "scripts": { "test": "jest", diff --git a/src/rest-client-v3.ts b/src/rest-client-v3.ts index 39881c1..fcc6513 100644 --- a/src/rest-client-v3.ts +++ b/src/rest-client-v3.ts @@ -45,12 +45,22 @@ import { import { BindUidRequestV3, GetEnsureCoinsRequestV3, + GetLoanBorrowHistoryRequestV3, + GetLoanBorrowOngoingRequestV3, + GetLoanCoinsRequestV3, + GetLoanInterestRequestV3, GetLoanOrderRequestV3, + GetLoanPledgeRateHistoryRequestV3, + GetLoanReducesRequestV3, + GetLoanRepayHistoryRequestV3, GetLTVConvertRequestV3, GetProductInfosRequestV3, GetRepaidHistoryRequestV3, GetSymbolsRequestV3, GetTransferedRequestV3, + LoanBorrowRequestV3, + LoanRepayRequestV3, + LoanRevisePledgeRequestV3, } from './types/request/v3/loan.js'; import { GetCandlesRequestV3, @@ -61,6 +71,8 @@ import { GetIndexComponentsRequestV3, GetInstrumentsRequestV3, GetMarginLoansRequestV3, + GetMarketFeeGroupRequestV3, + GetMarketScoreWeightsRequestV3, GetOpenInterestRequestV3, GetOrderBookRequestV3, GetPositionTierRequestV3, @@ -133,8 +145,19 @@ import { import { BindUidResponseV3, CoinInfoV3, + GetLoanCoinsResponseV3, + GetLoanDebtsResponseV3, + GetLoanInterestResponseV3, + LoanBorrowHistoryItemV3, + LoanBorrowOngoingItemV3, + LoanBorrowResponseV3, LoanOrderV3, + LoanPledgeRateHistoryItemV3, LoanProductInfoV3, + LoanReduceItemV3, + LoanRepayHistoryItemV3, + LoanRepayResponseV3, + LoanRevisePledgeResponseV3, LoanSymbolsV3, LoanTransfersV3, LTVConvertResponseV3, @@ -149,6 +172,8 @@ import { IndexPriceComponentsV3, InstrumentV3, MarginLoanV3, + MarketFeeGroupV3, + MarketScoreWeightV3, OpenInterestV3, OrderBookV3, PositionTierV3, @@ -289,6 +314,24 @@ export class RestClientV3 extends BaseRestClient { return this.get('/api/v3/market/instruments', params); } + /** + * Get Market Maker Fee Group - Query fee rate tiers and grouping + */ + getMarketFeeGroup( + params: GetMarketFeeGroupRequestV3, + ): Promise> { + return this.get('/api/v3/market/fee-group', params); + } + + /** + * Get Market Maker Score Weight - Query score weights per symbol + */ + getMarketScoreWeights( + params?: GetMarketScoreWeightsRequestV3, + ): Promise> { + return this.get('/api/v3/market/score-weights', params); + } + /** * Get Tickers */ @@ -1088,6 +1131,109 @@ export class RestClientV3 extends BaseRestClient { 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?: GetLoanCoinsRequestV3, + ): Promise> { + return this.getPrivate('/api/v3/loan/coins', params); + } + + /** + * Get Loan Interest - Query estimated interest and borrowable amount + */ + getLoanInterest( + params: GetLoanInterestRequestV3, + ): Promise> { + return this.getPrivate('/api/v3/loan/interest', params); + } + + /** + * Borrow - Borrow coins + */ + loanBorrow( + params: LoanBorrowRequestV3, + ): Promise> { + return this.postPrivate('/api/v3/loan/borrow', params); + } + + /** + * Get Borrow Ongoing - Query current borrowings + */ + getLoanBorrowOngoing( + params?: GetLoanBorrowOngoingRequestV3, + ): Promise> { + return this.getPrivate('/api/v3/loan/borrow-ongoing', params); + } + + /** + * Get Borrow History - Query borrowing history + */ + getLoanBorrowHistory( + params: GetLoanBorrowHistoryRequestV3, + ): Promise> { + return this.getPrivate('/api/v3/loan/borrow-history', params); + } + + /** + * Repay - Repay coins + */ + loanRepay( + params: LoanRepayRequestV3, + ): Promise> { + return this.postPrivate('/api/v3/loan/repay', params); + } + + /** + * Get Repay History - Query repayment history + */ + getLoanRepayHistory( + params: GetLoanRepayHistoryRequestV3, + ): Promise> { + return this.getPrivate('/api/v3/loan/repay-history', params); + } + + /** + * Revise Pledge - Adjust collateral ratio + */ + loanRevisePledge( + params: LoanRevisePledgeRequestV3, + ): Promise> { + return this.postPrivate('/api/v3/loan/revise-pledge', params); + } + + /** + * Get Pledge Rate History - Query collateral ratio history + */ + getLoanPledgeRateHistory( + params: GetLoanPledgeRateHistoryRequestV3, + ): Promise> { + return this.getPrivate('/api/v3/loan/pledge-rate-history', params); + } + + /** + * Get Loan Debts - Query assets and liabilities + */ + getLoanDebts(): Promise> { + return this.getPrivate('/api/v3/loan/debts'); + } + + /** + * Get Loan Reduces - Query liquidation records + */ + getLoanReduces( + params: GetLoanReducesRequestV3, + ): Promise> { + return this.getPrivate('/api/v3/loan/reduces', params); + } + /** * * =====Strategy======= endpoints diff --git a/src/types/request/v3/account.ts b/src/types/request/v3/account.ts index b556c5c..39b5e88 100644 --- a/src/types/request/v3/account.ts +++ b/src/types/request/v3/account.ts @@ -106,6 +106,8 @@ export interface TransferRequestV3 { amount: string; coin: string; symbol?: string; + /** Enable automatic margin borrowing when balance insufficient. yes | no */ + allowBorrow?: 'yes' | 'no'; } export interface GetTransferableCoinsRequestV3 { @@ -162,6 +164,8 @@ export interface SubAccountTransferRequestV3 { fromUserId: string; toUserId: string; clientOid: string; + /** Enable automatic margin borrowing when balance insufficient. yes | no */ + allowBorrow?: 'yes' | 'no'; } export interface GetSubUnifiedAssetsRequestV3 { diff --git a/src/types/request/v3/loan.ts b/src/types/request/v3/loan.ts index f7ddd48..ee5c758 100644 --- a/src/types/request/v3/loan.ts +++ b/src/types/request/v3/loan.ts @@ -36,3 +36,87 @@ export interface BindUidRequestV3 { export interface GetLTVConvertRequestV3 { riskUnitId?: string; } + +/* Unified Account Staking & Lending (Crypto Loans) - /api/v3/loan/* */ + +export interface GetLoanCoinsRequestV3 { + coin?: string; +} + +export interface GetLoanInterestRequestV3 { + loanCoin: string; + pledgeCoin: string; + daily: 'SEVEN' | 'THIRTY' | 'FLEXIBLE'; + pledgeAmount: string; +} + +export interface LoanBorrowRequestV3 { + loanCoin: string; + pledgeCoin: string; + daily: 'SEVEN' | 'THIRTY' | 'FLEXIBLE'; + pledgeAmount?: string; + loanAmount?: string; +} + +export interface GetLoanBorrowOngoingRequestV3 { + orderId?: string; + loanCoin?: string; + pledgeCoin?: string; +} + +export interface GetLoanBorrowHistoryRequestV3 { + orderId?: string; + loanCoin?: string; + pledgeCoin?: string; + status?: 'ROLLBACK' | 'FORCE' | 'REPAY'; + startTime: string; + endTime: string; + pageNum?: string; + pageSize?: string; +} + +export interface LoanRepayRequestV3 { + orderId: string; + method: 'borrowed_coin' | 'collateral'; + repayAll: 'yes' | 'no'; + amount?: string; + repayUnlock?: 'yes' | 'no'; +} + +export interface GetLoanRepayHistoryRequestV3 { + orderId?: string; + loanCoin?: string; + pledgeCoin?: string; + startTime: string; + endTime: string; + pageNum?: string; + pageSize?: string; +} + +export interface LoanRevisePledgeRequestV3 { + orderId: string; + amount: string; + pledgeCoin: string; + reviseType?: 'OUT' | 'IN'; +} + +export interface GetLoanPledgeRateHistoryRequestV3 { + orderId?: string; + reviseSide?: 'down' | 'up'; + pledgeCoin?: string; + startTime: string; + endTime: string; + pageNum?: string; + pageSize?: string; +} + +export interface GetLoanReducesRequestV3 { + orderId?: string; + loanCoin?: string; + pledgeCoin?: string; + status?: 'COMPLETE' | 'WAIT'; + startTime: string; + endTime: string; + pageNum?: string; + pageSize?: string; +} diff --git a/src/types/request/v3/public.ts b/src/types/request/v3/public.ts index 6c39296..3da021d 100644 --- a/src/types/request/v3/public.ts +++ b/src/types/request/v3/public.ts @@ -95,6 +95,15 @@ export interface GetInstrumentsRequestV3 { symbol?: string; } +export interface GetMarketFeeGroupRequestV3 { + category: 'SPOT' | 'FUTURES'; + group?: 'GROUP_A' | 'GROUP_B' | 'GROUP_C'; +} + +export interface GetMarketScoreWeightsRequestV3 { + category?: 'SPOT' | 'FUTURES'; +} + export interface GetOrderBookRequestV3 { category: 'SPOT' | 'USDT-FUTURES' | 'COIN-FUTURES' | 'USDC-FUTURES'; symbol: string; diff --git a/src/types/response/v3/loan.ts b/src/types/response/v3/loan.ts index d34f197..c18f1ce 100644 --- a/src/types/response/v3/loan.ts +++ b/src/types/response/v3/loan.ts @@ -61,10 +61,18 @@ export interface LoanOrderV3 { status: 'not_paid_off' | 'paid_off'; } +/** Tiered conversion rate item (when Tiered Discount Rate Model is enabled) */ +export interface ConvertRatioListItemV3 { + ladder: string; + convertRatio: string; +} + export interface CoinInfoV3 { coin: string; convertRatio: string; maxConvertValue: string; + /** Tiered conversion rate (when margin mode is Tiered Discount Rate Model) */ + convertRatioList?: ConvertRatioListItemV3[]; } export interface BindUidResponseV3 { @@ -94,3 +102,132 @@ export interface LTVConvertResponseV3 { unpaidInfo: UnpaidInfoV3[]; balanceInfo: BalanceInfoV3[]; } + +/* Unified Account Staking & Lending (Crypto Loans) - /api/v3/loan/* */ + +export interface LoanCoinInfoV3 { + coin: string; + hourRateFlexible: string; + rateFlexible: string; + hourRate7D: string; + rate7D: string; + hourRate30D: string; + rate30D: string; + minBorrowAmount: string; + maxBorrowAmount: string; + minBorrowLimit: string; + maxBorrowLimit: string; +} + +export interface LoanPledgeInfoV3 { + coin: string; + initRate: string; + supRate: string; + forceRate: string; + minPledgeAmount: string; + maxPledgeAmount: string; +} + +export interface GetLoanCoinsResponseV3 { + loanInfos: LoanCoinInfoV3[]; + pledgeInfos: LoanPledgeInfoV3[]; +} + +export interface GetLoanInterestResponseV3 { + hourInterest: string; + loanAmount: string; +} + +export interface LoanBorrowResponseV3 { + orderId: string; +} + +export interface LoanBorrowOngoingItemV3 { + orderId: string; + loanCoin: string; + loanAmount: string; + interestAmount: string; + hourInterestRate: string; + pledgeCoin: string; + pledgeAmount: string; + pledgeRate: string; + supRate: string; + forceRate: string; + borrowTime: string; + expireTime: string; +} + +export interface LoanBorrowHistoryItemV3 { + orderId: string; + loanCoin: string; + pledgeCoin: string; + initPledgeAmount: string; + initLoanAmount: string; + hourRate: string; + daily: string; + borrowTime: string; + status: string; +} + +export interface LoanRepayResponseV3 { + loanCoin: string; + pledgeCoin: string; + repayAmount: string; + payInterest: string; + repayLoanAmount: string; + repayUnlockAmount: string; +} + +export interface LoanRepayHistoryItemV3 { + orderId: string; + loanCoin: string; + pledgeCoin: string; + repayAmount: string; + payInterest: string; + repayLoanAmount: string; + repayUnlockAmount: string; + repayTime: string; +} + +export interface LoanRevisePledgeResponseV3 { + loanCoin: string; + pledgeCoin: string; + afterPledgeRate: string; +} + +export interface LoanPledgeRateHistoryItemV3 { + loanCoin: string; + pledgeCoin: string; + orderId: string; + reviseTime: string; + reviseSide: string; + reviseAmount: string; + afterPledgeRate: string; + beforePledgeRate: string; +} + +export interface LoanDebtInfoV3 { + coin: string; + amount: string; + amountUsdt: string; +} + +export interface GetLoanDebtsResponseV3 { + pledgeInfos: LoanDebtInfoV3[]; + loanInfos: LoanDebtInfoV3[]; +} + +export interface LoanReduceItemV3 { + orderId: string; + loanCoin: string; + pledgeCoin: string; + reduceTime: string; + pledgeRate: string; + pledgePrice: string; + status: string; + pledgeAmount: string; + reduceFee: string; + residueAmount: string; + runlockAmount: string; + repayLoanAmount: string; +} diff --git a/src/types/response/v3/public.ts b/src/types/response/v3/public.ts index 64b56b0..897f2e4 100644 --- a/src/types/response/v3/public.ts +++ b/src/types/response/v3/public.ts @@ -127,7 +127,8 @@ export interface InstrumentV3 { deliveryTime?: string; deliveryStartTime?: string; deliveryPeriod?: string; - launchTime?: string; + /** Launch time - Unix millisecond timestamp. Null for some margin pairs. */ + launchTime?: string | null; fundInterval?: string; minLeverage?: string; maxLeverage?: string; @@ -142,6 +143,33 @@ export interface InstrumentV3 { userMinBorrow?: string; } +export interface MarketFeeGroupLabelV3 { + weight: string; + label: string; + symbols: string[]; +} + +export interface MarketFeeGroupTierV3 { + level: string; + makerFeeRate: string; +} + +export interface MarketFeeGroupV3 { + category: string; + group: string; + labelList: MarketFeeGroupLabelV3[]; + tierList: MarketFeeGroupTierV3[]; +} + +export interface MarketScoreWeightV3 { + category: string; + label: string; + symbol: string; + requiredSpread: string; + minMakerVolume: string; + weight: string; +} + export interface OrderBookV3 { a: string[][]; // asks - [price, size] b: string[][]; // bids - [price, size] diff --git a/src/websocket-client-v3.ts b/src/websocket-client-v3.ts index 52620f0..1face14 100644 --- a/src/websocket-client-v3.ts +++ b/src/websocket-client-v3.ts @@ -448,6 +448,14 @@ export class WebsocketClientV3 extends BaseWebsocketClient< eventType: 'exception', event: emittableEvent, }); + // Service upgrade (30033): Bitget sends this ~60s before disconnect. Log and let automatic reconnect handle when connection drops. + const code = msg['code']; + if (code === 30033 || code === '30033') { + this.logger.info( + 'Service upgrade in progress - connection might drop in 60s before automatic reconnect', + { ...WS_LOGGER_CATEGORY, wsKey, code }, + ); + } } return results;