feat(): added margin response types

This commit is contained in:
JJ-Cro
2024-12-13 13:14:30 +01:00
parent 6cabbe5edb
commit 8c736b0d3c
3 changed files with 446 additions and 25 deletions

View File

@@ -24,6 +24,10 @@ import {
CreateVirtualSubAccountV2, CreateVirtualSubAccountV2,
CreateVirtualSubApiKeyRequestV2, CreateVirtualSubApiKeyRequestV2,
CreateVirtualSubRequestV2, CreateVirtualSubRequestV2,
CrossInterestRateAndLimitResponseV2,
CrossMaxBorrowableResponseV2,
CrossMaxTransferableResponseV2,
CrossTierConfigurationResponseV2,
FundingAssetsV2, FundingAssetsV2,
FuturesAccountBillRequestV2, FuturesAccountBillRequestV2,
FuturesAccountBillV2, FuturesAccountBillV2,
@@ -151,11 +155,27 @@ import {
GetSpotWithdrawalRecordRequestV2, GetSpotWithdrawalRecordRequestV2,
GetSubAccountsRequestV2, GetSubAccountsRequestV2,
GetTradeRateRequestV2, GetTradeRateRequestV2,
IsolatedInterestRateAndLimitResponseV2,
IsolatedMarginBorrowingRatioV2, IsolatedMarginBorrowingRatioV2,
IsolatedMaxBorrowableResponseV2,
IsolatedMaxTransferableResponseV2,
IsolatedTierConfigurationResponseV2,
LeveragedLongShortRatioV2, LeveragedLongShortRatioV2,
MarginAccountAssetV2,
MarginBatchOrdersRequestV2, MarginBatchOrdersRequestV2,
MarginBatchOrdersResponseV2,
MarginBorrowHistoryV2,
MarginCurrencyV2,
MarginCurrentOrdersV2,
MarginFinancialHistoryV2,
MarginHistoryOrdersV2,
MarginInterestHistoryV2,
MarginLiquidationHistoryV2,
MarginLiquidationOrdersV2,
MarginLoanGrowthRateV2, MarginLoanGrowthRateV2,
MarginOrderFillsV2,
MarginPlaceOrderRequestV2, MarginPlaceOrderRequestV2,
MarginRepaymentHistoryV2,
MarginTransactionRecordV2, MarginTransactionRecordV2,
MarginType, MarginType,
ModifyFuturesTraderOrderTPSLRequestV2, ModifyFuturesTraderOrderTPSLRequestV2,
@@ -1619,7 +1639,7 @@ export class RestClientV2 extends BaseRestClient {
* *
*/ */
getMarginCurrencies(): Promise<APIResponse<any>> { getMarginCurrencies(): Promise<APIResponse<MarginCurrencyV2[]>> {
return this.get('/api/v2/margin/currencies'); return this.get('/api/v2/margin/currencies');
} }
@@ -1632,7 +1652,7 @@ export class RestClientV2 extends BaseRestClient {
getMarginBorrowHistory( getMarginBorrowHistory(
marginType: MarginType, marginType: MarginType,
params: GetBorrowHistoryRequestV2, params: GetBorrowHistoryRequestV2,
): Promise<APIResponse<any>> { ): Promise<APIResponse<MarginBorrowHistoryV2>> {
assertMarginType(marginType); assertMarginType(marginType);
return this.getPrivate( return this.getPrivate(
`/api/v2/margin/${marginType}/borrow-history`, `/api/v2/margin/${marginType}/borrow-history`,
@@ -1643,7 +1663,7 @@ export class RestClientV2 extends BaseRestClient {
getMarginRepayHistory( getMarginRepayHistory(
marginType: MarginType, marginType: MarginType,
params: GetRepayHistoryRequestV2, params: GetRepayHistoryRequestV2,
): Promise<APIResponse<any>> { ): Promise<APIResponse<MarginRepaymentHistoryV2>> {
assertMarginType(marginType); assertMarginType(marginType);
return this.getPrivate( return this.getPrivate(
`/api/v2/margin/${marginType}/repay-history`, `/api/v2/margin/${marginType}/repay-history`,
@@ -1654,7 +1674,7 @@ export class RestClientV2 extends BaseRestClient {
getMarginInterestHistory( getMarginInterestHistory(
marginType: MarginType, marginType: MarginType,
params: GetInterestHistoryRequestV2, params: GetInterestHistoryRequestV2,
): Promise<APIResponse<any>> { ): Promise<APIResponse<MarginInterestHistoryV2>> {
assertMarginType(marginType); assertMarginType(marginType);
return this.getPrivate( return this.getPrivate(
`/api/v2/margin/${marginType}/interest-history`, `/api/v2/margin/${marginType}/interest-history`,
@@ -1665,7 +1685,7 @@ export class RestClientV2 extends BaseRestClient {
getMarginLiquidationHistory( getMarginLiquidationHistory(
marginType: MarginType, marginType: MarginType,
params: GetLiquidationHistoryRequestV2, params: GetLiquidationHistoryRequestV2,
): Promise<APIResponse<any>> { ): Promise<APIResponse<MarginLiquidationHistoryV2>> {
assertMarginType(marginType); assertMarginType(marginType);
return this.getPrivate( return this.getPrivate(
`/api/v2/margin/${marginType}/liquidation-history`, `/api/v2/margin/${marginType}/liquidation-history`,
@@ -1676,7 +1696,7 @@ export class RestClientV2 extends BaseRestClient {
getMarginFinancialHistory( getMarginFinancialHistory(
marginType: MarginType, marginType: MarginType,
params: GetFinancialHistoryRequestV2, params: GetFinancialHistoryRequestV2,
): Promise<APIResponse<any>> { ): Promise<APIResponse<MarginFinancialHistoryV2>> {
assertMarginType(marginType); assertMarginType(marginType);
return this.getPrivate( return this.getPrivate(
`/api/v2/margin/${marginType}/financial-records`, `/api/v2/margin/${marginType}/financial-records`,
@@ -1693,7 +1713,7 @@ export class RestClientV2 extends BaseRestClient {
getMarginAccountAssets( getMarginAccountAssets(
marginType: MarginType, marginType: MarginType,
params?: { coin?: string }, params?: { coin?: string },
): Promise<APIResponse<any>> { ): Promise<APIResponse<MarginAccountAssetV2[]>> {
assertMarginType(marginType); assertMarginType(marginType);
return this.getPrivate( return this.getPrivate(
`/api/v2/margin/${marginType}/account/assets`, `/api/v2/margin/${marginType}/account/assets`,
@@ -1704,11 +1724,19 @@ export class RestClientV2 extends BaseRestClient {
marginBorrow( marginBorrow(
marginType: MarginType, marginType: MarginType,
params: { params: {
loanId: string;
symbol: string;
coin: string; coin: string;
borrowAmount: string; borrowAmount: string;
clientOid?: string;
}, },
): Promise<APIResponse<any>> { ): Promise<
APIResponse<{
loanId: string;
symbol: string;
coin: string;
borrowAmount: string;
}>
> {
assertMarginType(marginType); assertMarginType(marginType);
return this.postPrivate( return this.postPrivate(
`/api/v2/margin/${marginType}/account/borrow`, `/api/v2/margin/${marginType}/account/borrow`,
@@ -1719,10 +1747,21 @@ export class RestClientV2 extends BaseRestClient {
marginRepay( marginRepay(
marginType: MarginType, marginType: MarginType,
params: { params: {
remainDebtAmount: string;
symbol: string;
repayId: string;
coin: string; coin: string;
repayAmount: string; repayAmount: string;
}, },
): Promise<APIResponse<any>> { ): Promise<
APIResponse<{
symbol: string;
coin: string;
repayId: string;
remainDebtAmount: string;
repayAmount: string;
}>
> {
assertMarginType(marginType); assertMarginType(marginType);
return this.postPrivate( return this.postPrivate(
`/api/v2/margin/${marginType}/account/repay`, `/api/v2/margin/${marginType}/account/repay`,
@@ -1730,7 +1769,14 @@ export class RestClientV2 extends BaseRestClient {
); );
} }
getMarginRiskRate(marginType: MarginType): Promise<APIResponse<any>> { getMarginRiskRate(marginType: MarginType): Promise<
APIResponse<
{
symbol: string;
riskRateRatio: string;
}[]
>
> {
assertMarginType(marginType); assertMarginType(marginType);
return this.getPrivate(`/api/v2/margin/${marginType}/account/risk-rate`); return this.getPrivate(`/api/v2/margin/${marginType}/account/risk-rate`);
} }
@@ -1738,7 +1784,9 @@ export class RestClientV2 extends BaseRestClient {
getMarginMaxBorrowable( getMarginMaxBorrowable(
marginType: MarginType, marginType: MarginType,
params: { coin: string }, params: { coin: string },
): Promise<APIResponse<any>> { ): Promise<
APIResponse<CrossMaxBorrowableResponseV2 | IsolatedMaxBorrowableResponseV2>
> {
assertMarginType(marginType); assertMarginType(marginType);
return this.getPrivate( return this.getPrivate(
'/api/v2/margin/${marginType}/account/max-borrowable-amount', '/api/v2/margin/${marginType}/account/max-borrowable-amount',
@@ -1749,7 +1797,11 @@ export class RestClientV2 extends BaseRestClient {
getMarginMaxTransferable( getMarginMaxTransferable(
marginType: MarginType, marginType: MarginType,
params: { coin: string }, params: { coin: string },
): Promise<APIResponse<any>> { ): Promise<
APIResponse<
CrossMaxTransferableResponseV2 | IsolatedMaxTransferableResponseV2
>
> {
assertMarginType(marginType); assertMarginType(marginType);
return this.getPrivate( return this.getPrivate(
'/api/v2/margin/${marginType}/account/max-transfer-out-amount', '/api/v2/margin/${marginType}/account/max-transfer-out-amount',
@@ -1760,7 +1812,12 @@ export class RestClientV2 extends BaseRestClient {
getMarginInterestRateAndMaxBorrowable( getMarginInterestRateAndMaxBorrowable(
marginType: MarginType, marginType: MarginType,
params: { coin: string }, params: { coin: string },
): Promise<APIResponse<any>> { ): Promise<
APIResponse<
| IsolatedInterestRateAndLimitResponseV2[]
| CrossInterestRateAndLimitResponseV2[]
>
> {
assertMarginType(marginType); assertMarginType(marginType);
return this.getPrivate( return this.getPrivate(
'/api/v2/margin/${marginType}/interest-rate-and-limit', '/api/v2/margin/${marginType}/interest-rate-and-limit',
@@ -1771,7 +1828,11 @@ export class RestClientV2 extends BaseRestClient {
getMarginTierConfiguration( getMarginTierConfiguration(
marginType: MarginType, marginType: MarginType,
params: { coin: string }, params: { coin: string },
): Promise<APIResponse<any>> { ): Promise<
APIResponse<
CrossTierConfigurationResponseV2[] | IsolatedTierConfigurationResponseV2[]
>
> {
assertMarginType(marginType); assertMarginType(marginType);
return this.getPrivate(`/api/v2/margin/${marginType}/tier-data`, params); return this.getPrivate(`/api/v2/margin/${marginType}/tier-data`, params);
} }
@@ -1779,7 +1840,14 @@ export class RestClientV2 extends BaseRestClient {
marginFlashRepay( marginFlashRepay(
marginType: MarginType, marginType: MarginType,
params: { coin: string }, params: { coin: string },
): Promise<APIResponse<any>> { ): Promise<
APIResponse<{
repayId: string;
coin?: string;
symbol?: string;
result?: string;
}>
> {
assertMarginType(marginType); assertMarginType(marginType);
return this.postPrivate( return this.postPrivate(
'/api/v2/margin/${marginType}/account/flash-repay', '/api/v2/margin/${marginType}/account/flash-repay',
@@ -1790,7 +1858,14 @@ export class RestClientV2 extends BaseRestClient {
getMarginFlashRepayResult( getMarginFlashRepayResult(
marginType: MarginType, marginType: MarginType,
params: { idList: string }, params: { idList: string },
): Promise<APIResponse<any>> { ): Promise<
APIResponse<
{
repayId: string;
status: string;
}[]
>
> {
assertMarginType(marginType); assertMarginType(marginType);
return this.getPrivate( return this.getPrivate(
'/api/v2/margin/${marginType}/account/query-flash-repay-status', '/api/v2/margin/${marginType}/account/query-flash-repay-status',
@@ -1807,7 +1882,12 @@ export class RestClientV2 extends BaseRestClient {
marginSubmitOrder( marginSubmitOrder(
marginType: MarginType, marginType: MarginType,
params: MarginPlaceOrderRequestV2, params: MarginPlaceOrderRequestV2,
): Promise<APIResponse<any>> { ): Promise<
APIResponse<{
orderId: string;
clientOid: string;
}>
> {
assertMarginType(marginType); assertMarginType(marginType);
return this.postPrivate(`/api/v2/margin/${marginType}/place-order`, params); return this.postPrivate(`/api/v2/margin/${marginType}/place-order`, params);
} }
@@ -1815,7 +1895,7 @@ export class RestClientV2 extends BaseRestClient {
marginBatchSubmitOrders( marginBatchSubmitOrders(
marginType: MarginType, marginType: MarginType,
params: MarginBatchOrdersRequestV2, params: MarginBatchOrdersRequestV2,
): Promise<APIResponse<any>> { ): Promise<APIResponse<MarginBatchOrdersResponseV2>> {
assertMarginType(marginType); assertMarginType(marginType);
return this.postPrivate( return this.postPrivate(
`/api/v2/margin/${marginType}/batch-place-order`, `/api/v2/margin/${marginType}/batch-place-order`,
@@ -1830,7 +1910,12 @@ export class RestClientV2 extends BaseRestClient {
orderId?: string; orderId?: string;
clientOid?: string; clientOid?: string;
}, },
): Promise<APIResponse<any>> { ): Promise<
APIResponse<{
orderId: string;
clientOid: string;
}>
> {
assertMarginType(marginType); assertMarginType(marginType);
return this.postPrivate( return this.postPrivate(
`/api/v2/margin/${marginType}/cancel-order`, `/api/v2/margin/${marginType}/cancel-order`,
@@ -1844,7 +1929,7 @@ export class RestClientV2 extends BaseRestClient {
symbol: string; symbol: string;
orderIdList: string[]; orderIdList: string[];
}, },
): Promise<APIResponse<any>> { ): Promise<APIResponse<MarginBatchOrdersResponseV2>> {
assertMarginType(marginType); assertMarginType(marginType);
return this.postPrivate( return this.postPrivate(
'/api/v2/margin/${marginType}/batch-cancel-order', '/api/v2/margin/${marginType}/batch-cancel-order',
@@ -1855,7 +1940,7 @@ export class RestClientV2 extends BaseRestClient {
getMarginOpenOrders( getMarginOpenOrders(
marginType: MarginType, marginType: MarginType,
params: GetMarginCurrentOrdersRequestV2, params: GetMarginCurrentOrdersRequestV2,
): Promise<APIResponse<any>> { ): Promise<APIResponse<MarginCurrentOrdersV2>> {
assertMarginType(marginType); assertMarginType(marginType);
return this.getPrivate(`/api/v2/margin/${marginType}/open-orders`, params); return this.getPrivate(`/api/v2/margin/${marginType}/open-orders`, params);
} }
@@ -1863,7 +1948,7 @@ export class RestClientV2 extends BaseRestClient {
getMarginHistoricOrders( getMarginHistoricOrders(
marginType: MarginType, marginType: MarginType,
params: GetHistoryOrdersRequestV2, params: GetHistoryOrdersRequestV2,
): Promise<APIResponse<any>> { ): Promise<APIResponse<MarginHistoryOrdersV2>> {
assertMarginType(marginType); assertMarginType(marginType);
return this.getPrivate( return this.getPrivate(
`/api/v2/margin/${marginType}/history-orders`, `/api/v2/margin/${marginType}/history-orders`,
@@ -1874,7 +1959,7 @@ export class RestClientV2 extends BaseRestClient {
getMarginHistoricOrderFills( getMarginHistoricOrderFills(
marginType: MarginType, marginType: MarginType,
params: GetMarginOrderFillsRequestV2, params: GetMarginOrderFillsRequestV2,
): Promise<APIResponse<any>> { ): Promise<APIResponse<MarginOrderFillsV2>> {
assertMarginType(marginType); assertMarginType(marginType);
return this.getPrivate(`/api/v2/margin/${marginType}/fills`, params); return this.getPrivate(`/api/v2/margin/${marginType}/fills`, params);
} }
@@ -1882,7 +1967,7 @@ export class RestClientV2 extends BaseRestClient {
getMarginLiquidationOrders( getMarginLiquidationOrders(
marginType: MarginType, marginType: MarginType,
params: GetMarginLiquidationOrdersRequestV2, params: GetMarginLiquidationOrdersRequestV2,
): Promise<APIResponse<any>> { ): Promise<APIResponse<MarginLiquidationOrdersV2>> {
assertMarginType(marginType); assertMarginType(marginType);
return this.getPrivate( return this.getPrivate(
`/api/v2/margin/${marginType}/liquidation-order`, `/api/v2/margin/${marginType}/liquidation-order`,

View File

@@ -4,4 +4,5 @@ export * from './v1/spot';
export * from './v2/broker'; export * from './v2/broker';
export * from './v2/common'; export * from './v2/common';
export * from './v2/futures'; export * from './v2/futures';
export * from './v2/margin';
export * from './v2/spot'; export * from './v2/spot';

View File

@@ -0,0 +1,335 @@
/**
*
* * Margin | Common
*
*/
export interface MarginCurrencyV2 {
symbol: string;
baseCoin: string;
quoteCoin: string;
maxCrossedLeverage: string;
maxIsolatedLeverage: string;
warningRiskRatio: string;
liquidationRiskRatio: string;
minTradeAmount: string;
maxTradeAmount: string;
takerFeeRate: string;
makerFeeRate: string;
pricePrecision: string;
quantityPrecision: string;
minTradeUSDT: string;
isBorrowable: boolean;
userMinBorrow: string;
status: string;
isIsolatedBaseBorrowable: boolean;
isIsolatedQuoteBorrowable: boolean;
isCrossBorrowable: boolean;
}
/**
*
* * Margin | Cross/Isolated | Order Record
*
*/
export interface MarginBorrowHistoryV2 {
resultList: {
loanId: string;
coin: string;
borrowAmount: string;
borrowType: string;
cTime: string;
uTime: string;
}[];
maxId: string;
minId: string;
}
export interface MarginRepaymentHistoryV2 {
resultList: {
repayId: string;
coin: string;
repayAmount: string;
repayType: string;
repayInterest: string;
repayPrincipal: string;
symbol: string;
cTime: string;
uTime: string;
}[];
maxId: string;
minId: string;
}
export interface MarginInterestHistoryV2 {
resultList: {
interestId: string;
interestCoin: string;
dailyInterestRate: string;
loanCoin: string;
interestAmount: string;
interstType: string;
symbol: string;
cTime: string;
uTime: string;
}[];
maxId: string;
minId: string;
}
export interface MarginLiquidationHistoryV2 {
resultList: {
liqId: string;
symbol: string;
liqStartTime: string;
liqEndTime: string;
liqRiskRatio: string;
totalAssets: string;
totalDebt: string;
liqFee: string;
cTime: string;
uTime: string;
}[];
maxId: string;
minId: string;
}
export interface MarginFinancialHistoryV2 {
resultList: {
coin: string;
symbol: string;
marginId: string;
amount: string;
balance: string;
fee: string;
marginType: string;
cTime: string;
uTime: string;
}[];
maxId: string;
minId: string;
}
/**
*
* * Margin | Cross/Isolated | Account
*
*/
export interface MarginAccountAssetV2 {
symbol: string;
coin: string;
totalAmount: string;
available: string;
frozen: string;
borrow: string;
interest: string;
net: string;
coupon: string;
cTime: string;
uTime: string;
}
export interface CrossMaxBorrowableResponseV2 {
coin: string;
maxBorrowableAmount: string;
}
export interface IsolatedMaxBorrowableResponseV2 {
symbol: string;
baseCoin: string;
baseCoinMaxBorrowAmount: string;
quoteCoin: string;
quoteCoinMaxBorrowAmount: string;
}
export interface CrossMaxTransferableResponseV2 {
coin: string;
maxTransferOutAmount: string;
}
export interface IsolatedMaxTransferableResponseV2 {
baseCoin: string;
symbol: string;
baseCoinMaxTransferOutAmount: string;
quoteCoin: string;
quoteCoinMaxTransferOutAmount: string;
}
export interface CrossInterestRateAndLimitResponseV2 {
transferable: boolean;
leverage: string;
coin: string;
borrowable: boolean;
dailyInterestRate: string;
annualInterestRate: string;
maxBorrowableAmount: string;
vipList: {
level: string;
limit: string;
dailyInterestRate: string;
annualInterestRate: string;
discountRate: string;
}[];
}
export interface IsolatedInterestRateAndLimitResponseV2 {
symbol: string;
leverage: string;
baseCoin: string;
baseTransferable: boolean;
baseBorrowable: boolean;
baseDailyInterestRate: string;
baseAnnuallyInterestRate: string;
baseMaxBorrowableAmount: string;
baseVipList: {
level: string;
dailyInterestRate: string;
limit: string;
annuallyInterestRate: string;
discountRate: string;
}[];
quoteCoin: string;
quoteTransferable: boolean;
quoteBorrowable: boolean;
quoteDailyInterestRate: string;
quoteAnnuallyInterestRate: string;
quoteMaxBorrowableAmount: string;
quoteList: {
level: string;
dailyInterestRate: string;
limit: string;
annuallyInterestRate: string;
discountRate: string;
}[];
}
export interface CrossTierConfigurationResponseV2 {
tier: string;
leverage: string;
coin: string;
maxBorrowableAmount: string;
maintainMarginRate: string;
}
export interface IsolatedTierConfigurationResponseV2 {
tier: string;
symbol: string;
leverage: string;
baseCoin: string;
quoteCoin: string;
baseMaxBorrowableAmount: string;
quoteMaxBorrowableAmount: string;
maintainMarginRate: string;
initRate: string;
}
/**
*
* * Margin | Cross/Isolated | Trade
*
*/
export interface MarginBatchOrdersResponseV2 {
successList: {
orderId: string;
clientOid: string;
}[];
failureList: {
clientOid: string;
errorMsg: string;
}[];
}
export interface MarginCurrentOrdersV2 {
orderList: {
orderId: string;
symbol: string;
orderType: string;
enterPointSource: string;
clientOid: string;
loanType: string;
price: string;
side: string;
status: string;
baseSize: string;
quoteSize: string;
priceAvg: string;
size: string;
amount: string;
force: string;
cTime: string;
uTime: string;
}[];
maxId: string;
minId: string;
}
export interface MarginHistoryOrdersV2 {
orderList: {
orderId: string;
symbol: string;
orderType: string;
enterPointSource: string;
clientOid: string;
loanType: string;
price: string;
side: string;
status: string;
baseSize: string;
quoteSize: string;
priceAvg: string;
size: string;
amount: string;
force: string;
cTime: string;
uTime: string;
}[];
maxId: string;
minId: string;
}
export interface MarginOrderFillsV2 {
fills: {
orderId: string;
tradeId: string;
orderType: string;
side: string;
priceAvg: string;
size: string;
amount: string;
tradeScope: string;
feeDetail: {
deduction: string;
feeCoin: string;
totalDeductionFee: string;
totalFee: string;
};
cTime: string;
uTime: string;
}[];
minId: string;
maxId: string;
}
export interface MarginLiquidationOrdersV2 {
resultList: {
symbol: string;
orderType: string;
side: string;
priceAvg: string;
price: string;
fillSize: string;
size: string;
amount: string;
orderId: string;
fromCoin: string;
toCoin: string;
fromSize: string;
toSize: string;
cTime: string;
uTime: string;
}[];
idLessThan: string;
}