From d3a392dea70e1fd39b89008657e1466ada2eddb8 Mon Sep 17 00:00:00 2001 From: JJ-Cro Date: Thu, 12 Dec 2024 12:00:58 +0100 Subject: [PATCH] feat(): added common response types --- src/rest-client-v2.ts | 206 ++++++++++----- src/types/index.ts | 2 +- src/types/response/index.ts | 4 + src/types/response/v1/index.ts | 3 - src/types/response/v2/common.ts | 443 ++++++++++++++++++++++++++++++++ 5 files changed, 583 insertions(+), 75 deletions(-) create mode 100644 src/types/response/index.ts delete mode 100644 src/types/response/v1/index.ts create mode 100644 src/types/response/v2/common.ts diff --git a/src/rest-client-v2.ts b/src/rest-client-v2.ts index 2e71d7f..be254a4 100644 --- a/src/rest-client-v2.ts +++ b/src/rest-client-v2.ts @@ -1,9 +1,30 @@ import { + AnnouncementV2, APIResponse, + BGBConvertCoinsV2, + BGBConvertHistoryV2, BorrowLoanRequestV2, + BotAssetsV2, CloseFuturesFollowerPositionsRequestV2, + ConvertBGBResponseV2, + ConvertCurrenciesV2, + ConvertHistoryV2, + ConvertQuotedPriceV2, + ConvertQuoteRequestV2, + ConvertRequestV2, + ConvertTradeResponseV2, CopyTradingProductTypeV2, + CreateSubAccountApiKeyRequestV2, + CreateVirtualSubAccountAndApiKeyV2, + CreateVirtualSubAccountApiKeyV2, + CreateVirtualSubAccountV2, + CreateVirtualSubApiKeyRequestV2, + CreateVirtualSubRequestV2, + FundingAssetsV2, FuturesAccountBillRequestV2, + FuturesActiveBuySellVolumeV2, + FuturesActiveLongShortAccountV2, + FuturesActiveLongShortPositionV2, FuturesBatchCancelOrderRequestV2, FuturesBatchOrderRequestV2, FuturesCancelAllOrdersRequestV2, @@ -21,6 +42,7 @@ import { FuturesHistoricalPositionsRequestV2, FuturesHistoricTradesRequestV2, FuturesInterestHistoryRequestV2, + FuturesLongShortRatioV2, FuturesMergeDepthRequestV2, FuturesModifyOrderRequestV2, FuturesModifyPlanOrderRequestV2, @@ -38,7 +60,11 @@ import { FuturesSingleAccountRequestV2, FuturesTPSLOrderRequestV2, FuturesTraderSymbolSettingRequestV2, + FuturesTransactionRecordV2, + GetAnnouncementsRequestV2, GetBorrowHistoryRequestV2, + GetConvertBGBHistoryRequestV2, + GetConvertHistoryRequestV2, GetEarnSavingsAssetsRequestV2, GetEarnSavingsRecordsRequestV2, GetFinancialHistoryRequestV2, @@ -49,6 +75,7 @@ import { GetFuturesTraderFollowersRequestV2, GetFuturesTraderHistoryOrdersRequestV2, GetFuturesTraderProfitShareDetailRequestV2, + GetFuturesTransactionsRequestV2, GetHistoryOrdersRequestV2, GetInterestHistoryRequestV2, GetLiquidationHistoryRequestV2, @@ -60,6 +87,11 @@ import { GetMarginCurrentOrdersRequestV2, GetMarginLiquidationOrdersRequestV2, GetMarginOrderFillsRequestV2, + GetMarginTransactionsRequestV2, + GetMerchantAdvertisementsRequestV2, + GetMerchantP2POrdersRequestV2, + GetP2PMerchantsRequestV2, + GetP2PTransactionsRequestV2, GetRepayHistoryRequestV2, GetSharkfinAssetsRequestV2, GetSharkfinRecordsRequestV2, @@ -78,13 +110,29 @@ import { GetSpotTraderFollowersRequestV2, GetSpotTraderHistoryOrdersRequestV2, GetSpotTraderHistoryProfitRequestV2, + GetSpotTransactionsRequestV2, GetSpotTransferRecordRequestV2, GetSpotWithdrawalRecordRequestV2, + GetSubAccountsRequestV2, + GetTradeRateRequestV2, + IsolatedMarginBorrowingRatioV2, + LeveragedLongShortRatioV2, MarginBatchOrdersRequestV2, + MarginLoanGrowthRateV2, MarginPlaceOrderRequestV2, + MarginTransactionRecordV2, MarginType, ModifyFuturesTraderOrderTPSLRequestV2, ModifyLoanPledgeRateRequestV2, + ModifySubAccountApiKeyRequestV2, + ModifySubRequestV2, + ModifyVirtualSubAccountApiKeyV2, + ModifyVirtualSubApiKeyRequestV2, + ModifyVirtualSubRequestV2, + P2PMerchantAdvertisementV2, + P2PMerchantInfoV2, + P2PMerchantListV2, + P2PMerchantOrderV2, RedeemSavingsRequestV2, RepayLoanRequestV2, SpotAccountBill, @@ -95,6 +143,7 @@ import { SpotCancelOrderRequestV2, SpotCandlesRequestV2, SpotFollowerCopyTradeSettingV2, + SpotFundFlowV2, SpotHistoricCandlesRequestV2, SpotHistoricTradesRequestV2, SpotMainSubTransferRecordRequestV2, @@ -102,39 +151,18 @@ import { SpotOrderRequestV2, SpotPlanOrderRequestV2, SpotSubAccountTransferRequestV2, + SpotTransactionRecordV2, SpotTransferRequestV2, + SpotWhaleNetFlowV2, SpotWithdrawalRequestV2, - UpdateFuturesFollowerSettingsRequestV2, - UpdateFuturesFollowerTPSLRequestV2, -} from './types'; -import { - CreateSubAccountApiKeyRequestV2, - GetSubAccountsRequestV2, - ModifySubAccountApiKeyRequestV2, - ModifySubRequestV2, + SubAccountApiKeyListV2, SubDepositRecordsRequestV2, SubWithdrawalRecordsRequestV2, SubWithdrawalRequestV2, -} from './types/request/v2/broker'; -import { - ConvertQuoteRequestV2, - ConvertRequestV2, - CreateVirtualSubApiKeyRequestV2, - CreateVirtualSubRequestV2, - GetAnnouncementsRequestV2, - GetConvertBGBHistoryRequestV2, - GetConvertHistoryRequestV2, - GetFuturesTransactionsRequestV2, - GetMarginTransactionsRequestV2, - GetMerchantAdvertisementsRequestV2, - GetMerchantP2POrdersRequestV2, - GetP2PMerchantsRequestV2, - GetP2PTransactionsRequestV2, - GetSpotTransactionsRequestV2, - GetTradeRateRequestV2, - ModifyVirtualSubApiKeyRequestV2, - ModifyVirtualSubRequestV2, -} from './types/request/v2/common'; + UpdateFuturesFollowerSettingsRequestV2, + UpdateFuturesFollowerTPSLRequestV2, + VirtualSubAccountListV2, +} from './types'; import { assertMarginType, REST_CLIENT_TYPE_ENUM } from './util'; import BaseRestClient from './util/BaseRestClient'; @@ -236,7 +264,7 @@ export class RestClientV2 extends BaseRestClient { getAnnouncements( params?: GetAnnouncementsRequestV2, - ): Promise> { + ): Promise> { return this.get('/api/v2/public/annoucements', params); } @@ -246,11 +274,20 @@ export class RestClientV2 extends BaseRestClient { * */ - getServerTime(): Promise> { + getServerTime(): Promise< + APIResponse<{ + serverTime: string; + }> + > { return this.get('/api/v2/public/time'); } - getTradeRate(params: GetTradeRateRequestV2): Promise> { + getTradeRate(params: GetTradeRateRequestV2): Promise< + APIResponse<{ + makerFeeRate: string; + takerFeeRate: string; + }> + > { return this.getPrivate('/api/v2/common/trade-rate', params); } @@ -262,25 +299,25 @@ export class RestClientV2 extends BaseRestClient { getSpotTransactionRecords( params: GetSpotTransactionsRequestV2, - ): Promise> { + ): Promise> { return this.getPrivate('/api/v2/tax/spot-record', params); } getFuturesTransactionRecords( params: GetFuturesTransactionsRequestV2, - ): Promise> { + ): Promise> { return this.getPrivate('/api/v2/tax/future-record', params); } getMarginTransactionRecords( params: GetMarginTransactionsRequestV2, - ): Promise> { + ): Promise> { return this.getPrivate('/api/v2/tax/margin-record', params); } getP2PTransactionRecords( params: GetP2PTransactionsRequestV2, - ): Promise> { + ): Promise> { return this.getPrivate('/api/v2/tax/p2p-record', params); } @@ -292,23 +329,23 @@ export class RestClientV2 extends BaseRestClient { getP2PMerchantList( params?: GetP2PMerchantsRequestV2, - ): Promise> { + ): Promise> { return this.getPrivate('/api/v2/p2p/merchantList', params); } - getP2PMerchantInfo(): Promise> { + getP2PMerchantInfo(): Promise> { return this.getPrivate('/api/v2/p2p/merchantInfo'); } getP2PMerchantOrders( params: GetMerchantP2POrdersRequestV2, - ): Promise> { + ): Promise> { return this.getPrivate('/api/v2/p2p/orderList', params); } getP2PMerchantAdvertisementList( params: GetMerchantAdvertisementsRequestV2, - ): Promise> { + ): Promise> { return this.getPrivate('/api/v2/p2p/advList', params); } @@ -320,21 +357,21 @@ export class RestClientV2 extends BaseRestClient { getSpotWhaleNetFlowData(params: { symbol: string; - }): Promise> { + }): Promise> { return this.getPrivate('/api/v2/spot/market/whale-net-flow', params); } getFuturesActiveTakerBuySellVolumeData(params: { symbol: string; period?: string; - }): Promise> { + }): Promise> { return this.get('/api/v2/mix/market/taker-buy-sell', params); } getFuturesActiveLongShortPositionData(params: { symbol: string; period?: string; - }): Promise> { + }): Promise> { return this.get('/api/v2/mix/market/position-long-short', params); } @@ -342,7 +379,7 @@ export class RestClientV2 extends BaseRestClient { symbol: string; period?: string; coin?: string; - }): Promise> { + }): Promise> { return this.get('/api/v2/mix/market/long-short-ratio', params); } @@ -350,45 +387,55 @@ export class RestClientV2 extends BaseRestClient { symbol: string; period?: string; coin?: string; - }): Promise> { + }): Promise> { return this.get('/api/v2/mix/market/loan-growth', params); } getIsolatedMarginBorrowingRatio(params: { symbol: string; period?: string; - }): Promise> { + }): Promise> { return this.get('/api/v2/mix/market/isolated-borrow-rate', params); } getFuturesActiveBuySellVolumeData(params: { symbol: string; period?: string; - }): Promise> { + }): Promise> { return this.get('/api/v2/mix/market/long-short', params); } getSpotFundFlow(params: { symbol: string; period?: string; - }): Promise> { + }): Promise> { return this.get('/api/v2/spot/market/fund-flow', params); } - getTradeDataSupportSymbols(): Promise> { + getTradeDataSupportSymbols(): Promise< + APIResponse<{ + spotList: string[]; + futureList: string[]; + }> + > { return this.get('/api/v2/spot/market/support-symbols'); } - getSpotFundNetFlowData(params: { - symbol: string; - }): Promise> { + getSpotFundNetFlowData(params: { symbol: string }): Promise< + APIResponse< + { + netFlow: string; + ts: string; + }[] + > + > { return this.get('/api/v2/spot/market/fund-net-flow', params); } getFuturesActiveLongShortAccountData(params: { symbol: string; period?: string; - }): Promise> { + }): Promise> { return this.get('/api/v2/mix/market/account-long-short', params); } @@ -400,19 +447,21 @@ export class RestClientV2 extends BaseRestClient { createVirtualSubaccount(params: { subAccountList: string[]; - }): Promise> { + }): Promise> { return this.postPrivate('/api/v2/user/create-virtual-subaccount', params); } - modifyVirtualSubaccount( - params: ModifyVirtualSubRequestV2, - ): Promise> { + modifyVirtualSubaccount(params: ModifyVirtualSubRequestV2): Promise< + APIResponse<{ + result: string; + }> + > { return this.postPrivate('/api/v2/user/modify-virtual-subaccount', params); } batchCreateVirtualSubaccountAndAPIKey( params: CreateVirtualSubRequestV2, - ): Promise> { + ): Promise> { return this.postPrivate( '/api/v2/user/batch-create-subaccount-and-apikey', params, @@ -423,13 +472,13 @@ export class RestClientV2 extends BaseRestClient { limit?: string; idLessThan?: string; status?: 'normal' | 'freeze'; - }): Promise> { + }): Promise> { return this.getPrivate('/api/v2/user/virtual-subaccount-list', params); } createVirtualSubaccountAPIKey( params: CreateVirtualSubApiKeyRequestV2, - ): Promise> { + ): Promise> { return this.postPrivate( '/api/v2/user/create-virtual-subaccount-apikey', params, @@ -438,7 +487,7 @@ export class RestClientV2 extends BaseRestClient { modifyVirtualSubaccountAPIKey( params: ModifyVirtualSubApiKeyRequestV2, - ): Promise> { + ): Promise> { return this.postPrivate( '/api/v2/user/modify-virtual-subaccount-apikey', params, @@ -447,7 +496,7 @@ export class RestClientV2 extends BaseRestClient { getVirtualSubaccountAPIKeys(params: { subAccountUid: string; - }): Promise> { + }): Promise> { return this.getPrivate( '/api/v2/user/virtual-subaccount-apikey-list', params, @@ -459,16 +508,27 @@ export class RestClientV2 extends BaseRestClient { * * Common | Assets * */ - getFundingAssets(params?: { coin?: string }): Promise> { + getFundingAssets(params?: { + coin?: string; + }): Promise> { return this.getPrivate('/api/v2/account/funding-assets', params); } - getBotAccount(params?: { accountType?: string }): Promise> { + getBotAccount(params?: { + accountType?: string; + }): Promise> { return this.getPrivate('/api/v2/account/bot-assets', params); } /** Get assets overview */ - getBalances(): Promise> { + getBalances(): Promise< + APIResponse< + { + accountType: string; + usdtBalance: string; + }[] + > + > { return this.getPrivate('/api/v2/account/all-account-balance'); } @@ -478,23 +538,25 @@ export class RestClientV2 extends BaseRestClient { * */ - getConvertCoins(): Promise> { + getConvertCoins(): Promise> { return this.getPrivate('/api/v2/convert/currencies'); } getConvertQuotedPrice( params: ConvertQuoteRequestV2, - ): Promise> { + ): Promise> { return this.getPrivate('/api/v2/convert/quoted-price', params); } - convert(params: ConvertRequestV2): Promise> { + convert( + params: ConvertRequestV2, + ): Promise> { return this.postPrivate('/api/v2/convert/trade', params); } getConvertHistory( params: GetConvertHistoryRequestV2, - ): Promise> { + ): Promise> { return this.getPrivate('/api/v2/convert/convert-record', params); } @@ -504,17 +566,19 @@ export class RestClientV2 extends BaseRestClient { * */ - getConvertBGBCoins(): Promise> { + getConvertBGBCoins(): Promise> { return this.getPrivate('/api/v2/convert/bgb-convert-coin-list'); } - convertBGB(params: { coinList: string }): Promise> { + convertBGB(params: { + coinList: string; + }): Promise> { return this.postPrivate('/api/v2/convert/bgb-convert', params); } getConvertBGBHistory( params: GetConvertBGBHistoryRequestV2, - ): Promise> { + ): Promise> { return this.getPrivate('/api/v2/convert/bgb-convert-records', params); } diff --git a/src/types/index.ts b/src/types/index.ts index 2b763b1..86329ba 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,4 +1,4 @@ export * from './request'; -export * from './response/v1'; +export * from './response'; export * from './shared'; export * from './websockets'; diff --git a/src/types/response/index.ts b/src/types/response/index.ts new file mode 100644 index 0000000..a98abe2 --- /dev/null +++ b/src/types/response/index.ts @@ -0,0 +1,4 @@ +export * from './v1/futures'; +export * from './v1/shared'; +export * from './v1/spot'; +export * from './v2/common'; diff --git a/src/types/response/v1/index.ts b/src/types/response/v1/index.ts deleted file mode 100644 index e42f90e..0000000 --- a/src/types/response/v1/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './futures'; -export * from './shared'; -export * from './spot'; diff --git a/src/types/response/v2/common.ts b/src/types/response/v2/common.ts new file mode 100644 index 0000000..091f82a --- /dev/null +++ b/src/types/response/v2/common.ts @@ -0,0 +1,443 @@ +/** + * + * * Common | Notice + * + */ + +export interface AnnouncementV2 { + annId: string; + annTitle: string; + annDesc: string; + cTime: string; + language: string; + annUrl: string; +} + +/** + * + * * Common | Public + * + */ + +/** + * + * * Common | Tax + * + */ + +export interface SpotTransactionRecordV2 { + id: string; + coin: string; + spotTaxType: string; + amount: string; + fee: string; + balance: string; + ts: string; +} + +export interface FuturesTransactionRecordV2 { + id: string; + symbol: string; + marginCoin: string; + futureTaxType: string; + amount: string; + fee: string; + ts: string; +} + +export interface MarginTransactionRecordV2 { + id: string; + coin: string; + marginTaxType: string; + amount: string; + fee: string; + total: string; + symbol: string; + ts: string; +} + +export interface P2PMerchantOrderV2 { + id: string; + coin: string; + p2pTaxType: string; + total: string; + ts: string; +} + +/** + * + * * Common | P2P + * + */ + +export interface P2PMerchantListV2 { + merchantList: { + registerTime: string; + nickName: string; + isOnline: string; + avgPaymentTime: string; + avgReleaseTime: string; + totalTrades: string; + totalBuy: string; + totalSell: string; + totalCompletionRate: string; + trades30d: string; + sell30d: string; + buy30d: string; + completionRate30d: string; + }[]; + minMerchantId: string; +} + +export interface P2PMerchantInfoV2 { + registerTime: string; + nickName: string; + merchantId: string; + avgPaymentTime: string; + avgReleaseTime: string; + totalTrades: string; + totalBuy: string; + totalSell: string; + totalCompletionRate: string; + trades30d: string; + sell30d: string; + buy30d: string; + completionRate30d: string; + kycStatus: boolean; + emailBindStatus: boolean; + mobileBindStatus: boolean; + email: string; + mobile: string; +} + +export interface P2PMerchantOrderV2 { + orderList: { + orderId: string; + orderNo: string; + advNo: string; + side: string; + count: string; + coin: string; + price: string; + fiat: string; + withdrawTime: string; + representTime: string; + releaseTime: string; + paymentTime: string; + amount: string; + status: string; + buyerRealName: string; + sellerRealName: string; + ctime: string; + utime: string; + paymentInfo: { + paymethodName: string; + paymethodId: string; + paymethodInfo: { + name: string; + required: string; + type: string; + value: string; + }[]; + }; + }[]; + minOrderId: string; +} + +export interface P2PMerchantAdvertisementV2 { + advList: { + advId: string; + advNo: string; + side: string; + advSize: string; + size: string; + coin: string; + price: string; + coinPrecision: string; + fiat: string; + fiatPrecision: string; + fiatSymbol: string; + status: string; + hide: string; + maxTradeAmount: string; + minTradeAmount: string; + payDuration: string; + turnoverNum: string; + turnoverRate: string; + label: string | null; + userLimitList: { + minCompleteNum: string; + maxCompleteNum: string; + placeOrderNum: string; + allowMerchantPlace: string; + completeRate30d: string; + country: string; + }; + paymentMethodList: { + paymentMethod: string; + paymentId: string; + paymentInfo: { + name: string; + required: boolean; + type: string; + }[]; + }[]; + merchantCertifiedList: { + imageUrl: string; + desc: string; + }[]; + utime: string; + ctime: string; + }[]; + minAdvId: string; +} + +/** + * + * * Common | Trading insights + * + */ + +export interface SpotWhaleNetFlowV2 { + volume: string; + date: string; +} + +export interface FuturesActiveBuySellVolumeV2 { + buyVolume: string; + sellVolume: string; + ts: string; +} + +export interface FuturesActiveLongShortPositionV2 { + longPositionRatio: string; + shortPositionRatio: string; + longShortPositionRatio: string; + ts: string; +} + +export interface LeveragedLongShortRatioV2 { + ts: string; + longShortRatio: string; +} + +export interface MarginLoanGrowthRateV2 { + ts: string; + growthRate: string; +} + +export interface IsolatedMarginBorrowingRatioV2 { + ts: string; + borrowRate: string; +} + +export interface FuturesLongShortRatioV2 { + longRatio: string; + shortRatio: string; + longShortRatio: string; + ts: string; +} + +export interface SpotFundFlowV2 { + whaleBuyVolume: string; + dolphinBuyVolume: string; + fishBuyVolume: string; + whaleSellVolume: string; + dolphinSellVolume: string; + fishSellVolume: string; + whaleBuyRatio: string; + dolphinBuyRatio: string; + fishBuyRatio: string; + whaleSellRatio: string; + dolphinSellRatio: string; + fishSellRatio: string; +} + +export interface FuturesActiveLongShortAccountV2 { + longAccountRatio: string; + shortAccountRatio: string; + longShortAccountRatio: string; + ts: string; +} + +/** + * + * * Common | Virtual Subaccount + * + */ + +export interface CreateVirtualSubAccountV2 { + failureList: { + subaAccountName: string; + }[]; + successList: { + subaAccountUid: string; + subaAccountName: string; + status: string; + label: string; + permList: string[]; + cTime: string; + uTime: string; + }[]; +} + +export interface CreateVirtualSubAccountAndApiKeyV2 { + subAccountUid: string; + subAccountName: string; + label: string; + subAccountApiKey: string; + secretKey: string; + permList: string[]; + ipList: string[]; +} + +export interface VirtualSubAccountListV2 { + endId: string; + subAccountList: { + subAccountUid: string; + subAccountName: string; + status: string; + permList: string[]; + label: string; + accountType: string; + bindingTime: string; + cTime: string; + uTime: string; + }[]; +} + +export interface CreateVirtualSubAccountApiKeyV2 { + subAccountUid: string; + label: string; + subAccountApiKey: string; + secretKey: string; + permList: string[]; + ipList: string[]; +} + +export interface ModifyVirtualSubAccountApiKeyV2 { + subAccountUid: string; + label: string; + subAccountApiKey: string; + secretKey: string; + permList: string[]; + ipList: string[]; +} + +export interface SubAccountApiKeyListV2 { + subAccountUid: string; + label: string; + subAccountApiKey: string; + permList: string[]; + ipList: string[]; +} + +/** + * + * * Common | Assets + * + */ + +export interface FundingAssetsV2 { + coin: string; + available: string; + frozen: string; + usdtValue: string; +} + +export interface BotAssetsV2 { + coin: string; + available: string; + equity: string; + bonus: string; + frozen: string; + usdtValue: string; +} + +/** + * + * * Common | Convert + * + */ + +export interface ConvertCurrenciesV2 { + // array type + coin: string; + available: string; + maxAmount: string; + minAmount: string; +} + +export interface ConvertQuotedPriceV2 { + fee: string; + fromCoinSize: string; + fromCoin: string; + cnvtPrice: string; + toCoinSize: string; + toCoin: string; + traceId: string; +} + +export interface ConvertTradeResponseV2 { + ts: string; + cnvtPrice: string; + toCoinSize: string; + toCoin: string; +} + +export interface ConvertHistoryV2 { + dataList: { + id: string; + ts: string; + cnvtPrice: string; + fee: string; + fromCoinSize: string; + fromCoin: string; + toCoinSize: string; + toCoin: string; + }[]; + endId: string; +} + +/** + * + * * Common | BGB Convert + * + */ + +export interface BGBConvertCoinsV2 { + coinList: { + coin: string; + available: string; + bgbEstAmount: string; + precision: string; + feeDetail: { + feeRate: string; + fee: string; + }[]; + cTime: string; + }[]; +} + +export interface ConvertBGBResponseV2 { + orderList: { + coin: string; + orderId: string; + }[]; +} + +export interface BGBConvertHistoryV2 { + orderId: string; + fromCoin: string; + fromAmount: string; + fromCoinPrice: string; + toCoin: string; + toAmount: string; + toCoinPrice: string; + feeDetail: { + feeCoin: string; + fee: string; + }[]; + status: string; + ctime: string; +}