@hoox-sh/pynets 0.1.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.
- package/CHANGELOG.md +30 -0
- package/LICENSE +661 -0
- package/NOTICE +46 -0
- package/README.md +327 -0
- package/dist/browser.js +44 -0
- package/dist/index.d.ts +348 -0
- package/dist/index.js +41741 -0
- package/package.json +77 -0
- package/src/ast/builder.ts +1002 -0
- package/src/ast/dump.ts +43 -0
- package/src/ast/helper.ts +77 -0
- package/src/ast/nodes.ts +570 -0
- package/src/ast/unparse.ts +360 -0
- package/src/cli/rich.ts +378 -0
- package/src/cli.ts +627 -0
- package/src/generated/PinescriptLexer.interp +267 -0
- package/src/generated/PinescriptLexer.tokens +131 -0
- package/src/generated/PinescriptLexer.ts +673 -0
- package/src/generated/PinescriptLexerBase.ts +395 -0
- package/src/generated/PinescriptParser.interp +267 -0
- package/src/generated/PinescriptParser.tokens +131 -0
- package/src/generated/PinescriptParser.ts +8863 -0
- package/src/generated/PinescriptParserBase.ts +21 -0
- package/src/generated/PinescriptParserVisitor.ts +840 -0
- package/src/index.ts +55 -0
- package/src/parser/LexerBase.ts +395 -0
- package/src/parser/ParserBase.ts +21 -0
- package/src/parser/error.ts +33 -0
- package/src/runtime/array.ts +486 -0
- package/src/runtime/color.ts +164 -0
- package/src/runtime/drawings.ts +510 -0
- package/src/runtime/input.ts +102 -0
- package/src/runtime/interpret.ts +3897 -0
- package/src/runtime/library.ts +282 -0
- package/src/runtime/log.ts +69 -0
- package/src/runtime/map.ts +85 -0
- package/src/runtime/math.ts +231 -0
- package/src/runtime/matrix.ts +1154 -0
- package/src/runtime/provider.ts +232 -0
- package/src/runtime/request.ts +372 -0
- package/src/runtime/series.ts +44 -0
- package/src/runtime/str.ts +433 -0
- package/src/runtime/strategy.ts +1105 -0
- package/src/runtime/ta.ts +2093 -0
- package/src/runtime/ticker.ts +81 -0
- package/src/runtime/time.ts +439 -0
- package/src/runtime/timeframe.ts +85 -0
- package/src/runtime/udt.ts +119 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public API of @hoox-sh/pynets (generated by scripts/build.ts).
|
|
3
|
+
* Matches src/index.ts. Interpret only — no compile backend.
|
|
4
|
+
*/
|
|
5
|
+
export type ParseMode = "exec" | "eval";
|
|
6
|
+
|
|
7
|
+
export type ASTKind = string;
|
|
8
|
+
export interface AST {
|
|
9
|
+
readonly kind: ASTKind;
|
|
10
|
+
lineno?: number;
|
|
11
|
+
col_offset?: number;
|
|
12
|
+
end_lineno?: number | null;
|
|
13
|
+
end_col_offset?: number | null;
|
|
14
|
+
}
|
|
15
|
+
export interface Script extends AST {
|
|
16
|
+
kind: "Script";
|
|
17
|
+
body: unknown[];
|
|
18
|
+
annotations: string[];
|
|
19
|
+
}
|
|
20
|
+
export interface Expression extends AST {
|
|
21
|
+
kind: "Expression";
|
|
22
|
+
body: unknown;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class PinescriptSyntaxError extends Error {
|
|
26
|
+
name: "PinescriptSyntaxError";
|
|
27
|
+
lineno: number | null;
|
|
28
|
+
col_offset: number | null;
|
|
29
|
+
constructor(message: string, lineno?: number | null, col_offset?: number | null);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function parse(source: string, filename?: string, mode?: ParseMode): AST;
|
|
33
|
+
export function unparse(node: AST): string;
|
|
34
|
+
export function dump(node: AST, options?: { annotate_fields?: boolean; include_attributes?: boolean }): string;
|
|
35
|
+
export function tokenize(source: string): unknown[];
|
|
36
|
+
|
|
37
|
+
export type Cell = number | null;
|
|
38
|
+
export const NA: null;
|
|
39
|
+
|
|
40
|
+
export class PineSeries {
|
|
41
|
+
push(value: Cell): void;
|
|
42
|
+
setCurrent(value: Cell): void;
|
|
43
|
+
readonly current: Cell;
|
|
44
|
+
get(offset: number): Cell;
|
|
45
|
+
readonly length: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface OHLCVBar {
|
|
49
|
+
open?: number;
|
|
50
|
+
high?: number;
|
|
51
|
+
low?: number;
|
|
52
|
+
close?: number;
|
|
53
|
+
volume?: number;
|
|
54
|
+
time?: number;
|
|
55
|
+
}
|
|
56
|
+
export type InputOverrides = Record<string, number | string | boolean>;
|
|
57
|
+
export interface BrokerSettings {
|
|
58
|
+
commission?: number;
|
|
59
|
+
slippage?: number;
|
|
60
|
+
pyramiding?: number;
|
|
61
|
+
}
|
|
62
|
+
export interface RuntimeOptions {
|
|
63
|
+
inputs?: InputOverrides;
|
|
64
|
+
broker?: BrokerSettings;
|
|
65
|
+
timeframe?: string | null;
|
|
66
|
+
libraries?: LibraryRegistry;
|
|
67
|
+
}
|
|
68
|
+
export interface RuntimeFill {
|
|
69
|
+
type: "fill";
|
|
70
|
+
bar: number;
|
|
71
|
+
id: string;
|
|
72
|
+
side: "buy" | "sell";
|
|
73
|
+
qty: number;
|
|
74
|
+
price: number;
|
|
75
|
+
}
|
|
76
|
+
export interface StrategyEvent {
|
|
77
|
+
type: string;
|
|
78
|
+
id: string;
|
|
79
|
+
direction?: string;
|
|
80
|
+
qty?: number | null;
|
|
81
|
+
bar: number;
|
|
82
|
+
}
|
|
83
|
+
export interface StrategySummary {
|
|
84
|
+
netprofit: number;
|
|
85
|
+
netprofitPercent: number;
|
|
86
|
+
openprofit: number;
|
|
87
|
+
equity: number;
|
|
88
|
+
wintrades: number;
|
|
89
|
+
losstrades: number;
|
|
90
|
+
eventrades: number;
|
|
91
|
+
closedtrades: number;
|
|
92
|
+
opentrades: number;
|
|
93
|
+
grossprofit: number;
|
|
94
|
+
grossloss: number;
|
|
95
|
+
avgTrade: number;
|
|
96
|
+
avgWinningTrade: number;
|
|
97
|
+
avgLosingTrade: number;
|
|
98
|
+
percentProfitable: number;
|
|
99
|
+
profitFactor: number;
|
|
100
|
+
maxDrawdown: number;
|
|
101
|
+
maxDrawdownPercent: number;
|
|
102
|
+
maxRunup: number;
|
|
103
|
+
maxRunupPercent: number;
|
|
104
|
+
initialCapital: number;
|
|
105
|
+
}
|
|
106
|
+
export interface DrawingEvent {
|
|
107
|
+
kind: string;
|
|
108
|
+
bar: number;
|
|
109
|
+
text?: string;
|
|
110
|
+
extra?: Record<string, unknown>;
|
|
111
|
+
deleted?: boolean;
|
|
112
|
+
}
|
|
113
|
+
export interface LogRecord {
|
|
114
|
+
level: LogLevel;
|
|
115
|
+
bar: number;
|
|
116
|
+
message: string;
|
|
117
|
+
}
|
|
118
|
+
export type LogLevel = "INFO" | "WARNING" | "ERROR";
|
|
119
|
+
export interface RuntimeResult {
|
|
120
|
+
series: Record<string, Array<number | null>>;
|
|
121
|
+
plots: Array<number | null>;
|
|
122
|
+
plot_meta: Array<{ title: string }>;
|
|
123
|
+
count: number;
|
|
124
|
+
script_name: string | null;
|
|
125
|
+
script_type: string;
|
|
126
|
+
mode: "interpret";
|
|
127
|
+
events?: StrategyEvent[];
|
|
128
|
+
fills?: RuntimeFill[];
|
|
129
|
+
drawings?: DrawingEvent[];
|
|
130
|
+
logs?: LogRecord[];
|
|
131
|
+
plot_data?: Record<string, { data: Array<{ value: number | null; time?: number }> }>;
|
|
132
|
+
strategy?: StrategySummary;
|
|
133
|
+
error?: string;
|
|
134
|
+
error_kind?: string;
|
|
135
|
+
}
|
|
136
|
+
export type StreamEvent = "bar" | "error" | "end";
|
|
137
|
+
|
|
138
|
+
export class Runtime {
|
|
139
|
+
readonly symbol: string;
|
|
140
|
+
readonly inputs: InputOverrides;
|
|
141
|
+
readonly broker: BrokerSettings;
|
|
142
|
+
readonly timeframe: string | null;
|
|
143
|
+
readonly libraries: LibraryRegistry;
|
|
144
|
+
constructor(symbol?: string, options?: RuntimeOptions);
|
|
145
|
+
registerLibrarySource(namespace: string, name: string, version: number, source: string): void;
|
|
146
|
+
run(source: string, ohlcv: OHLCVBar[], extra?: RuntimeOptions | InputOverrides): RuntimeResult;
|
|
147
|
+
stream(source: string): RuntimeStream;
|
|
148
|
+
runProvider(
|
|
149
|
+
source: string,
|
|
150
|
+
provider: BarProvider,
|
|
151
|
+
extra?: RuntimeOptions & { limit?: number },
|
|
152
|
+
): Promise<RuntimeResult>;
|
|
153
|
+
}
|
|
154
|
+
export class RuntimeStream {
|
|
155
|
+
on(event: "bar", handler: (out: RuntimeResult) => void): this;
|
|
156
|
+
on(event: "error", handler: (err: Error) => void): this;
|
|
157
|
+
on(event: "end", handler: (out: RuntimeResult) => void): this;
|
|
158
|
+
push(bar: OHLCVBar): this;
|
|
159
|
+
end(): RuntimeResult;
|
|
160
|
+
}
|
|
161
|
+
export function interpret(source: string, ohlcv: OHLCVBar[]): { plots: Array<number | null> };
|
|
162
|
+
export function interpretTree(
|
|
163
|
+
tree: AST,
|
|
164
|
+
ohlcv: OHLCVBar[],
|
|
165
|
+
host?: {
|
|
166
|
+
symbol?: string;
|
|
167
|
+
inputs?: InputOverrides;
|
|
168
|
+
broker?: BrokerSettings;
|
|
169
|
+
timeframe?: string | null;
|
|
170
|
+
libraries?: LibraryRegistry;
|
|
171
|
+
},
|
|
172
|
+
): RuntimeResult;
|
|
173
|
+
|
|
174
|
+
export class TaEngine {
|
|
175
|
+
[key: string]: unknown;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export class PineArray {
|
|
179
|
+
constructor(size?: number, initial?: Cell);
|
|
180
|
+
size(): number;
|
|
181
|
+
get(index: number): Cell;
|
|
182
|
+
set(index: number, value: Cell): void;
|
|
183
|
+
push(value: Cell): void;
|
|
184
|
+
pop(): Cell;
|
|
185
|
+
static from(...values: Cell[]): PineArray;
|
|
186
|
+
}
|
|
187
|
+
export class PineMap {
|
|
188
|
+
size(): number;
|
|
189
|
+
put(key: unknown, value: Cell): void;
|
|
190
|
+
get(key: unknown): Cell;
|
|
191
|
+
contains(key: unknown): boolean;
|
|
192
|
+
remove(key: unknown): Cell;
|
|
193
|
+
clear(): void;
|
|
194
|
+
putAll(other: PineMap): void;
|
|
195
|
+
keys(): Array<string | number>;
|
|
196
|
+
values(): Cell[];
|
|
197
|
+
copy(): PineMap;
|
|
198
|
+
}
|
|
199
|
+
export class PineMatrix {
|
|
200
|
+
constructor(rows?: number, cols?: number, initial?: Cell);
|
|
201
|
+
rows(): number;
|
|
202
|
+
columns(): number;
|
|
203
|
+
get(row: number, col: number): Cell;
|
|
204
|
+
set(row: number, col: number, value: Cell): void;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export class DrawingBook {
|
|
208
|
+
readonly items: DrawingEvent[];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export interface ProviderBar {
|
|
212
|
+
open?: number;
|
|
213
|
+
high?: number;
|
|
214
|
+
low?: number;
|
|
215
|
+
close?: number;
|
|
216
|
+
volume?: number;
|
|
217
|
+
time?: number;
|
|
218
|
+
}
|
|
219
|
+
export interface BarProvider {
|
|
220
|
+
fetch(opts: { symbol: string; timeframe?: string | null; limit?: number }): Promise<ProviderBar[]>;
|
|
221
|
+
}
|
|
222
|
+
export class ProviderError extends Error {
|
|
223
|
+
readonly status?: number;
|
|
224
|
+
constructor(message: string, status?: number);
|
|
225
|
+
}
|
|
226
|
+
export interface JsonBarProviderOptions {
|
|
227
|
+
url?: (opts: { symbol: string; timeframe?: string | null; limit?: number }) => string;
|
|
228
|
+
fetch?: typeof fetch;
|
|
229
|
+
map?: (json: unknown) => ProviderBar[];
|
|
230
|
+
headers?: Record<string, string>;
|
|
231
|
+
fetchBars?: (opts: {
|
|
232
|
+
symbol: string;
|
|
233
|
+
timeframe?: string | null;
|
|
234
|
+
limit?: number;
|
|
235
|
+
}) => Promise<unknown> | unknown;
|
|
236
|
+
}
|
|
237
|
+
export class MemoryProvider implements BarProvider {
|
|
238
|
+
constructor(bars: ProviderBar[]);
|
|
239
|
+
fetch(opts: { limit?: number }): Promise<ProviderBar[]>;
|
|
240
|
+
}
|
|
241
|
+
export class StaticMapProvider implements BarProvider {
|
|
242
|
+
constructor(feeds: Record<string, ProviderBar[]>);
|
|
243
|
+
fetch(opts: { symbol: string; timeframe?: string | null; limit?: number }): Promise<ProviderBar[]>;
|
|
244
|
+
}
|
|
245
|
+
export class JsonBarProvider implements BarProvider {
|
|
246
|
+
constructor(opts: JsonBarProviderOptions);
|
|
247
|
+
fetch(opts: { symbol: string; timeframe?: string | null; limit?: number }): Promise<ProviderBar[]>;
|
|
248
|
+
}
|
|
249
|
+
export function mapJsonBars(json: unknown): ProviderBar[];
|
|
250
|
+
|
|
251
|
+
export class LibraryModule {
|
|
252
|
+
title: string;
|
|
253
|
+
namespace: string | null;
|
|
254
|
+
version: number | null;
|
|
255
|
+
get(name: string): unknown;
|
|
256
|
+
has(name: string): boolean;
|
|
257
|
+
}
|
|
258
|
+
export class LibraryRegistry {
|
|
259
|
+
register(module: LibraryModule): void;
|
|
260
|
+
registerSource(namespace: string, name: string, version: number, source: string): void;
|
|
261
|
+
getSource(namespace: string, name: string, version: number): string | null;
|
|
262
|
+
lookup(query: { namespace?: string | null; name: string; version?: number | null }): LibraryModule | null;
|
|
263
|
+
clear(): void;
|
|
264
|
+
}
|
|
265
|
+
export function createStubModule(title: string): LibraryModule;
|
|
266
|
+
export function applyStubExport(name: string, args?: unknown[], kwargs?: Record<string, unknown>): unknown;
|
|
267
|
+
export const STUB_KNOWN_EXPORTS: Record<string, (...args: unknown[]) => unknown>;
|
|
268
|
+
|
|
269
|
+
export interface UtcParts {
|
|
270
|
+
year: number;
|
|
271
|
+
month: number;
|
|
272
|
+
dayofmonth: number;
|
|
273
|
+
hour: number;
|
|
274
|
+
minute: number;
|
|
275
|
+
second: number;
|
|
276
|
+
dayofweek: number;
|
|
277
|
+
}
|
|
278
|
+
export function utcPartsFromMs(ms: number): UtcParts;
|
|
279
|
+
export function timestampFromComponents(
|
|
280
|
+
year: number | null | undefined,
|
|
281
|
+
month: number | null | undefined,
|
|
282
|
+
day: number | null | undefined,
|
|
283
|
+
hour?: number | null,
|
|
284
|
+
minute?: number | null,
|
|
285
|
+
second?: number | null,
|
|
286
|
+
tzOffsetMinutes?: number | null,
|
|
287
|
+
): number | null;
|
|
288
|
+
export function parseTimestampString(text: string): number | null;
|
|
289
|
+
export function timestamp(...args: unknown[]): number | null;
|
|
290
|
+
export function weekOfYear(ms: number): number | null;
|
|
291
|
+
export function timeTradingDay(ms: number): number | null;
|
|
292
|
+
|
|
293
|
+
export class LogBook {
|
|
294
|
+
readonly records: LogRecord[];
|
|
295
|
+
info(bar: number, message: string): void;
|
|
296
|
+
warning(bar: number, message: string): void;
|
|
297
|
+
error(bar: number, message: string): void;
|
|
298
|
+
clear(): void;
|
|
299
|
+
snapshot(): LogRecord[];
|
|
300
|
+
}
|
|
301
|
+
export class RuntimeError extends Error {
|
|
302
|
+
name: "RuntimeError";
|
|
303
|
+
}
|
|
304
|
+
export function runtimeError(message: string): never;
|
|
305
|
+
|
|
306
|
+
export class TickerId {
|
|
307
|
+
symbol: string;
|
|
308
|
+
session?: string;
|
|
309
|
+
adjust?: string;
|
|
310
|
+
heikinashi: boolean;
|
|
311
|
+
renko: boolean;
|
|
312
|
+
kagi: boolean;
|
|
313
|
+
linebreak: boolean;
|
|
314
|
+
pointfigure: boolean;
|
|
315
|
+
toString(): string;
|
|
316
|
+
}
|
|
317
|
+
export function tickerNew(symbol: string, session?: string, adjust?: string): TickerId;
|
|
318
|
+
export function tickerHeikinashi(symbol: string): TickerId;
|
|
319
|
+
export function tickerStandard(symbol: string): TickerId;
|
|
320
|
+
export function tickerRenko(symbol: string): TickerId;
|
|
321
|
+
export function tickerKagi(symbol: string): TickerId;
|
|
322
|
+
export function tickerLinebreak(symbol: string): TickerId;
|
|
323
|
+
export function tickerPointfigure(symbol: string): TickerId;
|
|
324
|
+
export function tickerModify(
|
|
325
|
+
ticker: TickerId | string,
|
|
326
|
+
opts?: { symbol?: string; session?: string; adjust?: string; adjustment?: string },
|
|
327
|
+
): TickerId;
|
|
328
|
+
|
|
329
|
+
export class UdtType {
|
|
330
|
+
readonly name: string;
|
|
331
|
+
newInstance(overrides?: Record<string, unknown>): UdtInstance;
|
|
332
|
+
}
|
|
333
|
+
export class UdtInstance {
|
|
334
|
+
readonly typeName: string;
|
|
335
|
+
get(field: string): unknown;
|
|
336
|
+
set(field: string, value: unknown): void;
|
|
337
|
+
}
|
|
338
|
+
export class EnumType {
|
|
339
|
+
readonly name: string;
|
|
340
|
+
readonly members: Map<string, EnumMember>;
|
|
341
|
+
}
|
|
342
|
+
export class EnumMember {
|
|
343
|
+
readonly enumName: string;
|
|
344
|
+
readonly name: string;
|
|
345
|
+
readonly value?: unknown;
|
|
346
|
+
equals(other: unknown): boolean;
|
|
347
|
+
toString(): string;
|
|
348
|
+
}
|