Skip to content

Commit

Permalink
Merge pull request #33 from tiagosiebler/jerko
Browse files Browse the repository at this point in the history
feat(): tests
  • Loading branch information
JJ-Cro authored Sep 19, 2024
2 parents eac31a8 + 5d3a7dc commit caecf74
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ ts-adv-trade-test-private.ts
examples/ts-app-priv.ts
examples/ts-commerce.ts
ts-exchange-priv.ts
testfile-cbexch.ts
61 changes: 61 additions & 0 deletions examples/testfile-cbexch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* eslint-disable @typescript-eslint/no-unused-vars */

import { CBExchangeClient } from '../src/index.js';

(async () => {
//console.clear();

const credsViewPermission = {
key: '6e0a73cfd6e02701655d38a383dc5fcf',
secret:
'g1uvHV/QklP+wB+cWoGXdCOYmQ5BQ1/XYMCaLDs2rH7bZ7V07X3ECroC0Zb6H5aBSa0CkMc/WMzpz5RHvqpxFQ==',
passphrase: 'gdgjgehg3i',
};

const client = new CBExchangeClient({
apiKey: credsViewPermission.key,
apiSecret: credsViewPermission.secret,
apiPassphrase: credsViewPermission.passphrase,
useSandbox: true,
});

try {
/* const res = await client.getNewLoanPreview({
currency: 'USDC',
native_amount: '100',
});
console.log('req result: ', res); */

/* const res = await client.getProfiles({ active: true });
console.log('req result: ', res); */
/* const accounts = await client.getAccounts();
console.log('req result: ', accounts); */
const order = await client.submitOrder({
product_id: 'BTC-GBP',
price: '1000',
side: 'buy',
type: 'limit',
size: '0.001',
});

console.log('order', order);

const res = await client.getOrder({
order_id: '2e9a5d90-84f7-4267-a6e5-722b9d43e2d0',
});
console.log('order', res);
// console.log('res', res);
// const res = await client.cancelOrder({ order_id: 'dummyorder' });
// console.log('cancelOrder result: ', res);
// const orderReq: SubmitAdvTradeOrderRequest = {
// product_id: 123123,
// };
// const orderRes = await client.submitOrder({
// product_id: 12312312, // this should throw???
// });
} catch (e) {
console.error('req exception: ', JSON.stringify(e, null, 2));
}

//
})();
40 changes: 28 additions & 12 deletions test/CBExchangeClient/private.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import { CBExchangeClient } from '../../src/index.js';

describe('CBExchangeClient PRIVATE', () => {
const account = {
key: process.env.API_KEY_NAME,
secret: process.env.API_PRIVATE_KEY,
passphrase: process.env.API_PASSPHRASE,
key: process.env.API_KEY_NAME_EXCH,
secret: process.env.API_PRIVATE_KEY_EXCH,
passphrase: process.env.API_PASSPHRASE_EXCH,
};

const rest = new CBExchangeClient({
apiKey: account.key,
apiSecret: account.secret,
apiPassphrase: account.passphrase,
useSandbox: true,
});

it('should have credentials to test with', () => {
Expand All @@ -20,7 +21,7 @@ describe('CBExchangeClient PRIVATE', () => {

describe('public endpoints', () => {
it('should succeed making a GET request', async () => {
const res = await rest.getProductBook({ product_id: 'BTC-USDT' });
const res = await rest.getProductBook({ product_id: 'BTC-USD' });
//console.log(res);
expect(res).toMatchObject({
bids: expect.any(Array),
Expand All @@ -40,19 +41,34 @@ describe('CBExchangeClient PRIVATE', () => {
expect(res).toMatchObject({
taker_fee_rate: expect.any(String),
maker_fee_rate: expect.any(String),
usd_volume: expect.any(String),
usd_volume: expect.any(Object),
});
});

test('with params', async () => {
const res = await rest.getNewLoanPreview({
currency: 'USDC',
native_amount: '100',
const res = await rest.submitOrder({
product_id: 'BTC-GBP',
price: '1000',
side: 'buy',
type: 'limit',
size: '0.001',
});
//console.log('res with params', res);
console.log('res with params', res);
expect(res).toMatchObject({
overview: expect.any(Object),
loans: expect.any(Array),
id: expect.any(String),
price: expect.any(String),
size: expect.any(String),
product_id: expect.any(String),
side: expect.any(String),
type: expect.any(String),
time_in_force: expect.any(String),
post_only: expect.any(Boolean),
created_at: expect.any(String),
fill_fees: expect.any(String),
filled_size: expect.any(String),
executed_value: expect.any(String),
status: expect.any(String),
settled: expect.any(Boolean),
});
});
});
Expand All @@ -74,7 +90,7 @@ describe('CBExchangeClient PRIVATE', () => {
console.log('Error, CBExchange, post req:', e);
const responseBody = e?.body;
expect(responseBody).toMatchObject({
message: 'Unauthorized.',
message: 'Forbidden',
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion test/CBExchangeClient/public.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('CBExchangeClient PUBLIC', () => {

describe('public endpoints', () => {
it('should succeed making a GET request', async () => {
const res = await rest.getProductBook({ product_id: 'BTC-USDT' });
const res = await rest.getProductBook({ product_id: 'BTC-USD' });
//console.log(res);
expect(res).toMatchObject({
bids: expect.any(Array),
Expand Down
2 changes: 1 addition & 1 deletion test/CBInternationalClient/private.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('CBInternationalClient PRIVATE', () => {
} catch (e: any) {
// These are deliberatly restricted API keys. If the response is a permission error, it confirms the sign + request was OK and permissions were denied.
// console.log(`err "${expect.getState().currentTestName}"`, e?.body);
console.log('Error, CBINTX, post req:', e);
//console.log('Error, CBINTX, post req:', e);
const responseBody = e?.body;
expect(responseBody).toMatchObject({
title: 'Unauthorized',
Expand Down
2 changes: 1 addition & 1 deletion test/CBPrimeClient/private.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('CBPrimeClient PRIVATE', () => {
} catch (e: any) {
// These are deliberatly restricted API keys. If the response is a permission error, it confirms the sign + request was OK and permissions were denied.
// console.log(`err "${expect.getState().currentTestName}"`, e?.body);
console.log('Error, CBPrime, post req:', e);
//console.log('Error, CBPrime, post req:', e);
const responseBody = e?.body;
expect(responseBody).toMatchObject({
title: 'Unauthorized',
Expand Down

0 comments on commit caecf74

Please sign in to comment.