add v5 account rest endpoints
This commit is contained in:
@@ -65,6 +65,20 @@ import {
|
||||
ExecutionV5,
|
||||
GetClosedPnLParamsV5,
|
||||
ClosedPnLV5,
|
||||
GetWalletBalanceParamsV5,
|
||||
WalletBalanceV5,
|
||||
UnifiedAccountUpgradeResultV5,
|
||||
GetBorrowHistoryParamsV5,
|
||||
BorrowHistoryRecordV5,
|
||||
CollateralInfoV5,
|
||||
CoinGreeksV5,
|
||||
FeeRateV5,
|
||||
AccountInfoV5,
|
||||
GetTransactionLogParamsV5,
|
||||
TransactionLogV5,
|
||||
AccountMarginModeV5,
|
||||
MMPModifyParamsV5,
|
||||
MMPStateV5,
|
||||
} from './types';
|
||||
import { REST_CLIENT_TYPE_ENUM } from './util';
|
||||
import BaseRestClient from './util/BaseRestClient';
|
||||
@@ -544,6 +558,134 @@ export class RestClientV5 extends BaseRestClient {
|
||||
return this.getPrivate('/v5/position/closed-pnl', params);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Account APIs
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Obtain wallet balance, query asset information of each currency, and account risk rate information under unified margin mode.
|
||||
*
|
||||
* By default, currency information with assets or liabilities of 0 is not returned.
|
||||
*/
|
||||
getWalletBalance(
|
||||
params: GetWalletBalanceParamsV5
|
||||
): Promise<APIResponseV3WithTime<WalletBalanceV5>> {
|
||||
return this.getPrivate('/v5/account/wallet-balance', params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade to unified account.
|
||||
*
|
||||
* Banned/OTC loan/Net asset unsatisfying/Express path users cannot upgrade the account to Unified Account for now.
|
||||
*/
|
||||
upgradeToUnifiedAccount(): Promise<
|
||||
APIResponseV3WithTime<UnifiedAccountUpgradeResultV5>
|
||||
> {
|
||||
return this.postPrivate('/v5/account/upgrade-to-uta');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get interest records, sorted in reverse order of creation time.
|
||||
*
|
||||
* Unified account
|
||||
*/
|
||||
getBorrowHistory(
|
||||
params?: GetBorrowHistoryParamsV5
|
||||
): Promise<APIResponseV3WithTime<CursorListV5<BorrowHistoryRecordV5[]>>> {
|
||||
return this.getPrivate('/v5/account/borrow-history', params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the collateral information of the current unified margin account, including loan interest rate,
|
||||
* loanable amount, collateral conversion rate, whether it can be mortgaged as margin, etc.
|
||||
*/
|
||||
getCollateralInfo(
|
||||
currency?: string
|
||||
): Promise<APIResponseV3WithTime<{ list: CollateralInfoV5[] }>> {
|
||||
return this.getPrivate('/v5/account/collateral-info', { currency });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current account Greeks information
|
||||
*/
|
||||
getCoinGreeks(
|
||||
baseCoin?: string
|
||||
): Promise<APIResponseV3WithTime<{ list: CoinGreeksV5[] }>> {
|
||||
return this.getPrivate(
|
||||
'/v5/asset/coin-greeks',
|
||||
baseCoin ? { baseCoin } : undefined
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the trading fee rate of derivatives.
|
||||
* Covers: USDT perpetual / Inverse perpetual / Inverse futures
|
||||
*/
|
||||
getFeeRate(
|
||||
symbol?: string
|
||||
): Promise<APIResponseV3WithTime<{ list: FeeRateV5[] }>> {
|
||||
return this.getPrivate(
|
||||
'/v5/account/fee-rate',
|
||||
symbol ? { symbol } : undefined
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the margin mode and the upgraded status of account
|
||||
*/
|
||||
getAccountInfo(): Promise<APIResponseV3<AccountInfoV5>> {
|
||||
return this.getPrivate('/v5/account/info');
|
||||
}
|
||||
|
||||
/**
|
||||
* Query transaction logs in Unified account.
|
||||
*/
|
||||
getTransactionLog(
|
||||
params?: GetTransactionLogParamsV5
|
||||
): Promise<APIResponseV3WithTime<CursorListV5<TransactionLogV5[]>>> {
|
||||
return this.getPrivate('/v5/account/transaction-log', params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default is regular margin mode.
|
||||
*
|
||||
* This mode is valid for USDT Perp, USDC Perp and USDC Option.
|
||||
*/
|
||||
setMarginMode(
|
||||
marginMode: AccountMarginModeV5
|
||||
): Promise<
|
||||
APIResponseV3<{ reasons: { reasonCode: string; reasonMsg: string }[] }>
|
||||
> {
|
||||
return this.postPrivate('/v5/account/set-margin-mode', {
|
||||
setMarginMode: marginMode,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure Market Maker Protection (MMP)
|
||||
*/
|
||||
setMMP(params: MMPModifyParamsV5): Promise<APIResponseV3<undefined>> {
|
||||
return this.postPrivate('/v5/account/mmp-modify', params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Once the mmp triggered, you can unfreeze the account via this endpoint
|
||||
*/
|
||||
resetMMP(baseCoin: string): Promise<APIResponseV3<undefined>> {
|
||||
return this.postPrivate('/v5/account/mmp-modify', { baseCoin });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get MMP State
|
||||
*/
|
||||
getMMPState(
|
||||
baseCoin: string
|
||||
): Promise<APIResponseV3WithTime<{ result: MMPStateV5[] }>> {
|
||||
return this.getPrivate('/v5/account/mmp-state', { baseCoin });
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
@@ -8,6 +8,7 @@ export * from './usdc-perp';
|
||||
export * from './usdc-options';
|
||||
export * from './usdc-shared';
|
||||
export * from './unified-margin';
|
||||
export * from './v5-account';
|
||||
export * from './v5-market';
|
||||
export * from './v5-position';
|
||||
export * from './v5-trade';
|
||||
|
||||
34
src/types/request/v5-account.ts
Normal file
34
src/types/request/v5-account.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { AccountTypeV5, CategoryV5, TransactionTypeV5 } from '../v5-shared';
|
||||
|
||||
export interface GetWalletBalanceParamsV5 {
|
||||
accountType: AccountTypeV5;
|
||||
coin?: string;
|
||||
}
|
||||
|
||||
export interface GetBorrowHistoryParamsV5 {
|
||||
currency?: string;
|
||||
startTime?: number;
|
||||
endTime?: number;
|
||||
limit?: number;
|
||||
cursor?: string;
|
||||
}
|
||||
|
||||
export interface GetTransactionLogParamsV5 {
|
||||
accountType?: AccountTypeV5;
|
||||
category?: CategoryV5;
|
||||
currency?: string;
|
||||
baseCoin?: string;
|
||||
type?: TransactionTypeV5;
|
||||
startTime?: number;
|
||||
endTime?: number;
|
||||
limit?: number;
|
||||
cursor?: string;
|
||||
}
|
||||
|
||||
export interface MMPModifyParamsV5 {
|
||||
baseCoin: string;
|
||||
window: string;
|
||||
frozenPeriod: string;
|
||||
qtyLimit: string;
|
||||
deltaLimit: string;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ export * from './shared';
|
||||
export * from './spot';
|
||||
export * from './usdt-perp';
|
||||
export * from './unified-margin';
|
||||
export * from './v5-account';
|
||||
export * from './v5-market';
|
||||
export * from './v5-position';
|
||||
export * from './v5-trade';
|
||||
|
||||
113
src/types/response/v5-account.ts
Normal file
113
src/types/response/v5-account.ts
Normal file
@@ -0,0 +1,113 @@
|
||||
import { AccountTypeV5, CategoryV5, TransactionTypeV5 } from '../v5-shared';
|
||||
|
||||
export interface WalletBalanceV5Coin {
|
||||
coin: string;
|
||||
equity: string;
|
||||
usdValue: string;
|
||||
walletBalance: string;
|
||||
borrowAmount: string;
|
||||
availableToBorrow: string;
|
||||
availableToWithdraw: string;
|
||||
accruedInterest: string;
|
||||
totalOrderIM: string;
|
||||
totalPositionIM: string;
|
||||
totalPositionMM: string;
|
||||
unrealisedPnl: string;
|
||||
cumRealisedPnl: string;
|
||||
}
|
||||
|
||||
export interface WalletBalanceV5 {
|
||||
accountType: AccountTypeV5;
|
||||
accountIMRate: string;
|
||||
accountMMRate: string;
|
||||
totalEquity: string;
|
||||
totalWalletBalance: string;
|
||||
totalMarginBalance: string;
|
||||
totalAvailableBalance: string;
|
||||
totalPerpUPL: string;
|
||||
totalInitialMargin: string;
|
||||
totalMaintenanceMargin: string;
|
||||
coin: WalletBalanceV5Coin[];
|
||||
}
|
||||
|
||||
export type UnifiedUpdateStatusV5 = 'FAIL' | 'PROCESS' | 'SUCCESS';
|
||||
|
||||
export interface UnifiedAccountUpgradeResultV5 {
|
||||
unifiedUpdateStatus: UnifiedUpdateStatusV5;
|
||||
unifiedUpdateMsg: {
|
||||
msg: string[] | null;
|
||||
};
|
||||
}
|
||||
|
||||
export interface BorrowHistoryRecordV5 {
|
||||
currency: string;
|
||||
createdTime: number;
|
||||
borrowCost: string;
|
||||
hourlyBorrowRate: string;
|
||||
InterestBearingBorrowSize: string;
|
||||
costExemption: string;
|
||||
}
|
||||
|
||||
export interface CollateralInfoV5 {
|
||||
currency: string;
|
||||
hourlyBorrowRate: string;
|
||||
maxBorrowingAmount: string;
|
||||
freeBorrowingAmount: string;
|
||||
borrowAmount: string;
|
||||
availableToBorrow: string;
|
||||
borrowable: boolean;
|
||||
marginCollateral: boolean;
|
||||
collateralRatio: string;
|
||||
}
|
||||
|
||||
export interface CoinGreeksV5 {
|
||||
baseCoin: string;
|
||||
totalDelta: string;
|
||||
totalGamma: string;
|
||||
totalVega: string;
|
||||
totalTheta: string;
|
||||
}
|
||||
|
||||
export interface FeeRateV5 {
|
||||
symbol: string;
|
||||
takerFeeRate: string;
|
||||
makerFeeRate: string;
|
||||
}
|
||||
|
||||
export interface AccountInfoV5 {
|
||||
unifiedMarginStatus: number;
|
||||
marginMode: 'REGULAR_MARGIN' | 'PORTFOLIO_MARGIN';
|
||||
updatedTime: string;
|
||||
}
|
||||
|
||||
export interface TransactionLogV5 {
|
||||
symbol: string;
|
||||
category: CategoryV5;
|
||||
side: string;
|
||||
transactionTime: string;
|
||||
type: TransactionTypeV5;
|
||||
qty: string;
|
||||
size: string;
|
||||
currency: string;
|
||||
tradePrice: string;
|
||||
funding: string;
|
||||
fee: string;
|
||||
cashFlow: string;
|
||||
change: string;
|
||||
cashBalance: string;
|
||||
feeRate: string;
|
||||
tradeId: string;
|
||||
orderId: string;
|
||||
orderLinkId: string;
|
||||
}
|
||||
|
||||
export interface MMPStateV5 {
|
||||
baseCoin: string;
|
||||
mmpEnabled: boolean;
|
||||
window: string;
|
||||
frozenPeriod: string;
|
||||
qtyLimit: string;
|
||||
deltaLimit: string;
|
||||
mmpFrozenUntil: string;
|
||||
mmpFrozen: boolean;
|
||||
}
|
||||
@@ -11,6 +11,28 @@ export type PositionIdx = 0 | 1 | 2;
|
||||
*/
|
||||
export type TradeModeV5 = 0 | 1;
|
||||
export type TPSLModeV5 = 'Full' | 'Partial';
|
||||
export type AccountMarginModeV5 = 'REGULAR_MARGIN' | 'PORTFOLIO_MARGIN';
|
||||
|
||||
export type AccountTypeV5 =
|
||||
| 'CONTRACT'
|
||||
| 'SPOT'
|
||||
| 'INVESTMENT'
|
||||
| 'OPTION'
|
||||
| 'UNIFIED'
|
||||
| 'FUND';
|
||||
|
||||
export type TransactionTypeV5 =
|
||||
| 'TRANSFER_IN'
|
||||
| 'TRANSFER_OUT'
|
||||
| 'TRADE'
|
||||
| 'SETTLEMENT'
|
||||
| 'DELIVERY'
|
||||
| 'LIQUIDATION'
|
||||
| 'BONUS'
|
||||
| 'FEE_REFUND'
|
||||
| 'INTEREST'
|
||||
| 'CURRENCY_BUY'
|
||||
| 'CURRENCY_SELL';
|
||||
|
||||
export interface CategoryCursorListV5<T extends unknown[]> {
|
||||
category: CategoryV5;
|
||||
|
||||
Reference in New Issue
Block a user