Skip to content

Commit

Permalink
fix(vendor-ccxt): await symbol loading & fix funding rate
Browse files Browse the repository at this point in the history
  • Loading branch information
Thrimbda committed Feb 23, 2024
1 parent 9102cdb commit 917d85b
Show file tree
Hide file tree
Showing 4 changed files with 327 additions and 155 deletions.
37 changes: 37 additions & 0 deletions apps/vendor-ccxt/etc/vendor-ccxt.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,43 @@
```ts

import { Exchange } from 'ccxt';
import { FundingRate } from 'ccxt/js/src/base/types';
import { IPeriod } from '@yuants/data-model';
import { IProduct } from '@yuants/data-model';
import { ITick } from '@yuants/data-model';
import { Observable } from 'rxjs';

// Warning: (ae-internal-missing-underscore) The name "makeProducts$" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
export const makeProducts$: (ex: Exchange) => Observable<IProduct[]>;

// Warning: (ae-internal-missing-underscore) The name "makeUseFundingRate" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
export const makeUseFundingRate: (ex: Exchange) => (symbol: string) => Observable<FundingRate>;

// Warning: (ae-internal-missing-underscore) The name "mapProductIdToSymbol" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
export const mapProductIdToSymbol: Record<string, string>;

// Warning: (ae-internal-missing-underscore) The name "mapSymbolToProductId" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
export const mapSymbolToProductId: Record<string, string>;

// Warning: (ae-internal-missing-underscore) The name "subscribePeriods" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
export const subscribePeriods: (ex: Exchange) => (product_id: string, period_in_sec: number) => Observable<IPeriod[]>;

// Warning: (ae-internal-missing-underscore) The name "subscribeTick" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
export const subscribeTick: (ex: Exchange, useFundingRate: (symbol: string) => Observable<FundingRate>) => (product_id: string) => Observable<ITick>;

// (No @packageDocumentation comment for this package)

```
68 changes: 68 additions & 0 deletions apps/vendor-ccxt/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import ccxt from 'ccxt';
import { makeProducts$, makeUseFundingRate, mapProductIdToSymbol, subscribeTick } from '.';
import { take, tap, timeout } from 'rxjs';

const SMOKE_TEST = process.env.SMOKE_TEST === 'true';

jest.setTimeout(15_000);
describe('ccxt functional tests', () => {
const exchanges = ['binance', 'okx', 'gate'];
const testSymbolForExchange: Record<string, string> = {
binance: 'BTCUSDT',
okx: 'BTC-USDT-SWAP',
gate: 'BTC_USDT',
};
for (const exchangeName of exchanges) {
//@ts-ignore
const exchange = new ccxt[exchangeName]();
// it(`should get products from ${exchangeName}`, (done) => {
// makeProducts$(exchange)
// .pipe(timeout({ each: 15_000, meta: `makeProducts$ from ${exchangeName}` }))
// .subscribe({
// next: (products) => {
// expect(products).toBeDefined();
// expect(products.length).toBeGreaterThan(0);
// },
// error: (error) => {
// done(error);
// },
// complete: () => {
// done();
// },
// });
// });

it(`should subscribe ticker from ${exchangeName}`, (done) => {
if (!SMOKE_TEST) {
done();
return;
}

const useFundingRate = makeUseFundingRate(exchange);
mapProductIdToSymbol[testSymbolForExchange[exchangeName]] = 'BTC/USDT:USDT';
subscribeTick(
exchange,
useFundingRate,
)(testSymbolForExchange[exchangeName])
.pipe(
//
take(1),
tap((tick): any => {
console.info('tick', tick);
}),
timeout({ each: 5_000, meta: `subscribeTick from ${exchangeName}` }),
)
.subscribe({
next: (tick) => {
expect(tick).toBeDefined();
},
error: (error) => {
done(error);
},
complete: () => {
done();
},
});
});
}
});
Loading

0 comments on commit 917d85b

Please sign in to comment.