@reyaxyz/strategy-format 0.0.0-stage → 0.3.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.
@@ -0,0 +1,242 @@
1
+ export type BlockId = string;
2
+ export type Market = string;
3
+ export type Decimal = string;
4
+ export type SideSpec = 'buy' | 'sell' | {
5
+ row: 'side';
6
+ };
7
+ export type Size = {
8
+ rusd: Decimal;
9
+ } | {
10
+ qty: Decimal;
11
+ } | {
12
+ expr: Expr;
13
+ } | {
14
+ row: 'size';
15
+ };
16
+ export type ReduceBy = Size | {
17
+ pct: Decimal;
18
+ };
19
+ export type PriceSpec = {
20
+ fixed: Decimal;
21
+ } | {
22
+ offset_bps: number;
23
+ } | {
24
+ expr: Expr;
25
+ };
26
+ export type SeriesName = 'mark' | 'funding_rate' | 'funding_rate_avg_15m' | 'funding_paid' | 'volume' | 'open_interest' | 'spread' | 'depth' | 'trades';
27
+ export type InputName = 'balance' | 'position' | 'entry' | 'rounds' | 'wins' | 'losses' | 'consecutive_losses' | 'last_round_pnl' | 'pnl' | 'high_since_state_entry' | 'low_since_state_entry' | 'remembered';
28
+ export type OpName = 'add' | 'sub' | 'mul' | 'div' | 'neg' | 'gt' | 'ge' | 'lt' | 'le' | 'eq' | 'ne' | 'and' | 'or' | 'not';
29
+ export type FnName = 'sma' | 'ema' | 'high' | 'low' | 'stdev' | 'pct_change' | 'corr' | 'value_ago' | 'rsi' | 'atr' | 'n_of_m' | 'if_else' | 'count_in_state' | 'sum' | 'any' | 'max_over' | 'min_over';
30
+ export type Expr = {
31
+ kind: 'num';
32
+ value: Decimal;
33
+ } | {
34
+ kind: 'series';
35
+ series: SeriesName;
36
+ market?: Market;
37
+ } | {
38
+ kind: 'outside';
39
+ series: BlockId;
40
+ } | {
41
+ kind: 'row';
42
+ row: 'reads';
43
+ index: number;
44
+ } | {
45
+ kind: 'input';
46
+ name: InputName;
47
+ market?: Market;
48
+ head?: BlockId;
49
+ of?: Expr;
50
+ remember_anchor?: 'start' | 'state_entry';
51
+ } | {
52
+ kind: 'op';
53
+ op: OpName;
54
+ args: Expr[];
55
+ } | {
56
+ kind: 'fn';
57
+ fn: FnName;
58
+ args: Expr[];
59
+ window_secs?: number;
60
+ interval_secs?: 3600 | 86400;
61
+ period?: number;
62
+ ago_secs?: number;
63
+ anchor?: 'utc_midnight' | 'state_entry';
64
+ };
65
+ export type Level = {
66
+ kind: 'price';
67
+ price: Decimal;
68
+ } | {
69
+ kind: 'from_entry';
70
+ pct?: Decimal;
71
+ distance?: Decimal;
72
+ } | {
73
+ kind: 'trailing';
74
+ pct?: Decimal;
75
+ distance?: Decimal;
76
+ activation?: Decimal;
77
+ } | {
78
+ kind: 'expr';
79
+ value: Expr;
80
+ };
81
+ export interface StopLevel {
82
+ id: BlockId;
83
+ at: Level;
84
+ size?: Size;
85
+ }
86
+ export type Trigger = {
87
+ kind: 'start';
88
+ } | {
89
+ kind: 'cross';
90
+ value: Expr;
91
+ direction: 'up' | 'down';
92
+ level: Expr;
93
+ band?: Decimal;
94
+ } | {
95
+ kind: 'every';
96
+ period_secs: number;
97
+ anchor?: number;
98
+ } | {
99
+ kind: 'at';
100
+ cadence: 'daily' | 'weekly';
101
+ time: string;
102
+ day?: Weekday;
103
+ } | {
104
+ kind: 'elapsed';
105
+ after_secs: number;
106
+ } | {
107
+ kind: 'filled';
108
+ order: BlockId;
109
+ } | {
110
+ kind: 'stop_loss' | 'take_profit';
111
+ levels: StopLevel[];
112
+ market?: Market;
113
+ } | {
114
+ kind: 'instances_ended';
115
+ list: BlockId;
116
+ } | {
117
+ kind: 'refused';
118
+ action?: BlockId;
119
+ } | {
120
+ kind: 'close_open';
121
+ } | {
122
+ kind: 'source_unreadable' | 'source_ended';
123
+ series: BlockId;
124
+ };
125
+ export type Weekday = 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' | 'sun';
126
+ export interface Rule {
127
+ when: Trigger;
128
+ if?: Expr;
129
+ do?: BlockId[];
130
+ go: BlockId;
131
+ }
132
+ export interface RestingOrder {
133
+ id: BlockId;
134
+ side: SideSpec;
135
+ size: Size;
136
+ price: PriceSpec;
137
+ market?: Market;
138
+ taker_ok?: true;
139
+ }
140
+ export interface WeightRow {
141
+ id: BlockId;
142
+ weight: Decimal;
143
+ if?: Expr;
144
+ }
145
+ export type Action = {
146
+ kind: 'order';
147
+ side: SideSpec;
148
+ size: Size;
149
+ max_slippage_bps: number;
150
+ market?: Market;
151
+ } | {
152
+ kind: 'limit_orders';
153
+ orders: RestingOrder[];
154
+ keep?: true;
155
+ } | {
156
+ kind: 'close';
157
+ market?: Market;
158
+ } | {
159
+ kind: 'reduce';
160
+ by: ReduceBy;
161
+ market?: Market;
162
+ } | {
163
+ kind: 'close_set';
164
+ list: BlockId;
165
+ } | {
166
+ kind: 'rebalance';
167
+ list: BlockId;
168
+ weights: WeightRow[];
169
+ total_rusd?: Decimal;
170
+ } | {
171
+ kind: 'move_stop';
172
+ rule: BlockId;
173
+ level: BlockId;
174
+ to: Level;
175
+ };
176
+ interface StateBase {
177
+ name?: string;
178
+ in_list?: BlockId;
179
+ on?: BlockId[];
180
+ }
181
+ export type State = (StateBase & {
182
+ kind: 'normal';
183
+ }) | (StateBase & {
184
+ kind: 'loop_head';
185
+ rounds?: number;
186
+ then?: BlockId;
187
+ }) | (StateBase & {
188
+ kind: 'final';
189
+ outcome: 'done' | 'hold';
190
+ });
191
+ export interface Row {
192
+ id: BlockId;
193
+ market: Market;
194
+ side?: SideSpec;
195
+ size?: Size;
196
+ reads?: BlockId[];
197
+ }
198
+ export type ListBlock = {
199
+ kind: 'fixed';
200
+ id: BlockId;
201
+ start: BlockId;
202
+ members: Row[];
203
+ } | {
204
+ kind: 'filter';
205
+ id: BlockId;
206
+ start: BlockId;
207
+ where: Expr;
208
+ max_size: number;
209
+ from?: Market[];
210
+ } | {
211
+ kind: 'rank';
212
+ id: BlockId;
213
+ start: BlockId;
214
+ by: Expr;
215
+ top: number;
216
+ order: 'desc' | 'asc';
217
+ from?: Market[];
218
+ };
219
+ export interface SeriesPin {
220
+ kind: 'prediction';
221
+ source: 'polymarket';
222
+ market: string;
223
+ outcome: string;
224
+ label: {
225
+ question: string;
226
+ outcome: string;
227
+ ends: number;
228
+ };
229
+ }
230
+ export interface StrategyV3 {
231
+ schema: 'reya.workflow/3';
232
+ start: BlockId;
233
+ states: Record<BlockId, State>;
234
+ rules?: Record<BlockId, Rule>;
235
+ actions?: Record<BlockId, Action>;
236
+ series?: Record<BlockId, SeriesPin>;
237
+ lists?: ListBlock[];
238
+ max_loss_rusd?: Decimal;
239
+ on_liquidation: 'close_and_end' | 'carry_on';
240
+ on_margin_skip: 'keep_running' | 'stop';
241
+ }
242
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ // The v3 document types, written by hand from reya-chain's generated schema (src/schema). Decimals are
3
+ // canonical decimal strings. `tests/coverage.test.ts` fails when the schema gains a kind or a field
4
+ // that `sentences` does not cover, which is the cue to update these types too.
5
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "@reyaxyz/strategy-format",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.0",
4
+ "description": "The v3 strategy format for TypeScript: reya-chain's schema and accepted kinds, the reader, the version hash, the block sentences and the line table",
5
+ "publishConfig": {
6
+ "access": "public",
7
+ "registry": "https://registry.npmjs.org"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/Reya-Labs/reya-off-chain-monorepo.git"
12
+ },
13
+ "license": "MIT",
14
+ "author": "Reya Network",
15
+ "main": "dist/index.js",
16
+ "types": "dist/index.d.ts",
17
+ "sideEffects": false,
18
+ "files": [
19
+ "dist",
20
+ "README.md"
21
+ ],
22
+ "engines": {
23
+ "node": ">=18.18.0"
24
+ },
25
+ "scripts": {
26
+ "build": "rm -rf dist && tsc -p tsconfig.build.json",
27
+ "ts:check-types": "tsc --noEmit",
28
+ "ts:circular-check": "dpdm --no-output --no-tree --no-warning --exit-code circular:1 -T src/index.ts",
29
+ "ts:check": "pnpm ts:check-types && pnpm ts:circular-check",
30
+ "prettier:check": "prettier --log-level silent --check './src/**/*.ts' './tests/**/*.ts'",
31
+ "prettier:fix": "prettier --log-level silent --write './src/**/*.ts' './tests/**/*.ts'",
32
+ "lint:check": "eslint src tests --ext .ts",
33
+ "lint:fix": "eslint src tests --ext .ts --fix",
34
+ "code-quality:check": "concurrently 'pnpm ts:check' 'pnpm prettier:check' 'pnpm lint:check --quiet'",
35
+ "test": "jest --runInBand"
36
+ },
37
+ "dependencies": {
38
+ "@noble/hashes": "1.8.0",
39
+ "zod": "4.6.6"
40
+ },
41
+ "devDependencies": {
42
+ "typescript": "5.3.3"
43
+ },
44
+ "gitHead": "a9ea58ff44b41c862a7ce23bc69fa9d977242f0d"
45
+ }