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

View File

@@ -4,4 +4,5 @@ export * from './v1/spot';
export * from './v2/broker';
export * from './v2/common';
export * from './v2/futures';
export * from './v2/margin';
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;
}