add USDC perp client with tests

This commit is contained in:
tiagosiebler
2022-09-08 16:48:33 +01:00
parent 666720b27d
commit 5187350878
13 changed files with 583 additions and 37 deletions

View File

@@ -19,9 +19,15 @@ export function successResponseObject(successMsg: string | null = 'OK') {
export function successUSDCResponseObject() {
return {
result: expect.any(Object),
...successUSDCEmptyResponseObject(),
};
}
export function successUSDCEmptyResponseObject() {
return {
retCode: API_ERROR_CODE.SUCCESS,
retMsg: expect.stringMatching(
/OK|SUCCESS|success|success\.|Request accepted/gim
/OK|SUCCESS|success|success\.|Request accepted|/gim
),
};
}

View File

@@ -1,8 +1,5 @@
import { API_ERROR_CODE, USDCOptionsClient } from '../../../src';
import {
successResponseObject,
successUSDCResponseObject,
} from '../../response.util';
import { successUSDCResponseObject } from '../../response.util';
describe('Private Account Asset REST API Endpoints', () => {
const useLivenet = true;
@@ -16,7 +13,6 @@ describe('Private Account Asset REST API Endpoints', () => {
const api = new USDCOptionsClient(API_KEY, API_SECRET, useLivenet);
const category = 'OPTION';
const currency = 'USDC';
const symbol = 'BTC-30SEP22-400000-C';
@@ -159,11 +155,4 @@ describe('Private Account Asset REST API Endpoints', () => {
retCode: API_ERROR_CODE.INSTITION_MMP_PROFILE_NOT_FOUND,
});
});
/**
it('asdfasfasdfasdf()', async () => {
expect(await api.asadfasdfasdfasf()).toStrictEqual('');
});
*/
});

View File

@@ -0,0 +1,74 @@
import { USDCPerpetualClient } from '../../../src';
import { 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;
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 USDCPerpetualClient(API_KEY, API_SECRET, useLivenet);
const symbol = 'BTCPERP';
const category = 'PERPETUAL';
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('getSettlementHistory()', async () => {
expect(await api.getSettlementHistory({ symbol })).toMatchObject(
successUSDCResponseObject()
);
});
it('getPredictedFundingRate()', async () => {
expect(await api.getPredictedFundingRate(symbol)).toMatchObject(
successUSDCResponseObject()
);
});
});

View File

@@ -0,0 +1,85 @@
import { API_ERROR_CODE, USDCPerpetualClient } from '../../../src';
import {
successUSDCEmptyResponseObject,
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;
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 USDCPerpetualClient(API_KEY, API_SECRET, useLivenet);
const symbol = 'BTCPERP';
it('submitOrder()', async () => {
expect(
await api.submitOrder({
symbol,
side: 'Sell',
orderType: 'Limit',
orderFilter: 'Order',
orderQty: '1',
orderPrice: '20000',
orderLinkId: Date.now().toString(),
timeInForce: 'GoodTillCancel',
})
).toMatchObject({
retCode: API_ERROR_CODE.INSUFFICIENT_BALANCE_FOR_ORDER_COST,
});
});
it('modifyOrder()', async () => {
expect(
await api.modifyOrder({
symbol,
orderId: 'somethingFake',
orderPrice: '20000',
})
).toMatchObject({
retCode: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE,
});
});
it('cancelOrder()', async () => {
expect(
await api.cancelOrder({
symbol,
orderId: 'somethingFake1',
orderFilter: 'Order',
})
).toMatchObject({
retCode: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE,
});
});
it('cancelActiveOrders()', async () => {
expect(await api.cancelActiveOrders(symbol, 'Order')).toMatchObject(
successUSDCEmptyResponseObject()
);
});
it('setMarginMode()', async () => {
expect(await api.setMarginMode('REGULAR_MARGIN')).toMatchObject(
successUSDCResponseObject()
);
});
it('setLeverage()', async () => {
expect(await api.setLeverage(symbol, '10')).toMatchObject({
retCode: API_ERROR_CODE.LEVERAGE_NOT_MODIFIED,
});
});
it('setRiskLimit()', async () => {
expect(await api.setRiskLimit(symbol, 1)).toMatchObject({
retCode: API_ERROR_CODE.RISK_LIMIT_NOT_EXISTS,
});
});
});

View File

@@ -0,0 +1,95 @@
import { USDCKlineRequest, USDCPerpetualClient } 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 USDCPerpetualClient(API_KEY, API_SECRET, useLivenet);
const symbol = 'BTCPERP';
const category = 'PERPETUAL';
const startTime = Number((Date.now() / 1000).toFixed(0));
const candleRequest: USDCKlineRequest = { symbol, period: '1m', startTime };
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('getKline()', async () => {
expect(await api.getKline(candleRequest)).toMatchObject(
successUSDCResponseObject()
);
});
it('getMarkPrice()', async () => {
expect(await api.getMarkPrice(candleRequest)).toMatchObject(
successUSDCResponseObject()
);
});
it('getIndexPrice()', async () => {
expect(await api.getIndexPrice(candleRequest)).toMatchObject(
successUSDCResponseObject()
);
});
it('getIndexPremium()', async () => {
expect(await api.getIndexPremium(candleRequest)).toMatchObject(
successUSDCResponseObject()
);
});
it('getOpenInterest()', async () => {
expect(await api.getOpenInterest({ symbol, period: '1m' })).toMatchObject(
successUSDCResponseObject()
);
});
it('getLargeOrders()', async () => {
expect(await api.getLargeOrders({ symbol })).toMatchObject(
successUSDCResponseObject()
);
});
it('getLongShortRatio()', async () => {
expect(await api.getLongShortRatio({ symbol, period: '1m' })).toMatchObject(
successUSDCResponseObject()
);
});
it('getLast500Trades()', async () => {
expect(await api.getLast500Trades({ category })).toMatchObject(
successUSDCResponseObject()
);
});
it('getLastFundingRate()', async () => {
expect(await api.getLastFundingRate(symbol)).toMatchObject(
successUSDCResponseObject()
);
});
it('getServerTime()', async () => {
expect(await api.getServerTime()).toMatchObject(successResponseObject());
});
});