feat(): add new spot wallet endpoints
This commit is contained in:
@@ -7,6 +7,8 @@ import {
|
|||||||
KlineInterval,
|
KlineInterval,
|
||||||
CoinBalance,
|
CoinBalance,
|
||||||
SymbolRules,
|
SymbolRules,
|
||||||
|
NewSpotSubTransfer,
|
||||||
|
NewSpotWithdraw,
|
||||||
} from './types';
|
} from './types';
|
||||||
import { REST_CLIENT_TYPE_ENUM } from './util';
|
import { REST_CLIENT_TYPE_ENUM } from './util';
|
||||||
import BaseRestClient from './util/BaseRestClient';
|
import BaseRestClient from './util/BaseRestClient';
|
||||||
@@ -104,6 +106,18 @@ export class SpotClient extends BaseRestClient {
|
|||||||
return this.postPrivate('/api/spot/v1/wallet/transfer', params);
|
return this.postPrivate('/api/spot/v1/wallet/transfer', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Initiate wallet transfer (v2 endpoint) */
|
||||||
|
transferV2(params: NewWalletTransfer): Promise<APIResponse<any>> {
|
||||||
|
return this.postPrivate('/api/spot/v1/wallet/transfer-v2', params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transfer main-sub, sub-sub or sub-main
|
||||||
|
*/
|
||||||
|
subTransfer(params: NewSpotSubTransfer): Promise<APIResponse<any>> {
|
||||||
|
return this.postPrivate('/api/spot/v1/wallet/subTransfer', params);
|
||||||
|
}
|
||||||
|
|
||||||
/** Get Coin Address */
|
/** Get Coin Address */
|
||||||
getDepositAddress(coin: string, chain?: string): Promise<APIResponse<any>> {
|
getDepositAddress(coin: string, chain?: string): Promise<APIResponse<any>> {
|
||||||
return this.getPrivate('/api/spot/v1/wallet/deposit-address', {
|
return this.getPrivate('/api/spot/v1/wallet/deposit-address', {
|
||||||
@@ -112,19 +126,16 @@ export class SpotClient extends BaseRestClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Withdraw Coins On Chain*/
|
/** Withdraw Coins On Chain */
|
||||||
withdraw(params: {
|
withdraw(params: NewSpotWithdraw): Promise<APIResponse<any>> {
|
||||||
coin: string;
|
|
||||||
address: string;
|
|
||||||
chain: string;
|
|
||||||
tag?: string;
|
|
||||||
amount: string;
|
|
||||||
remark?: string;
|
|
||||||
clientOid?: string;
|
|
||||||
}): Promise<APIResponse<any>> {
|
|
||||||
return this.postPrivate('/api/spot/v1/wallet/withdrawal', params);
|
return this.postPrivate('/api/spot/v1/wallet/withdrawal', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Withdraw Coins On Chain (v2 endpoint) */
|
||||||
|
withdrawV2(params: NewSpotWithdraw): Promise<APIResponse<any>> {
|
||||||
|
return this.postPrivate('/api/spot/v1/wallet/withdrawal-v2', params);
|
||||||
|
}
|
||||||
|
|
||||||
/** Inner Withdraw : Internal withdrawal means that both users are on the Bitget platform */
|
/** Inner Withdraw : Internal withdrawal means that both users are on the Bitget platform */
|
||||||
innerWithdraw(
|
innerWithdraw(
|
||||||
coin: string,
|
coin: string,
|
||||||
@@ -140,6 +151,21 @@ export class SpotClient extends BaseRestClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Inner Withdraw (v2 endpoint) : Internal withdrawal means that both users are on the Bitget platform */
|
||||||
|
innerWithdrawV2(
|
||||||
|
coin: string,
|
||||||
|
toUid: string,
|
||||||
|
amount: string,
|
||||||
|
clientOid?: string
|
||||||
|
): Promise<APIResponse<any>> {
|
||||||
|
return this.postPrivate('/api/spot/v1/wallet/withdrawal-inner-v2', {
|
||||||
|
coin,
|
||||||
|
toUid,
|
||||||
|
amount,
|
||||||
|
clientOid,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/** Get Withdraw List */
|
/** Get Withdraw List */
|
||||||
getWithdrawals(
|
getWithdrawals(
|
||||||
coin: string,
|
coin: string,
|
||||||
|
|||||||
@@ -21,3 +21,23 @@ export interface NewSpotOrder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type NewBatchSpotOrder = Omit<NewSpotOrder, 'symbol'>;
|
export type NewBatchSpotOrder = Omit<NewSpotOrder, 'symbol'>;
|
||||||
|
|
||||||
|
export interface NewSpotSubTransfer {
|
||||||
|
fromType: WalletType;
|
||||||
|
toType: WalletType;
|
||||||
|
amount: string;
|
||||||
|
coin: string;
|
||||||
|
clientOid: string;
|
||||||
|
fromUserId: string;
|
||||||
|
toUserId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NewSpotWithdraw {
|
||||||
|
coin: string;
|
||||||
|
address: string;
|
||||||
|
chain: string;
|
||||||
|
tag?: string;
|
||||||
|
amount: string;
|
||||||
|
remark?: string;
|
||||||
|
clientOid?: string;
|
||||||
|
}
|
||||||
|
|||||||
@@ -43,6 +43,47 @@ describe('Private Spot REST API POST Endpoints', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('transferV2()', async () => {
|
||||||
|
try {
|
||||||
|
expect(
|
||||||
|
await api.transferV2({
|
||||||
|
amount: '100',
|
||||||
|
coin,
|
||||||
|
fromType: 'spot',
|
||||||
|
toType: 'mix_usdt',
|
||||||
|
})
|
||||||
|
).toStrictEqual('');
|
||||||
|
} catch (e) {
|
||||||
|
// console.error('transferV2: ', e);
|
||||||
|
expect(e.body).toMatchObject({
|
||||||
|
// not sure what this error means, probably no balance. Seems to change?
|
||||||
|
code: expect.stringMatching(/42013|43117/gim),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('subTransfer()', async () => {
|
||||||
|
try {
|
||||||
|
expect(
|
||||||
|
await api.subTransfer({
|
||||||
|
fromUserId: '123',
|
||||||
|
toUserId: '456',
|
||||||
|
amount: '100',
|
||||||
|
clientOid: '123456',
|
||||||
|
coin,
|
||||||
|
fromType: 'spot',
|
||||||
|
toType: 'mix_usdt',
|
||||||
|
})
|
||||||
|
).toStrictEqual('');
|
||||||
|
} catch (e) {
|
||||||
|
// console.error('transferV2: ', e);
|
||||||
|
expect(e.body).toMatchObject({
|
||||||
|
// not sure what this error means, probably no balance. Seems to change?
|
||||||
|
code: expect.stringMatching(/42013|43117/gim),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('withdraw()', async () => {
|
it('withdraw()', async () => {
|
||||||
try {
|
try {
|
||||||
expect(
|
expect(
|
||||||
@@ -63,6 +104,26 @@ describe('Private Spot REST API POST Endpoints', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('withdrawV2()', async () => {
|
||||||
|
try {
|
||||||
|
expect(
|
||||||
|
await api.withdrawV2({
|
||||||
|
amount: '100',
|
||||||
|
coin,
|
||||||
|
chain: 'TRC20',
|
||||||
|
address: `123456`,
|
||||||
|
})
|
||||||
|
).toMatchObject({
|
||||||
|
...sucessEmptyResponseObject(),
|
||||||
|
data: expect.any(Array),
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
expect(e.body).toMatchObject({
|
||||||
|
code: API_ERROR_CODE.INCORRECT_PERMISSIONS,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('innerWithdraw()', async () => {
|
it('innerWithdraw()', async () => {
|
||||||
try {
|
try {
|
||||||
expect(await api.innerWithdraw(coin, '12345', '1')).toMatchObject({
|
expect(await api.innerWithdraw(coin, '12345', '1')).toMatchObject({
|
||||||
@@ -76,6 +137,19 @@ describe('Private Spot REST API POST Endpoints', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('innerWithdrawV2()', async () => {
|
||||||
|
try {
|
||||||
|
expect(await api.innerWithdrawV2(coin, '12345', '1')).toMatchObject({
|
||||||
|
...sucessEmptyResponseObject(),
|
||||||
|
data: expect.any(Array),
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
expect(e.body).toMatchObject({
|
||||||
|
code: API_ERROR_CODE.INCORRECT_PERMISSIONS,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('submitOrder()', async () => {
|
it('submitOrder()', async () => {
|
||||||
try {
|
try {
|
||||||
expect(
|
expect(
|
||||||
|
|||||||
Reference in New Issue
Block a user