add account asset & USDC options clients

This commit is contained in:
tiagosiebler
2022-09-08 13:39:07 +01:00
parent ed373f380f
commit 63201b465c
19 changed files with 1009 additions and 80 deletions

View File

@@ -0,0 +1,67 @@
import { AccountAssetClient } from '../../src/';
import { successResponseObject } from '../response.util';
describe('Private Account Asset REST API Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_COM;
it('should have api credentials to test with', () => {
expect(API_KEY).toStrictEqual(expect.any(String));
expect(API_SECRET).toStrictEqual(expect.any(String));
});
const api = new AccountAssetClient(API_KEY, API_SECRET, useLivenet);
it('getInternalTransfers()', async () => {
expect(await api.getInternalTransfers()).toMatchObject(
successResponseObject()
);
});
it('getSubAccountTransfers()', async () => {
expect(await api.getSubAccountTransfers()).toMatchObject(
successResponseObject()
);
});
it('getSubAccounts()', async () => {
expect(await api.getSubAccounts()).toMatchObject(successResponseObject());
});
it('getUniversalTransfers()', async () => {
expect(await api.getInternalTransfers()).toMatchObject(
successResponseObject()
);
});
it('getDepositRecords()', async () => {
expect(await api.getDepositRecords()).toMatchObject(
successResponseObject()
);
});
it('getWithdrawRecords()', async () => {
expect(await api.getWithdrawRecords()).toMatchObject(
successResponseObject()
);
});
it('getCoinInformation()', async () => {
expect(await api.getCoinInformation()).toMatchObject(
successResponseObject()
);
});
it('getAssetInformation()', async () => {
expect(await api.getAssetInformation()).toMatchObject(
successResponseObject()
);
});
it('getDepositAddress()', async () => {
expect(await api.getDepositAddress('BTC')).toMatchObject(
successResponseObject()
);
});
});

View File

@@ -0,0 +1,20 @@
import { AccountAssetClient } from '../../src';
import { successResponseObject } from '../response.util';
describe('Public Account Asset REST API Endpoints', () => {
const useLivenet = true;
const API_KEY = undefined;
const API_SECRET = undefined;
const api = new AccountAssetClient(API_KEY, API_SECRET, useLivenet);
it('getSupportedDepositList()', async () => {
expect(await api.getSupportedDepositList()).toMatchObject(
successResponseObject()
);
});
it('getServerTime()', async () => {
expect(await api.getServerTime()).toMatchObject(successResponseObject());
});
});

View File

@@ -30,7 +30,6 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => {
})
).toMatchObject({
ret_code: API_ERROR_CODE.POSITION_IDX_NOT_MATCH_POSITION_MODE,
ret_msg: 'position idx not match position mode',
});
});
@@ -41,7 +40,6 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => {
})
).toMatchObject({
ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE,
ret_msg: 'order not exists or too late to cancel',
});
});
@@ -63,7 +61,6 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => {
})
).toMatchObject({
ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE,
ret_msg: 'order not exists or too late to replace',
});
});
@@ -82,7 +79,6 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => {
})
).toMatchObject({
ret_code: API_ERROR_CODE.POSITION_IDX_NOT_MATCH_POSITION_MODE,
ret_msg: 'position idx not match position mode',
});
});
@@ -94,7 +90,6 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => {
})
).toMatchObject({
ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE,
ret_msg: 'Order not exists',
});
});
@@ -115,7 +110,6 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => {
})
).toMatchObject({
ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE,
ret_msg: 'order not exists or too late to replace',
});
});
@@ -127,7 +121,6 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => {
})
).toMatchObject({
ret_code: API_ERROR_CODE.POSITION_IDX_NOT_MATCH_POSITION_MODE,
ret_msg: 'position idx not match position mode',
});
});
@@ -139,7 +132,6 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => {
})
).toMatchObject({
ret_code: API_ERROR_CODE.POSITION_IDX_NOT_MATCH_POSITION_MODE,
ret_msg: 'position idx not match position mode',
});
});
@@ -152,7 +144,6 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => {
})
).toMatchObject({
ret_code: API_ERROR_CODE.LEVERAGE_NOT_MODIFIED,
ret_msg: 'leverage not modified',
});
});
@@ -164,7 +155,6 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => {
})
).toMatchObject({
ret_code: API_ERROR_CODE.POSITION_MODE_NOT_MODIFIED,
ret_msg: 'position mode not modified',
});
});
@@ -178,7 +168,6 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => {
})
).toMatchObject({
ret_code: API_ERROR_CODE.ISOLATED_NOT_MODIFIED,
ret_msg: 'Isolated not modified',
});
});
});

View File

@@ -1,4 +1,4 @@
import { InverseClient } from '../../src/inverse-client';
import { InverseClient } from '../../src/';
import { successResponseList, successResponseObject } from '../response.util';
describe('Private Inverse REST API Endpoints', () => {

View File

@@ -40,7 +40,6 @@ describe('Private Inverse REST API Endpoints', () => {
})
).toMatchObject({
ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE,
ret_msg: 'order not exists or too late to cancel',
});
});
@@ -62,7 +61,6 @@ describe('Private Inverse REST API Endpoints', () => {
})
).toMatchObject({
ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE,
ret_msg: 'order not exists or too late to replace',
});
});
@@ -81,7 +79,6 @@ describe('Private Inverse REST API Endpoints', () => {
})
).toMatchObject({
ret_code: API_ERROR_CODE.INSUFFICIENT_BALANCE,
ret_msg: 'Insufficient wallet balance',
});
});
@@ -93,7 +90,6 @@ describe('Private Inverse REST API Endpoints', () => {
})
).toMatchObject({
ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE,
ret_msg: expect.any(String),
});
});
@@ -114,7 +110,6 @@ describe('Private Inverse REST API Endpoints', () => {
})
).toMatchObject({
ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE,
ret_msg: 'order not exists or too late to replace',
});
});
@@ -126,7 +121,6 @@ describe('Private Inverse REST API Endpoints', () => {
})
).toMatchObject({
ret_code: API_ERROR_CODE.POSITION_IS_CROSS_MARGIN,
ret_msg: expect.any(String),
});
});
@@ -138,7 +132,6 @@ describe('Private Inverse REST API Endpoints', () => {
})
).toMatchObject({
ret_code: API_ERROR_CODE.CANNOT_SET_TRADING_STOP_FOR_ZERO_POS,
ret_msg: 'can not set tp/sl/ts for zero position',
});
});
@@ -162,7 +155,6 @@ describe('Private Inverse REST API Endpoints', () => {
})
).toMatchObject({
ret_code: API_ERROR_CODE.SAME_SLTP_MODE,
ret_msg: 'same tp sl mode2',
});
});

View File

@@ -14,6 +14,14 @@ export function successResponseObject(successMsg: string | null = 'OK') {
};
}
export function successUSDCResponseObject() {
return {
result: expect.any(Object),
retCode: 0,
retMsg: expect.stringMatching(/OK|SUCCESS|success|success\./gim),
};
}
export function errorResponseObject(
result: null | any = null,
ret_code: number,

View File

@@ -0,0 +1,82 @@
import { USDCOptionsClient } from '../../../src';
import {
successResponseObject,
successUSDCResponseObject,
} from '../../response.util';
describe('Private Account Asset REST API Endpoints', () => {
const useLivenet = true;
const API_KEY = process.env.API_KEY_COM;
const API_SECRET = process.env.API_SECRET_COM;
const symbol = 'BTC-30SEP22-400000-C';
it('should have api credentials to test with', () => {
expect(API_KEY).toStrictEqual(expect.any(String));
expect(API_SECRET).toStrictEqual(expect.any(String));
});
const api = new USDCOptionsClient(API_KEY, API_SECRET, useLivenet);
const category = 'OPTION';
it('getActiveRealtimeOrders()', async () => {
expect(await api.getActiveRealtimeOrders()).toMatchObject(
successUSDCResponseObject()
);
});
it('getActiveOrders()', async () => {
expect(await api.getActiveOrders({ category })).toMatchObject(
successUSDCResponseObject()
);
});
it('getHistoricOrders()', async () => {
expect(await api.getHistoricOrders({ category })).toMatchObject(
successUSDCResponseObject()
);
});
it('getOrderExecutionHistory()', async () => {
expect(await api.getOrderExecutionHistory({ category })).toMatchObject(
successUSDCResponseObject()
);
});
it('getTransactionLog()', async () => {
expect(await api.getTransactionLog({ type: 'TRADE' })).toMatchObject(
successUSDCResponseObject()
);
});
it('getBalance()', async () => {
expect(await api.getBalance()).toMatchObject(successUSDCResponseObject());
});
it('getAssetInfo()', async () => {
expect(await api.getAssetInfo()).toMatchObject(successUSDCResponseObject());
});
it('getMarginMode()', async () => {
expect(await api.getMarginMode()).toMatchObject(
successUSDCResponseObject()
);
});
it('getPositions()', async () => {
expect(await api.getPositions({ category })).toMatchObject(
successUSDCResponseObject()
);
});
it('getDeliveryHistory()', async () => {
expect(await api.getDeliveryHistory({ symbol })).toMatchObject(
successUSDCResponseObject()
);
});
it('getPositionsInfoUponExpiry()', async () => {
expect(await api.getPositionsInfoUponExpiry()).toMatchObject(
successUSDCResponseObject()
);
});
});

View File

@@ -0,0 +1,54 @@
import { USDCOptionsClient } from '../../../src';
import {
successResponseObject,
successUSDCResponseObject,
} from '../../response.util';
describe('Public USDC Options REST API Endpoints', () => {
const useLivenet = true;
const API_KEY = undefined;
const API_SECRET = undefined;
const api = new USDCOptionsClient(API_KEY, API_SECRET, useLivenet);
const symbol = 'BTC-30SEP22-400000-C';
it('getOrderBook()', async () => {
expect(await api.getOrderBook(symbol)).toMatchObject(
successUSDCResponseObject()
);
});
it('getContractInfo()', async () => {
expect(await api.getContractInfo()).toMatchObject(
successUSDCResponseObject()
);
});
it('getSymbolTicker()', async () => {
expect(await api.getSymbolTicker(symbol)).toMatchObject(
successUSDCResponseObject()
);
});
it('getDeliveryPrice()', async () => {
expect(await api.getDeliveryPrice()).toMatchObject(
successUSDCResponseObject()
);
});
it('getLastTrades()', async () => {
expect(await api.getLastTrades({ category: 'OPTION' })).toMatchObject(
successUSDCResponseObject()
);
});
it('getHistoricalVolatility()', async () => {
expect(await api.getHistoricalVolatility()).toMatchObject(
successUSDCResponseObject()
);
});
it('getServerTime()', async () => {
expect(await api.getServerTime()).toMatchObject(successResponseObject());
});
});