chore(): lint for trailing commas, fix tests with new types

This commit is contained in:
Tiago Siebler
2023-03-22 17:02:12 +00:00
parent 831689e857
commit e9972ef829
20 changed files with 86 additions and 85 deletions

View File

@@ -47,7 +47,7 @@ function promiseSleep(milliseconds) {
// WARNING: for sensitive math you should be using a library such as decimal.js! // WARNING: for sensitive math you should be using a library such as decimal.js!
function roundDown(value, decimals) { function roundDown(value, decimals) {
return Number( return Number(
Math.floor(parseFloat(value + 'e' + decimals)) + 'e-' + decimals Math.floor(parseFloat(value + 'e' + decimals)) + 'e-' + decimals,
); );
} }
@@ -117,7 +117,7 @@ async function handleWsUpdate(event) {
const symbolRulesResult = await client.getSymbols('umcbl'); const symbolRulesResult = await client.getSymbols('umcbl');
const bitcoinUSDFuturesRule = symbolRulesResult.data.find( const bitcoinUSDFuturesRule = symbolRulesResult.data.find(
(row) => row.symbol === symbol (row) => row.symbol === symbol,
); );
console.log('symbol rules: ', bitcoinUSDFuturesRule); console.log('symbol rules: ', bitcoinUSDFuturesRule);
@@ -142,7 +142,7 @@ async function handleWsUpdate(event) {
const positionsResult = await client.getPositions('umcbl'); const positionsResult = await client.getPositions('umcbl');
const positionsToClose = positionsResult.data.filter( const positionsToClose = positionsResult.data.filter(
(pos) => pos.total !== '0' (pos) => pos.total !== '0',
); );
console.log('open positions to close: ', positionsToClose); console.log('open positions to close: ', positionsToClose);
@@ -167,7 +167,7 @@ async function handleWsUpdate(event) {
console.log( console.log(
'positions after closing all: ', 'positions after closing all: ',
await client.getPositions('umcbl') await client.getPositions('umcbl'),
); );
} catch (e) { } catch (e) {
console.error('request failed: ', e); console.error('request failed: ', e);

View File

@@ -35,7 +35,7 @@ function promiseSleep(milliseconds) {
// WARNING: for sensitive math you should be using a library such as decimal.js! // WARNING: for sensitive math you should be using a library such as decimal.js!
function roundDown(value, decimals) { function roundDown(value, decimals) {
return Number( return Number(
Math.floor(parseFloat(value + 'e' + decimals)) + 'e-' + decimals Math.floor(parseFloat(value + 'e' + decimals)) + 'e-' + decimals,
); );
} }

View File

@@ -22,7 +22,7 @@ import { WebsocketClient, DefaultLogger } from '../src';
// optionally provide rest options, e.g. to pass through a proxy // optionally provide rest options, e.g. to pass through a proxy
// }, // },
}, },
logger logger,
); );
wsClient.on('update', (data) => { wsClient.on('update', (data) => {

View File

@@ -15,7 +15,7 @@ import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../src';
// optionally provide rest options, e.g. to pass through a proxy // optionally provide rest options, e.g. to pass through a proxy
// }, // },
}, },
logger logger,
); );
wsClient.on('update', (data) => { wsClient.on('update', (data) => {

View File

@@ -30,7 +30,7 @@ export class BrokerClient extends BaseRestClient {
/** Create Sub Account */ /** Create Sub Account */
createSubAccount( createSubAccount(
subName: string, subName: string,
remark?: string remark?: string,
): Promise<APIResponse<any>> { ): Promise<APIResponse<any>> {
return this.postPrivate('/api/broker/v1/account/sub-create', { return this.postPrivate('/api/broker/v1/account/sub-create', {
subName, subName,
@@ -47,7 +47,7 @@ export class BrokerClient extends BaseRestClient {
modifySubAccount( modifySubAccount(
subUid: string, subUid: string,
perm: string, perm: string,
status: 'normal' | 'freeze' | 'del' status: 'normal' | 'freeze' | 'del',
): Promise<APIResponse<any>> { ): Promise<APIResponse<any>> {
return this.postPrivate('/api/broker/v1/account/sub-modify', { return this.postPrivate('/api/broker/v1/account/sub-modify', {
subUid, subUid,
@@ -79,7 +79,7 @@ export class BrokerClient extends BaseRestClient {
/** Get Sub Future Assets */ /** Get Sub Future Assets */
getSubFutureAssets( getSubFutureAssets(
subUid: string, subUid: string,
productType: BrokerProductType productType: BrokerProductType,
): Promise<APIResponse<any>> { ): Promise<APIResponse<any>> {
return this.getPrivate('/api/broker/v1/account/sub-future-assets', { return this.getPrivate('/api/broker/v1/account/sub-future-assets', {
subUid, subUid,
@@ -91,7 +91,7 @@ export class BrokerClient extends BaseRestClient {
getSubDepositAddress( getSubDepositAddress(
subUid: string, subUid: string,
coin: string, coin: string,
chain?: string chain?: string,
): Promise<APIResponse<any>> { ): Promise<APIResponse<any>> {
return this.postPrivate('/api/broker/v1/account/sub-address', { return this.postPrivate('/api/broker/v1/account/sub-address', {
subUid, subUid,
@@ -109,7 +109,7 @@ export class BrokerClient extends BaseRestClient {
setSubDepositAutoTransfer( setSubDepositAutoTransfer(
subUid: string, subUid: string,
coin: string, coin: string,
toAccountType: 'spot' | 'mix_usdt' | 'mix_usd' | 'mix_usdc' toAccountType: 'spot' | 'mix_usdt' | 'mix_usd' | 'mix_usdc',
): Promise<APIResponse<any>> { ): Promise<APIResponse<any>> {
return this.postPrivate('/api/broker/v1/account/sub-auto-transfer', { return this.postPrivate('/api/broker/v1/account/sub-auto-transfer', {
subUid, subUid,
@@ -130,7 +130,7 @@ export class BrokerClient extends BaseRestClient {
passphrase: string, passphrase: string,
remark: string, remark: string,
ip: string, ip: string,
perm?: string perm?: string,
): Promise<APIResponse<any>> { ): Promise<APIResponse<any>> {
return this.postPrivate('/api/broker/v1/manage/sub-api-create', { return this.postPrivate('/api/broker/v1/manage/sub-api-create', {
subUid, subUid,
@@ -148,7 +148,7 @@ export class BrokerClient extends BaseRestClient {
/** Modify Sub ApiKey (Only Broker) */ /** Modify Sub ApiKey (Only Broker) */
modifySubAPIKey( modifySubAPIKey(
params: BrokerSubAPIKeyModifyRequest params: BrokerSubAPIKeyModifyRequest,
): Promise<APIResponse<any>> { ): Promise<APIResponse<any>> {
return this.postPrivate('/api/broker/v1/manage/sub-api-modify', params); return this.postPrivate('/api/broker/v1/manage/sub-api-modify', params);
} }

View File

@@ -82,7 +82,7 @@ export default class WsStore<WsKey extends string> {
if (this.hasExistingActiveConnection(key)) { if (this.hasExistingActiveConnection(key)) {
this.logger.warning( this.logger.warning(
'WsStore setConnection() overwriting existing open connection: ', 'WsStore setConnection() overwriting existing open connection: ',
this.getWs(key) this.getWs(key),
); );
} }
this.wsState[key] = { this.wsState[key] = {
@@ -98,7 +98,7 @@ export default class WsStore<WsKey extends string> {
const ws = this.getWs(key); const ws = this.getWs(key);
this.logger.warning( this.logger.warning(
'WsStore deleting state for connection still open: ', 'WsStore deleting state for connection still open: ',
ws ws,
); );
ws?.close(); ws?.close();
} }
@@ -119,7 +119,7 @@ export default class WsStore<WsKey extends string> {
if (this.isWsOpen(key)) { if (this.isWsOpen(key)) {
this.logger.warning( this.logger.warning(
'WsStore setConnection() overwriting existing open connection: ', 'WsStore setConnection() overwriting existing open connection: ',
this.getWs(key) this.getWs(key),
); );
} }

View File

@@ -11,7 +11,7 @@ function _arrayBufferToBase64(buffer: ArrayBuffer) {
export async function signMessage( export async function signMessage(
message: string, message: string,
secret: string, secret: string,
method: 'hex' | 'base64' method: 'hex' | 'base64',
): Promise<string> { ): Promise<string> {
const encoder = new TextEncoder(); const encoder = new TextEncoder();
const key = await window.crypto.subtle.importKey( const key = await window.crypto.subtle.importKey(
@@ -19,20 +19,20 @@ export async function signMessage(
encoder.encode(secret), encoder.encode(secret),
{ name: 'HMAC', hash: { name: 'SHA-256' } }, { name: 'HMAC', hash: { name: 'SHA-256' } },
false, false,
['sign'] ['sign'],
); );
const signature = await window.crypto.subtle.sign( const signature = await window.crypto.subtle.sign(
'HMAC', 'HMAC',
key, key,
encoder.encode(message) encoder.encode(message),
); );
switch (method) { switch (method) {
case 'hex': { case 'hex': {
return Array.prototype.map return Array.prototype.map
.call(new Uint8Array(signature), (x: any) => .call(new Uint8Array(signature), (x: any) =>
('00' + x.toString(16)).slice(-2) ('00' + x.toString(16)).slice(-2),
) )
.join(''); .join('');
} }

View File

@@ -4,7 +4,7 @@ import { createHmac } from 'crypto';
export async function signMessage( export async function signMessage(
message: string, message: string,
secret: string, secret: string,
method: 'hex' | 'base64' method: 'hex' | 'base64',
): Promise<string> { ): Promise<string> {
const hmac = createHmac('sha256', secret).update(message); const hmac = createHmac('sha256', secret).update(message);

View File

@@ -30,7 +30,7 @@ export interface RestClientOptions {
export function serializeParams<T extends object | undefined = {}>( export function serializeParams<T extends object | undefined = {}>(
params: T, params: T,
strict_validation = false, strict_validation = false,
prefixWith: string = '' prefixWith: string = '',
): string { ): string {
if (!params) { if (!params) {
return ''; return '';
@@ -42,7 +42,7 @@ export function serializeParams<T extends object | undefined = {}>(
const value = params[key]; const value = params[key];
if (strict_validation === true && typeof value === 'undefined') { if (strict_validation === true && typeof value === 'undefined') {
throw new Error( throw new Error(
'Failed to sign API request due to undefined parameter' 'Failed to sign API request due to undefined parameter',
); );
} }
return `${key}=${value}`; return `${key}=${value}`;
@@ -55,7 +55,7 @@ export function serializeParams<T extends object | undefined = {}>(
export function getRestBaseUrl( export function getRestBaseUrl(
useTestnet: boolean, useTestnet: boolean,
restInverseOptions: RestClientOptions restInverseOptions: RestClientOptions,
): string { ): string {
const exchangeBaseUrls = { const exchangeBaseUrls = {
livenet: 'https://api.bitget.com', livenet: 'https://api.bitget.com',

View File

@@ -36,7 +36,7 @@ function isWsChannelEvent(event: WsBaseEvent): event is WsSnapshotChannelEvent {
/** TypeGuard: event is an account update (balance) */ /** TypeGuard: event is an account update (balance) */
export function isWsAccountSnapshotEvent( export function isWsAccountSnapshotEvent(
event: unknown event: unknown,
): event is WsSnapshotAccountEvent { ): event is WsSnapshotAccountEvent {
return ( return (
isWsSnapshotEvent(event) && isWsSnapshotEvent(event) &&
@@ -48,7 +48,7 @@ export function isWsAccountSnapshotEvent(
/** TypeGuard: event is a positions update */ /** TypeGuard: event is a positions update */
export function isWsPositionsSnapshotEvent( export function isWsPositionsSnapshotEvent(
event: unknown event: unknown,
): event is WsSnapshotPositionsEvent { ): event is WsSnapshotPositionsEvent {
return ( return (
isWsSnapshotEvent(event) && isWsSnapshotEvent(event) &&
@@ -60,14 +60,14 @@ export function isWsPositionsSnapshotEvent(
/** TypeGuard: event is a UMCBL account update (balance) */ /** TypeGuard: event is a UMCBL account update (balance) */
export function isWsFuturesAccountSnapshotEvent( export function isWsFuturesAccountSnapshotEvent(
event: unknown event: unknown,
): event is WsAccountSnapshotUMCBL { ): event is WsAccountSnapshotUMCBL {
return isWsAccountSnapshotEvent(event) && event.arg.instType === 'umcbl'; return isWsAccountSnapshotEvent(event) && event.arg.instType === 'umcbl';
} }
/** TypeGuard: event is a UMCBL positions update */ /** TypeGuard: event is a UMCBL positions update */
export function isWsFuturesPositionsSnapshotEvent( export function isWsFuturesPositionsSnapshotEvent(
event: unknown event: unknown,
): event is WSPositionSnapshotUMCBL { ): event is WSPositionSnapshotUMCBL {
return isWsPositionsSnapshotEvent(event) && event.arg.instType === 'umcbl'; return isWsPositionsSnapshotEvent(event) && event.arg.instType === 'umcbl';
} }

View File

@@ -11,7 +11,7 @@ import { BitgetInstType, WsTopicSubscribeEventArgs } from './WsStore';
*/ */
type NetworkMap< type NetworkMap<
TRequiredKeys extends string, TRequiredKeys extends string,
TOptionalKeys extends string | undefined = undefined TOptionalKeys extends string | undefined = undefined,
> = Record<TRequiredKeys, string> & > = Record<TRequiredKeys, string> &
(TOptionalKeys extends string (TOptionalKeys extends string
? Record<TOptionalKeys, string | undefined> ? Record<TOptionalKeys, string | undefined>
@@ -55,14 +55,14 @@ export const PUBLIC_WS_KEYS = [] as WsKey[];
export const PRIVATE_TOPICS = ['account', 'orders', 'positions', 'ordersAlgo']; export const PRIVATE_TOPICS = ['account', 'orders', 'positions', 'ordersAlgo'];
export function isPrivateChannel<TChannel extends string>( export function isPrivateChannel<TChannel extends string>(
channel: TChannel channel: TChannel,
): boolean { ): boolean {
return PRIVATE_TOPICS.includes(channel); return PRIVATE_TOPICS.includes(channel);
} }
export function getWsKeyForTopic( export function getWsKeyForTopic(
subscribeEvent: WsTopicSubscribeEventArgs, subscribeEvent: WsTopicSubscribeEventArgs,
isPrivate?: boolean isPrivate?: boolean,
): WsKey { ): WsKey {
const instType = subscribeEvent.instType.toUpperCase() as BitgetInstType; const instType = subscribeEvent.instType.toUpperCase() as BitgetInstType;
switch (instType) { switch (instType) {
@@ -78,7 +78,7 @@ export function getWsKeyForTopic(
default: { default: {
throw neverGuard( throw neverGuard(
instType, instType,
`getWsKeyForTopic(): Unhandled market ${'instrumentId'}` `getWsKeyForTopic(): Unhandled market ${'instrumentId'}`,
); );
} }
} }
@@ -110,14 +110,14 @@ export async function getWsAuthSignature(
apiKey: string | undefined, apiKey: string | undefined,
apiSecret: string | undefined, apiSecret: string | undefined,
apiPass: string | undefined, apiPass: string | undefined,
recvWindow: number = 0 recvWindow: number = 0,
): Promise<{ ): Promise<{
expiresAt: number; expiresAt: number;
signature: string; signature: string;
}> { }> {
if (!apiKey || !apiSecret || !apiPass) { if (!apiKey || !apiSecret || !apiPass) {
throw new Error( throw new Error(
`Cannot auth - missing api key, secret or passcode in config` `Cannot auth - missing api key, secret or passcode in config`,
); );
} }
const signatureExpiresAt = ((Date.now() + recvWindow) / 1000).toFixed(0); const signatureExpiresAt = ((Date.now() + recvWindow) / 1000).toFixed(0);
@@ -125,7 +125,7 @@ export async function getWsAuthSignature(
const signature = await signMessage( const signature = await signMessage(
signatureExpiresAt + 'GET' + '/user/verify', signatureExpiresAt + 'GET' + '/user/verify',
apiSecret, apiSecret,
'base64' 'base64',
); );
return { return {

View File

@@ -27,7 +27,7 @@ describe('Private Broker REST API GET Endpoints', () => {
it('getBrokerInfo()', async () => { it('getBrokerInfo()', async () => {
try { try {
expect(await api.getBrokerInfo()).toMatchObject( expect(await api.getBrokerInfo()).toMatchObject(
sucessEmptyResponseObject() sucessEmptyResponseObject(),
); );
} catch (e) { } catch (e) {
expect(e.body).toMatchObject({ expect(e.body).toMatchObject({
@@ -39,7 +39,7 @@ describe('Private Broker REST API GET Endpoints', () => {
it('getSubAccounts()', async () => { it('getSubAccounts()', async () => {
try { try {
expect(await api.getSubAccounts()).toMatchObject( expect(await api.getSubAccounts()).toMatchObject(
sucessEmptyResponseObject() sucessEmptyResponseObject(),
); );
} catch (e) { } catch (e) {
expect(e.body).toMatchObject({ expect(e.body).toMatchObject({
@@ -51,7 +51,7 @@ describe('Private Broker REST API GET Endpoints', () => {
it('getSubEmail()', async () => { it('getSubEmail()', async () => {
try { try {
expect(await api.getSubEmail(subUid)).toMatchObject( expect(await api.getSubEmail(subUid)).toMatchObject(
sucessEmptyResponseObject() sucessEmptyResponseObject(),
); );
} catch (e) { } catch (e) {
expect(e.body).toMatchObject({ expect(e.body).toMatchObject({
@@ -63,7 +63,7 @@ describe('Private Broker REST API GET Endpoints', () => {
it('getSubSpotAssets()', async () => { it('getSubSpotAssets()', async () => {
try { try {
expect(await api.getSubSpotAssets(subUid)).toMatchObject( expect(await api.getSubSpotAssets(subUid)).toMatchObject(
sucessEmptyResponseObject() sucessEmptyResponseObject(),
); );
} catch (e) { } catch (e) {
// expect(e.body).toBeNull(); // expect(e.body).toBeNull();
@@ -76,7 +76,7 @@ describe('Private Broker REST API GET Endpoints', () => {
it('getSubFutureAssets()', async () => { it('getSubFutureAssets()', async () => {
try { try {
expect(await api.getSubFutureAssets(subUid, 'usdt')).toMatchObject( expect(await api.getSubFutureAssets(subUid, 'usdt')).toMatchObject(
sucessEmptyResponseObject() sucessEmptyResponseObject(),
); );
} catch (e) { } catch (e) {
expect(e.body).toMatchObject({ expect(e.body).toMatchObject({
@@ -88,7 +88,7 @@ describe('Private Broker REST API GET Endpoints', () => {
it('getSubDepositAddress()', async () => { it('getSubDepositAddress()', async () => {
try { try {
expect(await api.getSubDepositAddress(subUid, coin)).toMatchObject( expect(await api.getSubDepositAddress(subUid, coin)).toMatchObject(
sucessEmptyResponseObject() sucessEmptyResponseObject(),
); );
} catch (e) { } catch (e) {
expect(e.body).toMatchObject({ expect(e.body).toMatchObject({
@@ -100,7 +100,7 @@ describe('Private Broker REST API GET Endpoints', () => {
it('getSubAPIKeys()', async () => { it('getSubAPIKeys()', async () => {
try { try {
expect(await api.getSubAPIKeys(subUid)).toMatchObject( expect(await api.getSubAPIKeys(subUid)).toMatchObject(
sucessEmptyResponseObject() sucessEmptyResponseObject(),
); );
} catch (e) { } catch (e) {
expect(e.body).toMatchObject({ expect(e.body).toMatchObject({

View File

@@ -27,7 +27,7 @@ describe('Private Broker REST API POST Endpoints', () => {
it('createSubAccount()', async () => { it('createSubAccount()', async () => {
try { try {
expect(await api.createSubAccount('test1')).toMatchObject( expect(await api.createSubAccount('test1')).toMatchObject(
sucessEmptyResponseObject() sucessEmptyResponseObject(),
); );
} catch (e) { } catch (e) {
expect(e.body).toMatchObject({ expect(e.body).toMatchObject({
@@ -39,7 +39,7 @@ describe('Private Broker REST API POST Endpoints', () => {
it('modifySubAccount()', async () => { it('modifySubAccount()', async () => {
try { try {
expect( expect(
await api.modifySubAccount('test1', 'spot_trade,transfer', 'normal') await api.modifySubAccount('test1', 'spot_trade,transfer', 'normal'),
).toMatchObject(sucessEmptyResponseObject()); ).toMatchObject(sucessEmptyResponseObject());
} catch (e) { } catch (e) {
expect(e.body).toMatchObject({ expect(e.body).toMatchObject({
@@ -51,7 +51,7 @@ describe('Private Broker REST API POST Endpoints', () => {
it('modifySubEmail()', async () => { it('modifySubEmail()', async () => {
try { try {
expect( expect(
await api.modifySubEmail('test1', 'ASDFASDF@LKMASDF.COM') await api.modifySubEmail('test1', 'ASDFASDF@LKMASDF.COM'),
).toMatchObject(sucessEmptyResponseObject()); ).toMatchObject(sucessEmptyResponseObject());
} catch (e) { } catch (e) {
expect(e.body).toMatchObject({ expect(e.body).toMatchObject({
@@ -69,7 +69,7 @@ describe('Private Broker REST API POST Endpoints', () => {
chain: 'TRC20', chain: 'TRC20',
coin: 'USDT', coin: 'USDT',
subUid, subUid,
}) }),
).toMatchObject(sucessEmptyResponseObject()); ).toMatchObject(sucessEmptyResponseObject());
} catch (e) { } catch (e) {
expect(e.body).toMatchObject({ expect(e.body).toMatchObject({
@@ -81,7 +81,7 @@ describe('Private Broker REST API POST Endpoints', () => {
it('setSubDepositAutoTransfer()', async () => { it('setSubDepositAutoTransfer()', async () => {
try { try {
expect( expect(
await api.setSubDepositAutoTransfer(subUid, 'USDT', 'spot') await api.setSubDepositAutoTransfer(subUid, 'USDT', 'spot'),
).toMatchObject(sucessEmptyResponseObject()); ).toMatchObject(sucessEmptyResponseObject());
} catch (e) { } catch (e) {
expect(e.body).toMatchObject({ expect(e.body).toMatchObject({
@@ -97,8 +97,8 @@ describe('Private Broker REST API POST Endpoints', () => {
subUid, subUid,
'passphrase12345', 'passphrase12345',
'remark', 'remark',
'10.0.0.1' '10.0.0.1',
) ),
).toMatchObject(sucessEmptyResponseObject()); ).toMatchObject(sucessEmptyResponseObject());
} catch (e) { } catch (e) {
expect(e.body).toMatchObject({ expect(e.body).toMatchObject({
@@ -114,7 +114,7 @@ describe('Private Broker REST API POST Endpoints', () => {
apikey: '12345', apikey: '12345',
subUid, subUid,
remark: 'test', remark: 'test',
}) }),
).toMatchObject(sucessEmptyResponseObject()); ).toMatchObject(sucessEmptyResponseObject());
} catch (e) { } catch (e) {
expect(e.body).toMatchObject({ expect(e.body).toMatchObject({

View File

@@ -57,7 +57,7 @@ describe('Private Futures REST API GET Endpoints', () => {
it('getOpenCount()', async () => { it('getOpenCount()', async () => {
try { try {
expect( expect(
await api.getOpenCount(symbol, marginCoin, 20000, 1) await api.getOpenCount(symbol, marginCoin, 20000, 1),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: { data: {
@@ -102,7 +102,7 @@ describe('Private Futures REST API GET Endpoints', () => {
endTime: to, endTime: to,
marginCoin, marginCoin,
symbol, symbol,
}) }),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: { data: {
@@ -125,7 +125,7 @@ describe('Private Futures REST API GET Endpoints', () => {
startTime: from, startTime: from,
endTime: to, endTime: to,
productType: 'umcbl', productType: 'umcbl',
}) }),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: { data: {
@@ -180,7 +180,7 @@ describe('Private Futures REST API GET Endpoints', () => {
it('getProductTypeOrderHistory()', async () => { it('getProductTypeOrderHistory()', async () => {
try { try {
expect( expect(
await api.getProductTypeOrderHistory('umcbl', from, to, '10') await api.getProductTypeOrderHistory('umcbl', from, to, '10'),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: expect.any(Object), data: expect.any(Object),
@@ -223,7 +223,7 @@ describe('Private Futures REST API GET Endpoints', () => {
await api.getProductTypeOrderFills('umcbl', { await api.getProductTypeOrderFills('umcbl', {
startTime: from, startTime: from,
endTime: to, endTime: to,
}) }),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: expect.any(Object), data: expect.any(Object),
@@ -253,7 +253,7 @@ describe('Private Futures REST API GET Endpoints', () => {
startTime: from, startTime: from,
endTime: to, endTime: to,
symbol, symbol,
}) }),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: expect.any(Object), data: expect.any(Object),
@@ -267,7 +267,7 @@ describe('Private Futures REST API GET Endpoints', () => {
it('getCopyTraderOpenOrder()', async () => { it('getCopyTraderOpenOrder()', async () => {
try { try {
expect( expect(
await api.getCopyTraderOpenOrder(symbol, 'umcbl', 1, 0) await api.getCopyTraderOpenOrder(symbol, 'umcbl', 1, 0),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: expect.any(Object), data: expect.any(Object),
@@ -282,7 +282,7 @@ describe('Private Futures REST API GET Endpoints', () => {
it('getCopyFollowersOpenOrder()', async () => { it('getCopyFollowersOpenOrder()', async () => {
try { try {
expect( expect(
await api.getCopyFollowersOpenOrder(symbol, 'umcbl', 1, 0) await api.getCopyFollowersOpenOrder(symbol, 'umcbl', 1, 0),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: expect.any(Object), data: expect.any(Object),
@@ -300,7 +300,7 @@ describe('Private Futures REST API GET Endpoints', () => {
{ {
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: expect.any(Object), data: expect.any(Object),
} },
); );
} catch (e) { } catch (e) {
expect(e.body).toMatchObject({ expect(e.body).toMatchObject({
@@ -342,8 +342,8 @@ describe('Private Futures REST API GET Endpoints', () => {
marginCoin, marginCoin,
from, from,
1, 1,
1 1,
) ),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: expect.any(Object), data: expect.any(Object),
@@ -358,7 +358,7 @@ describe('Private Futures REST API GET Endpoints', () => {
it('getCopyTraderHistoricProfitDetail()', async () => { it('getCopyTraderHistoricProfitDetail()', async () => {
try { try {
expect( expect(
await api.getCopyTraderHistoricProfitDetail(marginCoin, from, 1, 1) await api.getCopyTraderHistoricProfitDetail(marginCoin, from, 1, 1),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: expect.any(Object), data: expect.any(Object),

View File

@@ -53,7 +53,7 @@ describe('Private Futures REST API POST Endpoints', () => {
it('setMarginMode()', async () => { it('setMarginMode()', async () => {
try { try {
expect( expect(
await api.setMarginMode(symbol, marginCoin, 'crossed') await api.setMarginMode(symbol, marginCoin, 'crossed'),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: {}, data: {},
@@ -76,7 +76,7 @@ describe('Private Futures REST API POST Endpoints', () => {
symbol, symbol,
size: '1', size: '1',
side: 'open_long', side: 'open_long',
}) }),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: {}, data: {},
@@ -100,7 +100,7 @@ describe('Private Futures REST API POST Endpoints', () => {
size: '1', size: '1',
side: 'open_long', side: 'open_long',
}, },
]) ]),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: {}, data: {},
@@ -115,7 +115,7 @@ describe('Private Futures REST API POST Endpoints', () => {
it('cancelOrder()', async () => { it('cancelOrder()', async () => {
try { try {
expect( expect(
await api.cancelOrder(symbol, marginCoin, '1234656') await api.cancelOrder(symbol, marginCoin, '1234656'),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: {}, data: {},
@@ -130,7 +130,7 @@ describe('Private Futures REST API POST Endpoints', () => {
it('batchCancelOrder()', async () => { it('batchCancelOrder()', async () => {
try { try {
expect( expect(
await api.batchCancelOrder(symbol, marginCoin, ['1234656']) await api.batchCancelOrder(symbol, marginCoin, ['1234656']),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: {}, data: {},
@@ -164,7 +164,7 @@ describe('Private Futures REST API POST Endpoints', () => {
symbol, symbol,
triggerPrice: '1000', triggerPrice: '1000',
triggerType: 'market_price', triggerType: 'market_price',
}) }),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: {}, data: {},
@@ -187,7 +187,7 @@ describe('Private Futures REST API POST Endpoints', () => {
symbol, symbol,
triggerPrice: '100', triggerPrice: '100',
triggerType: 'market_price', triggerType: 'market_price',
}) }),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: {}, data: {},
@@ -207,7 +207,7 @@ describe('Private Futures REST API POST Endpoints', () => {
marginCoin, marginCoin,
symbol, symbol,
presetTakeProfitPrice: '100', presetTakeProfitPrice: '100',
}) }),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: {}, data: {},
@@ -229,7 +229,7 @@ describe('Private Futures REST API POST Endpoints', () => {
planType: 'profit_plan', planType: 'profit_plan',
holdSide: 'long', holdSide: 'long',
triggerPrice: '100', triggerPrice: '100',
}) }),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: {}, data: {},
@@ -251,7 +251,7 @@ describe('Private Futures REST API POST Endpoints', () => {
holdSide: 'long', holdSide: 'long',
planType: 'profit_plan', planType: 'profit_plan',
triggerPrice: '50', triggerPrice: '50',
}) }),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: {}, data: {},
@@ -270,7 +270,8 @@ describe('Private Futures REST API POST Endpoints', () => {
marginCoin, marginCoin,
symbol, symbol,
orderId: '123456', orderId: '123456',
}) planType: 'profit_plan',
}),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: {}, data: {},
@@ -292,7 +293,7 @@ describe('Private Futures REST API POST Endpoints', () => {
symbol, symbol,
orderId: '123456', orderId: '123456',
planType: 'profit_plan', planType: 'profit_plan',
}) }),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: {}, data: {},
@@ -310,7 +311,7 @@ describe('Private Futures REST API POST Endpoints', () => {
{ {
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: {}, data: {},
} },
); );
} catch (e) { } catch (e) {
expect(e.body).toMatchObject({ expect(e.body).toMatchObject({
@@ -324,7 +325,7 @@ describe('Private Futures REST API POST Endpoints', () => {
expect( expect(
await api.modifyCopyTraderTPSL(symbol, '123456', { await api.modifyCopyTraderTPSL(symbol, '123456', {
stopLossPrice: 1234, stopLossPrice: 1234,
}) }),
).toMatchObject({ ).toMatchObject({
...sucessEmptyResponseObject(), ...sucessEmptyResponseObject(),
data: {}, data: {},

View File

@@ -70,7 +70,7 @@ describe('Public Spot REST API Endpoints', () => {
it('getCandles()', async () => { it('getCandles()', async () => {
expect( expect(
await api.getCandles(symbol, '1min', `${from}`, `${to}`) await api.getCandles(symbol, '1min', `${from}`, `${to}`),
).toMatchObject(expect.any(Array)); ).toMatchObject(expect.any(Array));
}); });

View File

@@ -19,7 +19,7 @@ export function sucessEmptyResponseObject() {
export function errorResponseObject( export function errorResponseObject(
result: null | any = null, result: null | any = null,
ret_code: number, ret_code: number,
ret_msg: string ret_msg: string,
) { ) {
return { return {
result, result,
@@ -30,7 +30,7 @@ export function errorResponseObject(
export function errorResponseObjectV3( export function errorResponseObjectV3(
result: null | any = null, result: null | any = null,
retCode: number retCode: number,
) { ) {
return { return {
result, result,

View File

@@ -26,7 +26,7 @@ describe('Private Spot Websocket Client', () => {
apiSecret: 'bad', apiSecret: 'bad',
apiPass: 'bad', apiPass: 'bad',
}, },
getSilentLogger('expect401') getSilentLogger('expect401'),
); );
// const wsOpenPromise = waitForSocketEvent(badClient, 'open'); // const wsOpenPromise = waitForSocketEvent(badClient, 'open');
@@ -62,7 +62,7 @@ describe('Private Spot Websocket Client', () => {
beforeAll(() => { beforeAll(() => {
wsClient = new WebsocketClient( wsClient = new WebsocketClient(
wsClientOptions, wsClientOptions,
getSilentLogger('expectSuccess') getSilentLogger('expectSuccess'),
); );
wsClient.connectAll(); wsClient.connectAll();
// logAllEvents(wsClient); // logAllEvents(wsClient);

View File

@@ -13,7 +13,7 @@ describe('Public Spot Websocket Client', () => {
beforeAll(() => { beforeAll(() => {
wsClient = new WebsocketClient( wsClient = new WebsocketClient(
wsClientOptions, wsClientOptions,
getSilentLogger('expectSuccess') getSilentLogger('expectSuccess'),
); );
wsClient.connectAll(); wsClient.connectAll();
logAllEvents(wsClient); logAllEvents(wsClient);

View File

@@ -24,12 +24,12 @@ export const fullLogger = {
export function waitForSocketEvent( export function waitForSocketEvent(
wsClient: WebsocketClient, wsClient: WebsocketClient,
event: WsClientEvent, event: WsClientEvent,
timeoutMs: number = 4.5 * 1000 timeoutMs: number = 4.5 * 1000,
) { ) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
reject( reject(
`Failed to receive "${event}" event before timeout. Check that these are correct: topic, api keys (if private), signature process (if private)` `Failed to receive "${event}" event before timeout. Check that these are correct: topic, api keys (if private), signature process (if private)`,
); );
}, timeoutMs); }, timeoutMs);