@hoox-sh/pynets 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,8 +9,11 @@
9
9
  * is the host's job (`bucketIndex` / `shouldForwardFill`).
10
10
  * Lower-TF request without a feed is na — no invented intra-bar array.
11
11
  * Interpret should call this from `evalCall`; this module is host-agnostic.
12
+ * `request.footprint` is the Python mock (not foreign-na).
12
13
  */
13
14
 
15
+ import { createFootprint, seedFootprintRng } from "./footprint.ts";
16
+
14
17
  export type Cell = number | null;
15
18
 
16
19
  export interface SecurityArgs {
@@ -29,7 +32,7 @@ export interface RequestHost {
29
32
  * Named or positional args for `resolveRequest`.
30
33
  * Security uses `symbol` / `timeframe` / `sameSymbolValue`;
31
34
  * currency uses `from`/`to` (or `from_currency`/`to_currency`);
32
- * seed uses `seed`.
35
+ * seed uses `seed`; footprint uses `num_ticks` / `va_percentage`.
33
36
  */
34
37
  export interface RequestNamedArgs {
35
38
  symbol?: string | null;
@@ -41,6 +44,8 @@ export interface RequestNamedArgs {
41
44
  from_currency?: string | null;
42
45
  to_currency?: string | null;
43
46
  seed?: unknown;
47
+ num_ticks?: unknown;
48
+ va_percentage?: unknown;
44
49
  }
45
50
 
46
51
  export type RequestArgs = readonly unknown[] | RequestNamedArgs;
@@ -231,7 +236,7 @@ function bareTicker(symbol: string): string {
231
236
  return colon >= 0 ? s.slice(colon + 1) : s;
232
237
  }
233
238
 
234
- /** Missing / foreign fundamentals, economic, quandl, footprint → na. */
239
+ /** Missing / foreign fundamentals, economic, quandl → na. */
235
240
  export function resolveForeignNa(): Cell {
236
241
  return null;
237
242
  }
@@ -249,9 +254,10 @@ export function resolveCurrencyRate(
249
254
  return null;
250
255
  }
251
256
 
252
- /** `request.seed` — record the seed (Python returns None). */
257
+ /** `request.seed` — record the seed and seed the footprint RNG (Python returns None). */
253
258
  export function resolveSeed(seed?: unknown): Cell {
254
259
  lastSeed = coerceSeed(seed ?? 0);
260
+ seedFootprintRng(lastSeed);
255
261
  return null;
256
262
  }
257
263
 
@@ -262,7 +268,7 @@ export function lastRequestSeed(): number | null {
262
268
  /**
263
269
  * Dispatch a `request.*` name. Security keeps `resolveSecurity` semantics;
264
270
  * lower-TF without a feed is na; currency is 1.0 only for identical codes;
265
- * everything else is na.
271
+ * footprint is the Python mock; everything else is na.
266
272
  */
267
273
  export function resolveRequest(
268
274
  fname: string,
@@ -284,6 +290,10 @@ export function resolveRequest(
284
290
  if (fname === "request.seed") {
285
291
  return resolveSeed(seedFromArgs(args));
286
292
  }
293
+ if (fname === "request.footprint") {
294
+ const [numTicks, va] = footprintFromArgs(args);
295
+ return createFootprint(numTicks, va);
296
+ }
287
297
  return resolveForeignNa();
288
298
  }
289
299
 
@@ -326,6 +336,11 @@ function seedFromArgs(args: RequestArgs): unknown {
326
336
  return args.seed ?? 0;
327
337
  }
328
338
 
339
+ function footprintFromArgs(args: RequestArgs): [unknown, unknown] {
340
+ if (!isNamedArgs(args)) return [args[0] ?? 100, args[1] ?? 70];
341
+ return [args.num_ticks ?? 100, args.va_percentage ?? 70];
342
+ }
343
+
329
344
  function currencyPair(
330
345
  from: string | null | undefined,
331
346
  to: string | null | undefined,