v3.4.0: feat(#219) add support for account asset v3 REST endpoints

This commit is contained in:
tiagosiebler
2023-02-13 17:20:03 +00:00
parent 0c0900e608
commit 6fa204e8bd
11 changed files with 870 additions and 49 deletions

View File

@@ -0,0 +1,309 @@
import {
AccountCoinBalanceResponseV3,
AccountCoinBalancesRequestV3,
AccountCoinBalancesResponseV3,
APIKeyInfoV3,
APIResponseV3WithTime,
APIResponseWithTime,
AssetInfoRequestV3,
AssetInfoResponseV3,
CoinInfoQueryResponseV3,
CreateSubAPIKeyRequestV3,
CreateSubAPIKeyResponseV3,
CreateSubMemberRequestV3,
CreateSubMemberResponseV3,
DepositAddressResponseV3,
DepositRecordQueryRequestV3,
DepositRecordQueryResponseV3,
InternalTransferRequestV3,
ModifyAPIKeyRequestV3,
QueryDepositAddressRequestV3,
QueryInternalTransfersRequestV3,
QueryInternalTransferSResponseV3,
QuerySubAccountDepositAddressRequestV3,
SingleAccountCoinBalanceRequestV3,
SubAccountTransferRequestV3,
SubAccountTransferResponseV3,
SubDepositRecordQueryRequestV3,
SubMemberResponseV3,
SupportedDepositListRequestV3,
SupportedDepositListResponseV3,
TransferCoinListRequestV3,
UniversalTransferCreateResponse,
UniversalTransferListRequestV3,
UniversalTransferListResponseV3,
UniversalTransferRequestV3,
WithdrawCreateRequestV3,
WithdrawRecordQueryRequestV3,
WithdrawRecordsQueryResponseV3,
} from './types';
import { REST_CLIENT_TYPE_ENUM } from './util';
import BaseRestClient from './util/BaseRestClient';
/**
* REST API client for Account Asset V3 APIs
*/
export class AccountAssetClientV3 extends BaseRestClient {
getClientType() {
return REST_CLIENT_TYPE_ENUM.v3;
}
async fetchServerTime(): Promise<number> {
const res = await this.getServerTime();
return Number(res.time);
}
getServerTime(): Promise<
APIResponseV3WithTime<{ timeSecond: string; timeNano: string }>
> {
return this.get('/v3/public/time');
}
/**
*
* Transfer Data Endpoints
*
*/
createInternalTransfer(
params: InternalTransferRequestV3
): Promise<APIResponseWithTime<{ transferId: string }>> {
return this.postPrivate(
'/asset/v3/private/transfer/inter-transfer',
params
);
}
getInternalTransfers(
params: QueryInternalTransfersRequestV3
): Promise<APIResponseWithTime<QueryInternalTransferSResponseV3>> {
return this.getPrivate(
'/asset/v3/private/transfer/inter-transfer/list/query',
params
);
}
createSubAccountTransfer(params: {
transferId: string;
coin: string;
amount: string;
subMemberId: number;
type: 'IN' | 'OUT';
}): Promise<APIResponseWithTime<{ transferId: string }>> {
return this.postPrivate(
'/asset/v3/private/transfer/sub-member-transfer',
params
);
}
getSubAccountTransfers(
params?: SubAccountTransferRequestV3
): Promise<APIResponseWithTime<SubAccountTransferResponseV3>> {
return this.getPrivate(
'/asset/v3/private/transfer/sub-member-transfer/list/query',
params
);
}
getSubAccounts(): Promise<
APIResponseWithTime<{
subMemberIds: string[];
transferableSubMemberIds: string[];
}>
> {
return this.getPrivate('/asset/v3/private/transfer/sub-member/list/query');
}
enableUniversalTransfer(params?: {
subMemberIds?: string;
}): Promise<APIResponseWithTime<any>> {
return this.postPrivate(
'/asset/v3/private/transfer/transfer-sub-member-save',
params
);
}
createUniversalTransfer(
params: UniversalTransferRequestV3
): Promise<APIResponseWithTime<UniversalTransferCreateResponse>> {
return this.postPrivate(
'/asset/v3/private/transfer/universal-transfer',
params
);
}
getUniversalTransfers(
params: UniversalTransferListRequestV3
): Promise<APIResponseWithTime<UniversalTransferListResponseV3>> {
return this.getPrivate(
'/asset/v3/private/transfer/universal-transfer/list/query',
params
);
}
getTransferableCoinList(
params: TransferCoinListRequestV3
): Promise<APIResponseWithTime<{ list: string[] }>> {
return this.getPrivate(
'/asset/v3/private/transfer/transfer-coin/list/query',
params
);
}
getAccountCoinBalance(
params: SingleAccountCoinBalanceRequestV3
): Promise<APIResponseWithTime<AccountCoinBalanceResponseV3>> {
return this.getPrivate(
'/asset/v3/private/transfer/account-coin/balance/query',
params
);
}
getAccountCoinBalances(
params: AccountCoinBalancesRequestV3
): Promise<APIResponseWithTime<AccountCoinBalancesResponseV3>> {
return this.getPrivate(
'/asset/v3/private/transfer/account-coins/balance/query',
params
);
}
getAssetInfo(
params?: AssetInfoRequestV3
): Promise<APIResponseWithTime<AssetInfoResponseV3>> {
return this.getPrivate(
'/asset/v3/private/transfer/asset-info/query',
params
);
}
/**
*
* Wallet & Deposit Endpoints
*
*/
/** Get Deposit Spec */
getSupportedDepositList(
params?: SupportedDepositListRequestV3
): Promise<APIResponseWithTime<SupportedDepositListResponseV3>> {
return this.get(
'/asset/v3/public/deposit/allowed-deposit-list/query',
params
);
}
getDepositRecords(
params?: DepositRecordQueryRequestV3
): Promise<APIResponseWithTime<DepositRecordQueryResponseV3>> {
return this.getPrivate('/asset/v3/private/deposit/record/query', params);
}
getSubDepositRecords(
params: SubDepositRecordQueryRequestV3
): Promise<APIResponseWithTime<DepositRecordQueryResponseV3>> {
return this.getPrivate(
'/asset/v3/private/deposit/sub-member-record/query',
params
);
}
getWithdrawRecords(
params?: WithdrawRecordQueryRequestV3
): Promise<APIResponseWithTime<WithdrawRecordsQueryResponseV3>> {
return this.getPrivate('/asset/v3/private/withdraw/record/query', params);
}
getCoinInformation(
coin?: string
): Promise<APIResponseWithTime<CoinInfoQueryResponseV3>> {
return this.getPrivate('/asset/v3/private/coin-info/query', { coin });
}
submitWithdrawal(
params: WithdrawCreateRequestV3
): Promise<APIResponseWithTime<{ id: string }>> {
return this.postPrivate('/asset/v3/private/withdraw/create', params);
}
cancelWithdrawal(
withdrawalId: number
): Promise<APIResponseWithTime<{ status: 1 | 0 }>> {
return this.postPrivate('/asset/v3/private/withdraw/create', {
withdrawalId,
});
}
getMasterAccountDepositAddress(
params?: QueryDepositAddressRequestV3
): Promise<APIResponseWithTime<DepositAddressResponseV3>> {
return this.getPrivate('/asset/v3/private/deposit/address/query', params);
}
getSubAccountDepositAddress(
params: QuerySubAccountDepositAddressRequestV3
): Promise<APIResponseWithTime<DepositAddressResponseV3>> {
return this.getPrivate(
'/asset/v3/private/deposit/sub-member-address/query',
params
);
}
createSubMember(
params: CreateSubMemberRequestV3
): Promise<APIResponseWithTime<CreateSubMemberResponseV3>> {
return this.postPrivate('/user/v3/private/create-sub-member', params);
}
createSubAPIKey(
params: CreateSubAPIKeyRequestV3
): Promise<APIResponseWithTime<CreateSubAPIKeyResponseV3>> {
return this.postPrivate('/user/v3/private/create-sub-api', params);
}
/**
* Get Sub UID List
*/
getSubMembers(): Promise<APIResponseWithTime<SubMemberResponseV3>> {
return this.postPrivate('/user/v3/private/query-sub-members');
}
/**
* Froze Sub UID
*/
freezeSubMember(
subuid: number,
frozenStatus: 0 | 1
): Promise<APIResponseWithTime<{}>> {
return this.postPrivate('/user/v3/private/frozen-sub-member', {
subuid,
frozen: frozenStatus,
});
}
getAPIKeyInformation(): Promise<APIResponseWithTime<APIKeyInfoV3>> {
return this.getPrivate('/user/v3/private/query-api');
}
modifyMasterAPIKey(
params: ModifyAPIKeyRequestV3
): Promise<APIResponseWithTime<APIKeyInfoV3>> {
return this.postPrivate('/user/v3/private/update-api', params);
}
modifySubAPIKey(
params: ModifyAPIKeyRequestV3
): Promise<APIResponseWithTime<APIKeyInfoV3>> {
return this.postPrivate('/user/v3/private/update-sub-api', params);
}
/** WARNING: BE CAREFUL! The API key used to call this interface will be invalid immediately. */
deleteMasterAPIKey(): Promise<APIResponseWithTime<{}>> {
return this.postPrivate('/user/v3/private/delete-api');
}
/** WARNING: BE CAREFUL! The API key used to call this interface will be invalid immediately. */
deleteSubAPIKey(): Promise<APIResponseWithTime<{}>> {
return this.postPrivate('/user/v3/private/delete-sub-api');
}
}

View File

@@ -1,4 +1,5 @@
export * from './account-asset-client';
export * from './account-asset-client-v3';
export * from './copy-trading-client';
export * from './inverse-client';
export * from './inverse-futures-client';

View File

@@ -19,6 +19,24 @@ export interface InternalTransferRequest {
to_account_type: TransferAccountType;
}
export interface InternalTransferRequestV3 {
transferId: string;
coin: string;
amount: string;
fromAccountType: string;
toAccountType: string;
}
export interface QueryInternalTransfersRequestV3 {
transferId?: string;
coin: string;
status?: string;
startTime?: number;
endTime?: number;
limit?: number;
cursor?: string;
}
export interface SubAccountTransferRequest {
transfer_id: string;
coin: string;
@@ -27,6 +45,16 @@ export interface SubAccountTransferRequest {
type: TransferType;
}
export interface SubAccountTransferRequestV3 {
transferId?: string;
coin?: string;
status?: string;
startTime?: number;
endTime?: number;
limit?: number;
cursor?: string;
}
export interface TransferQueryRequest {
transfer_id?: string;
coin?: string;
@@ -52,7 +80,6 @@ export interface UniversalTransferRequest {
from_account_type: TransferAccountType;
to_account_type: TransferAccountType;
}
export interface SupportedDepositListRequest {
coin?: string;
chain?: string;
@@ -92,3 +119,140 @@ export interface WithdrawalRequest {
chain: string;
tag?: string;
}
export interface UniversalTransferRequestV3 {
transferId: string;
coin: string;
amount: string;
fromMemberId: string;
toMemberId: string;
fromAccountType: TransferAccountType;
toAccountType: TransferAccountType;
}
export interface UniversalTransferListRequestV3 {
transferId?: string;
coin: string;
status?: string;
startTime?: number;
endTime?: number;
limit?: number;
cursor?: string;
}
export interface TransferCoinListRequestV3 {
fromAccountType: TransferAccountType;
toAccountType: TransferAccountType;
}
export interface SingleAccountCoinBalanceRequestV3 {
memberId?: string;
accountType: TransferAccountType;
coin: string;
withBonus?: '0' | '1';
}
export interface AccountCoinBalancesRequestV3 {
memberId?: string;
accountType: TransferAccountType;
coin?: string;
withBonus?: '0' | '1';
}
export interface AssetInfoRequestV3 {
accountType?: TransferAccountType;
coin?: string;
}
export interface SupportedDepositListRequestV3 {
coin?: string;
chain?: string;
cursor?: string;
limit?: number;
}
export interface DepositRecordQueryRequestV3 {
startTime?: number;
endTime?: number;
coin?: string;
cursor?: string;
limit?: number;
}
export interface SubDepositRecordQueryRequestV3 {
subMemberId: number;
startTime?: number;
endTime?: number;
coin?: string;
cursor?: string;
limit?: number;
}
export interface WithdrawRecordQueryRequestV3 {
withdrawID?: number;
startTime?: number;
endTime?: number;
coin?: string;
withdrawType?: string;
cursor?: string;
limit?: number;
}
export interface WithdrawCreateRequestV3 {
coin: string;
chain: string;
address: string;
tag?: string;
amount: string;
timestamp: number;
forceChain?: 0 | 1;
}
export interface QueryDepositAddressRequestV3 {
coin?: string;
chainType?: string;
}
export interface QuerySubAccountDepositAddressRequestV3 {
coin?: string;
chainType?: string;
subMemberId: string;
}
export interface CreateSubMemberRequestV3 {
username: string;
memberType: 1 | 6;
switch?: 0 | 1;
note?: string;
}
export interface CreateSubAPIKeyRequestV3 {
subuid: string;
note?: string;
readOnly: 0 | 1;
ips?: string[];
permissions: {
ContractTrade?: [];
Spot?: string[];
Wallet?: string[];
Options?: string[];
Derivatives?: string[];
Exchange?: string[];
};
}
export interface ModifyAPIKeyRequestV3 {
readOnly: number;
ips?: string[];
permissions: {
ContractTrade?: string[];
Spot?: string[];
Wallet?: string[];
Options?: string[];
Derivatives?: string[];
CopyTrading?: string[];
BlockTrade?: string[];
Exchange?: string[];
NFT?: string[];
};
}

View File

@@ -0,0 +1,236 @@
export interface UniversalTransferCreateResponse {
transferId: string;
}
export interface UniversalTransferListResponseV3 {
list: {
transferId: string;
coin: string;
amount: string;
timestamp: string;
status: string;
fromAccountType: string;
toAccountType: string;
fromMemberId: string;
toMemberId: string;
}[];
nextPageCursor: string;
}
export interface QueryInternalTransferSResponseV3 {
list: {
transferId: string;
coin: string;
amount: string;
fromAccountType: string;
toAccountType: string;
timestamp: string;
status: string;
}[];
nextPageCursor: string;
}
export interface SubAccountTransferResponseV3 {
list: {
transferId: string;
coin: string;
amount: string;
memberId: number;
subMemberId: number;
timestamp: string;
status: string;
type: 'IN' | 'OUT';
}[];
nextPageCursor: string;
}
export interface AccountCoinBalanceResponseV3 {
accountType: string;
bizType: number;
accountId: string;
memberId: string;
balance: {
coin: string;
walletBalance: string;
transferBalance: string;
bonus: string;
};
}
export interface AccountCoinBalancesResponseV3 {
accountType: string;
memberId: string;
balance: {
coin: string;
walletBalance: string;
transferBalance: string;
bonus: string;
}[];
}
export interface AssetInfoResponseV3 {
spot: {
status: 'ACCOUNT_STATUS_NORMAL' | 'ACCOUNT_STATUS_UNSPECIFIED';
assets: {
coin: string;
frozen: string;
free: string;
withdraw: string;
}[];
};
}
export interface SupportedDepositListResponseV3 {
configList: SupportedDepositV3[];
nextPageCursor: string;
}
interface SupportedDepositV3 {
coin: string;
chain: string;
coinShowName: string;
chainType: string;
blockConfirmNumber: number;
minDepositAmount: string;
}
export interface DepositRecordQueryResponseV3 {
rows: DepositRecordV3[];
nextPageCursor: string;
}
interface DepositRecordV3 {
coin: string;
chain: string;
amount: string;
txID: string;
status: number;
toAddress: string;
tag: string;
depositFee: string;
successAt: string;
confirmations: string;
txIndex: string;
blockHash: string;
}
export interface WithdrawRecordsQueryResponseV3 {
rows: {
coin: string;
chain: string;
amount: string;
txID: string;
status: number;
toAddress: string;
tag: string;
withdrawFee: string;
createTime: string;
updateTime: string;
withdrawId: string;
withdrawType: number;
}[];
nextPageCursor: string;
}
export interface CoinInfoV3 {
name: string;
coin: string;
remainAmount: string;
chains: {
chainType: string;
confirmation: string;
withdrawFee: string;
depositMin: string;
withdrawMin: string;
chain: string;
chainDeposit: string;
chainWithdraw: string;
minAccuracy: string;
}[];
}
export interface CoinInfoQueryResponseV3 {
rows: CoinInfoV3[];
}
export interface DepositAddressChainV3 {
chainType: string;
addressDeposit: string;
tagDeposit: string;
chain: string;
}
export interface DepositAddressResponseV3 {
coin: string;
chains: DepositAddressChainV3[];
}
export interface CreateSubMemberResponseV3 {
uid: number;
username: string;
memberType: 1 | 6;
switch: 0 | 1;
note: string;
}
export interface CreateSubAPIKeyResponseV3 {
id: string;
note: string;
apiKey: string;
readOnly: string;
secret: string;
permissions: {
ContractTrade: string[];
Spot: string[];
Wallet: string[];
Options: string[];
Derivatives: string[];
CopyTrading: string[];
BlockTrade: string[];
Exchange: string[];
NFT: string[];
};
}
export interface SubMemberV3 {
uid: string;
username: string;
memberType: 1 | 6;
status: 1 | 2 | 4;
remark: string;
}
export interface SubMemberResponseV3 {
subMembers: SubMemberV3[];
}
export interface APIKeyInfoV3 {
id: string;
note: string;
apiKey: string;
readOnly: string;
secret: string;
permissions: {
ContractTrade: string[];
Spot: string[];
Wallet: string[];
Options: string[];
Derivatives: string[];
CopyTrading: string[];
BlockTrade: string[];
Exchange: string[];
NFT: string[];
};
ips: string[];
type: number;
deadlineDay: number;
expiredAt: string;
createdAt: string;
unified: number;
uta: number;
userID: number;
inviterID: number;
vipLevel: string;
mktMakerLevel: string;
affiliateID: number;
}

View File

@@ -1,3 +1,4 @@
export * from './account-asset';
export * from './contract';
export * from './shared';
export * from './spot';

View File

@@ -65,6 +65,13 @@ export interface APIResponseV3<T> {
result: T;
}
export interface APIResponseV3WithTime<T> {
retCode: number;
retMsg: 'OK' | string;
result: T;
time: number;
}
export interface APIResponseWithTime<T = {}> extends APIResponse<T> {
/** UTC timestamp */
time_now: numberInString;

View File

@@ -15,10 +15,29 @@ import {
// return request;
// });
// axios.interceptors.response.use((response) => {
// console.log(new Date(), 'Response:', JSON.stringify(response, null, 2));
// return response;
// });
if (
typeof process === 'object' &&
typeof process.env === 'object' &&
process.env.BYBITTRACE
) {
axios.interceptors.response.use((response) => {
console.log(new Date(), 'Response:', {
request: {
url: response.config.url,
method: response.config.method,
data: response.config.data,
headers: response.config.headers,
},
response: {
status: response.status,
statusText: response.statusText,
headers: response.headers,
data: response.data,
},
});
return response;
});
}
interface SignedRequestContext {
timestamp?: number;