diff --git a/src/spot-client.ts b/src/spot-client.ts index b239ec3..3e06632 100644 --- a/src/spot-client.ts +++ b/src/spot-client.ts @@ -7,6 +7,8 @@ import { KlineInterval, CoinBalance, SymbolRules, + NewSpotSubTransfer, + NewSpotWithdraw, } from './types'; import { REST_CLIENT_TYPE_ENUM } from './util'; import BaseRestClient from './util/BaseRestClient'; @@ -104,6 +106,18 @@ export class SpotClient extends BaseRestClient { return this.postPrivate('/api/spot/v1/wallet/transfer', params); } + /** Initiate wallet transfer (v2 endpoint) */ + transferV2(params: NewWalletTransfer): Promise> { + return this.postPrivate('/api/spot/v1/wallet/transfer-v2', params); + } + + /** + * Transfer main-sub, sub-sub or sub-main + */ + subTransfer(params: NewSpotSubTransfer): Promise> { + return this.postPrivate('/api/spot/v1/wallet/subTransfer', params); + } + /** Get Coin Address */ getDepositAddress(coin: string, chain?: string): Promise> { return this.getPrivate('/api/spot/v1/wallet/deposit-address', { @@ -112,19 +126,16 @@ export class SpotClient extends BaseRestClient { }); } - /** Withdraw Coins On Chain*/ - withdraw(params: { - coin: string; - address: string; - chain: string; - tag?: string; - amount: string; - remark?: string; - clientOid?: string; - }): Promise> { + /** Withdraw Coins On Chain */ + withdraw(params: NewSpotWithdraw): Promise> { return this.postPrivate('/api/spot/v1/wallet/withdrawal', params); } + /** Withdraw Coins On Chain (v2 endpoint) */ + withdrawV2(params: NewSpotWithdraw): Promise> { + return this.postPrivate('/api/spot/v1/wallet/withdrawal-v2', params); + } + /** Inner Withdraw : Internal withdrawal means that both users are on the Bitget platform */ innerWithdraw( 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> { + return this.postPrivate('/api/spot/v1/wallet/withdrawal-inner-v2', { + coin, + toUid, + amount, + clientOid, + }); + } + /** Get Withdraw List */ getWithdrawals( coin: string, diff --git a/src/types/request/spot.ts b/src/types/request/spot.ts index edc5e46..10e4fb2 100644 --- a/src/types/request/spot.ts +++ b/src/types/request/spot.ts @@ -21,3 +21,23 @@ export interface NewSpotOrder { } export type NewBatchSpotOrder = Omit; + +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; +} diff --git a/test/spot/private.write.test.ts b/test/spot/private.write.test.ts index 280a764..3ed2e8d 100644 --- a/test/spot/private.write.test.ts +++ b/test/spot/private.write.test.ts @@ -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 () => { try { 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 () => { try { 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 () => { try { expect(