Skip to content

Commit 21a4dcd

Browse files
committed
refactor(exchange): address review β€” optional-chain init, trim comments
- call strategy.init via optional chaining instead of an if-guard - shrink getRecentCandles JSDoc to its first sentence - drop the getDataset doc comment in @typedtrader/candles
1 parent 510afea commit 21a4dcd

3 files changed

Lines changed: 2 additions & 13 deletions

File tree

β€Žpackages/candles/src/index.tsβ€Ž

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export const datasets: CandleDataset[] = [
8585
},
8686
];
8787

88-
/** Look up a dataset by its `id` (e.g. `'uptrend-stx'`), or `undefined` if there is no match. */
8988
export function getDataset(id: string): CandleDataset | undefined {
9089
return datasets.find(dataset => dataset.id === id);
9190
}

β€Žpackages/exchange/src/broker/MarketDataSource.tsβ€Ž

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,7 @@ export abstract class MarketDataSource extends EventEmitter {
1919

2020
/**
2121
* Fetch the most recent `count` candles of the given interval, oldest first β€” so a strategy can
22-
* say "300 hourly candles" without computing calendar windows itself. This is the `count > 1`
23-
* generalization of `getLatestCandle`: same "anchor to the latest real bar" trick, wider window.
24-
*
25-
* Anchors the window's end to the latest real bar (so market closures β€” nights, weekends,
26-
* holidays β€” don't leave us with an empty "now" window that never fills) and pins it there while
27-
* widening the start backward. `getCandles` already paginates a time window to exhaustion, so each
28-
* attempt returns a superset of the previous one β€” no cross-window dedupe needed. We over-ask and
29-
* widen only because `count` bars can span far more wall-clock than `count * interval` once closed
30-
* sessions are excluded. Built purely on the abstract `getCandles`/`getLatestCandle`.
22+
* say "300 hourly candles" without computing calendar windows itself.
3123
*/
3224
async getRecentCandles(pair: TradingPair, count: number, intervalInMillis: number): Promise<Candle[]> {
3325
if (count <= 0) {

β€Žpackages/exchange/src/trader/TradingSession.tsβ€Ž

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ export class TradingSession extends EventEmitter<TradingSessionEventMap> {
6969
tradingRules,
7070
};
7171

72-
if (this.#strategy.init) {
73-
await this.#strategy.init(this.#broker, this.#pair);
74-
}
72+
await this.#strategy.init?.(this.#broker, this.#pair);
7573

7674
// Subscribe to candles only after state is ready
7775
const openTimeInISO = new Date().toISOString();

0 commit comments

Comments
Β (0)