Skip to content

Commit

Permalink
fix(vendor-ccxt): fetchOHLCV instead of watch to avoid error (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thrimbda authored Feb 25, 2024
1 parent 455547a commit 4203785
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
58 changes: 28 additions & 30 deletions apps/vendor-ccxt/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,38 +385,36 @@ interface IGeneralSpecificRelation {
if (!symbol) {
return of([]);
}
return (
ex.has['watchOHLCV']
? defer(() => ex.watchOHLCV(symbol, timeframe)).pipe(repeat())
: defer(() => {
const since = Date.now() - 3 * period_in_sec * 1000;
return ex.fetchOHLCV(symbol, timeframe, since);
}).pipe(
//
repeat({ delay: 1000 }),
)
).pipe(
mergeMap((x) =>
from(x).pipe(
map(
([t, o, h, l, c, vol]): IPeriod => ({
datasource_id: EXCHANGE_ID,
product_id,
period_in_sec,
timestamp_in_us: t! * 1000,
start_at: t,
open: o!,
high: h!,
low: l!,
close: c!,
volume: vol!,
}),
return defer(() => {
const since = Date.now() - 3 * period_in_sec * 1000;
return ex.fetchOHLCV(symbol, timeframe, since);
})
.pipe(
//
repeat({ delay: 1000 }),
)
.pipe(
mergeMap((x) =>
from(x).pipe(
map(
([t, o, h, l, c, vol]): IPeriod => ({
datasource_id: EXCHANGE_ID,
product_id,
period_in_sec,
timestamp_in_us: t! * 1000,
start_at: t,
open: o!,
high: h!,
low: l!,
close: c!,
volume: vol!,
}),
),
toArray(),
),
toArray(),
),
),
retry({ delay: 1000 }),
);
retry({ delay: 1000 }),
);
});

if (!PUBLIC_ONLY) {
Expand Down
10 changes: 10 additions & 0 deletions common/changes/@yuants/vendor-ccxt/2024-02-25-14-57.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@yuants/vendor-ccxt",
"comment": "fetch ohlcv to correct error",
"type": "patch"
}
],
"packageName": "@yuants/vendor-ccxt"
}

0 comments on commit 4203785

Please sign in to comment.