@reyaxyz/strategy-format 0.2.0 → 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.
package/README.md CHANGED
@@ -26,6 +26,17 @@ show and hash a document it receives.
26
26
  fails if no line changes. A pin's source ids
27
27
  (`market`, `outcome`) are not shown: the card shows the label the trader saw, which the service
28
28
  checks against them.
29
+ - `line(key, vars?, t?)` and `src/lines.json`: every line the chat, the cards and the pages show for v3
30
+ (AGT-219 part 3, the line table), keyed `id` or `id.form`, returned as `{ id, text }`, the shape of a
31
+ tool result's `say`. A line whose main text is the service's holds only the follow-on code adds
32
+ (`FOLLOW_ONS`, by issue code). The pickers choose the line by the service's code, never by text:
33
+ `needsYouLine`, `activityLine` (`null` for a code with nothing to show), `endedLine`, `whatIfLine`
34
+ (`null` for an authored row, which reads as its rule's sentence), `READ_OUTS` (each read-out's name by
35
+ field) and `gradedFigure` ("at most …", "not known yet"). A code this client does not know shows the
36
+ general line for its kind with the code as its reference. Money is in USDC; "$" only for Polymarket's
37
+ own figures. `sentences` takes its settings and its pin line from the same table. A test pins the line
38
+ ids, and another fails on an engine code (copied by hand from reya-chain, commit in the test) that has
39
+ no line.
29
40
  - `workflowV3Schema`, `acceptedKinds`, `schemaSource`: the copies of reya-chain's files and the commit
30
41
  they came from.
31
42
 
package/dist/en.json CHANGED
@@ -59,7 +59,7 @@
59
59
  "level.trailing.distance": "trailing {distance}{activation}",
60
60
  "level.trailing.activation": " once the price reaches {activation}",
61
61
  "level.expr": "at {value}",
62
- "action.order": "{side} {size} of {market} at the market, at most {bps} bps from the mark",
62
+ "action.order": "{side} {size} of {market} at the market, max slippage {bps} bps",
63
63
  "action.limit_orders.one": "place {count} resting order ({orders}); {keep}",
64
64
  "action.limit_orders.other": "place {count} resting orders ({orders}); {keep}",
65
65
  "action.limit_orders.keep": "they stay when {home} is left",
@@ -71,7 +71,7 @@
71
71
  "action.rebalance": "rebalance list {list} to {total} by weight ({weights})",
72
72
  "action.rebalance.total.account": "the account value",
73
73
  "action.rebalance.total.account.paper": "this Paper run's margin",
74
- "action.rebalance.total": "{total} rUSD",
74
+ "action.rebalance.total": "{total} USDC",
75
75
  "action.move_stop": "move level {level} of {rule} to {to}",
76
76
  "orders.join": "; ",
77
77
  "order.resting": "{side} {size} of {market} at {price}, {taker}",
@@ -90,14 +90,14 @@
90
90
  "side.buy": "buy",
91
91
  "side.sell": "sell",
92
92
  "side.row": "buy or sell (the row's side)",
93
- "size.rusd": "{rusd} rUSD",
93
+ "size.rusd": "{rusd} USDC",
94
94
  "size.qty": "{qty}",
95
- "size.expr": "{expr} rUSD",
95
+ "size.expr": "{expr} USDC",
96
96
  "size.row": "the row's size",
97
97
  "size.pct": "{pct}%",
98
98
  "market.row": "the row's market",
99
99
  "pin": "the chance of \"{outcome}\" on \"{question}\"",
100
- "pin.line": "Reads {pin} on Polymarket; the market ends on {ends}.",
100
+ "pin.line": "Reads Polymarket: \"{question}\" · {outcome} · listed end {ends}",
101
101
  "list.fixed": "List {n}: {rows}. Each member starts at {start}.",
102
102
  "list.filter": "List {n}: up to {max} markets from {from} where {where}. Each member starts at {start}.",
103
103
  "list.rank": "List {n}: the {top} markets from {from} with the {order} {by}. Each member starts at {start}.",
@@ -109,15 +109,15 @@
109
109
  "row.side": ", {side}",
110
110
  "row.size": ", {size}",
111
111
  "row.reads": ", reading {pins}",
112
- "setting.max_loss_rusd": "Max loss: {value} rUSD; when the account's loss since Start (open positions at the mark, fees and funding included; a position held at Start counts from its mark at Start) reaches it, the strategy closes every position on the account, including ones held before Start, and ends.",
113
- "setting.max_loss_rusd.paper": "Max loss: {value} rUSD; when this Paper run's loss since Start (its Paper positions at the mark, simulated fees and funding included) reaches it, the run closes its Paper positions and ends. Nothing on your real account changes.",
112
+ "setting.max_loss_rusd": "Max loss: {value} USDC; when the account's loss since Start (open positions at the mark, fees and funding included; a position held at Start counts from its mark at Start) reaches it, the strategy closes every position on the account, including ones held before Start, and ends.",
113
+ "setting.max_loss_rusd.paper": "Max loss: {value} USDC; when this Paper run's loss since Start (its Paper positions at the mark, simulated fees and funding included) reaches it, the run closes its Paper positions and ends. Nothing on your real account changes.",
114
114
  "setting.max_loss_rusd.none": "No max loss is set.",
115
- "setting.on_liquidation.close_and_end": "If the account is liquidated, the strategy closes every position on the account and ends.",
116
- "setting.on_liquidation.close_and_end.paper": "Paper has no liquidation: nothing forces a Paper position closed. On Live, if the account is liquidated, the strategy closes every position on the account and ends.",
117
- "setting.on_liquidation.carry_on": "If the account is liquidated, the strategy carries on.",
118
- "setting.on_liquidation.carry_on.paper": "Paper has no liquidation: nothing forces a Paper position closed. On Live, if the account is liquidated, the strategy carries on.",
119
- "setting.on_margin_skip.keep_running": "If an order is refused for lack of margin, the rule that placed it does nothing (no other action, no state change), a rule on a refused action can answer it, and the strategy keeps running.",
120
- "setting.on_margin_skip.stop": "If an order is refused for lack of margin, the rule that placed it does nothing and the strategy stops.",
115
+ "setting.on_liquidation.close_and_end": "If the account is liquidated: everything left is closed and the strategy ends.",
116
+ "setting.on_liquidation.close_and_end.paper": "Paper has no liquidation: nothing forces a Paper position closed. If the paper margin runs out, new orders are skipped and exits keep running.",
117
+ "setting.on_liquidation.carry_on": "If the account is liquidated: the strategy carries on with what is left.",
118
+ "setting.on_liquidation.carry_on.paper": "Paper has no liquidation: nothing forces a Paper position closed. If the paper margin runs out, new orders are skipped and exits keep running.",
119
+ "setting.on_margin_skip.keep_running": "If an order does not fit the margin: it is skipped, the strategy is marked Needs-you, and it tries again on the next trigger.",
120
+ "setting.on_margin_skip.stop": "If an order does not fit the margin: the strategy stops.",
121
121
  "series.mark": "the mark price of {market}",
122
122
  "series.funding_rate": "the funding rate of {market} (a fraction per day)",
123
123
  "series.funding_rate_avg_15m": "the 15-minute average funding rate of {market} (a fraction per day)",
package/dist/index.d.ts CHANGED
@@ -1810,3 +1810,5 @@ export declare const schemaSource: {
1810
1810
  };
1811
1811
  export { sentences } from './sentences';
1812
1812
  export type { Mode, SentenceKey, Translations } from './sentences';
1813
+ export { line, lineId, LINES, FOLLOW_ONS, needsYouLine, NEEDS_YOU_CODES, activityLine, ACTIVITY_CODES, ACTIVITY_NOT_LISTED, ENTRY_DROPPED, endedLine, PAPER_LINES, END_REASONS, READ_OUTS, gradedFigure, whatIfLine, WHAT_IF_RESPONSES, } from './lines';
1814
+ export type { LineKey, LineTranslations, LineVars, SayLine, RunStatus, NeedsYouItem, ActivityEntry, Grade, WhatIfRow, } from './lines';
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.sentences = exports.schemaSource = exports.acceptedKinds = exports.workflowV3Schema = exports.versionHash = exports.canonical = exports.MAX_DOCUMENT_BYTES = exports.readStrategy = void 0;
20
+ exports.WHAT_IF_RESPONSES = exports.whatIfLine = exports.gradedFigure = exports.READ_OUTS = exports.END_REASONS = exports.PAPER_LINES = exports.endedLine = exports.ENTRY_DROPPED = exports.ACTIVITY_NOT_LISTED = exports.ACTIVITY_CODES = exports.activityLine = exports.NEEDS_YOU_CODES = exports.needsYouLine = exports.FOLLOW_ONS = exports.LINES = exports.lineId = exports.line = exports.sentences = exports.schemaSource = exports.acceptedKinds = exports.workflowV3Schema = exports.versionHash = exports.canonical = exports.MAX_DOCUMENT_BYTES = exports.readStrategy = void 0;
21
21
  const workflow_v3_schema_json_1 = __importDefault(require("./schema/workflow-v3.schema.json"));
22
22
  const workflow_v3_accepted_kinds_json_1 = __importDefault(require("./schema/workflow-v3.accepted-kinds.json"));
23
23
  const source_json_1 = __importDefault(require("./schema/source.json"));
@@ -35,3 +35,21 @@ exports.acceptedKinds = workflow_v3_accepted_kinds_json_1.default;
35
35
  exports.schemaSource = source_json_1.default;
36
36
  var sentences_1 = require("./sentences");
37
37
  Object.defineProperty(exports, "sentences", { enumerable: true, get: function () { return sentences_1.sentences; } });
38
+ var lines_1 = require("./lines");
39
+ Object.defineProperty(exports, "line", { enumerable: true, get: function () { return lines_1.line; } });
40
+ Object.defineProperty(exports, "lineId", { enumerable: true, get: function () { return lines_1.lineId; } });
41
+ Object.defineProperty(exports, "LINES", { enumerable: true, get: function () { return lines_1.LINES; } });
42
+ Object.defineProperty(exports, "FOLLOW_ONS", { enumerable: true, get: function () { return lines_1.FOLLOW_ONS; } });
43
+ Object.defineProperty(exports, "needsYouLine", { enumerable: true, get: function () { return lines_1.needsYouLine; } });
44
+ Object.defineProperty(exports, "NEEDS_YOU_CODES", { enumerable: true, get: function () { return lines_1.NEEDS_YOU_CODES; } });
45
+ Object.defineProperty(exports, "activityLine", { enumerable: true, get: function () { return lines_1.activityLine; } });
46
+ Object.defineProperty(exports, "ACTIVITY_CODES", { enumerable: true, get: function () { return lines_1.ACTIVITY_CODES; } });
47
+ Object.defineProperty(exports, "ACTIVITY_NOT_LISTED", { enumerable: true, get: function () { return lines_1.ACTIVITY_NOT_LISTED; } });
48
+ Object.defineProperty(exports, "ENTRY_DROPPED", { enumerable: true, get: function () { return lines_1.ENTRY_DROPPED; } });
49
+ Object.defineProperty(exports, "endedLine", { enumerable: true, get: function () { return lines_1.endedLine; } });
50
+ Object.defineProperty(exports, "PAPER_LINES", { enumerable: true, get: function () { return lines_1.PAPER_LINES; } });
51
+ Object.defineProperty(exports, "END_REASONS", { enumerable: true, get: function () { return lines_1.END_REASONS; } });
52
+ Object.defineProperty(exports, "READ_OUTS", { enumerable: true, get: function () { return lines_1.READ_OUTS; } });
53
+ Object.defineProperty(exports, "gradedFigure", { enumerable: true, get: function () { return lines_1.gradedFigure; } });
54
+ Object.defineProperty(exports, "whatIfLine", { enumerable: true, get: function () { return lines_1.whatIfLine; } });
55
+ Object.defineProperty(exports, "WHAT_IF_RESPONSES", { enumerable: true, get: function () { return lines_1.WHAT_IF_RESPONSES; } });
@@ -0,0 +1,138 @@
1
+ import lines from './lines.json';
2
+ /**
3
+ * The words of every line the chat, the cards and the pages show for v3 (AGT-219 part 3, the line
4
+ * table), keyed `id` or `id.form`. The id is what a tool result's `say` carries and what the other
5
+ * parts use; the form picks one wording of it (`start-1.empty`, `close-reason.close_open_halted`).
6
+ * A line whose main text is the service's (a warning, most refusals) holds only the follow-on code
7
+ * adds after that message.
8
+ */
9
+ export type LineKey = keyof typeof lines;
10
+ /** A translation of `lines.json`: every key, with the same `{placeholders}`. */
11
+ export type LineTranslations = Record<LineKey, string>;
12
+ export type SayLine = {
13
+ id: string;
14
+ text: string;
15
+ };
16
+ export type LineVars = Record<string, string | number>;
17
+ export declare const LINES: LineTranslations;
18
+ /** The line id of a key: what comes before its form. */
19
+ export declare const lineId: (key: LineKey) => string;
20
+ /**
21
+ * The line for `key`, filled in one pass, so a `{...}` inside a value (a market's question) stays as
22
+ * text. A placeholder with no value is left as written.
23
+ */
24
+ export declare function line(key: LineKey, vars?: LineVars, t?: LineTranslations): SayLine;
25
+ /**
26
+ * The follow-on code adds after the service's message, by the issue's code or, for a refused check,
27
+ * its `details.reason`. A code with none is relayed alone.
28
+ */
29
+ export declare const FOLLOW_ONS: Readonly<Record<string, LineKey>>;
30
+ /** A run's status, as the strategy service reports it. */
31
+ export type RunStatus = 'running' | 'closing' | 'holding' | 'ended';
32
+ type Options = {
33
+ t?: LineTranslations;
34
+ mode?: 'live' | 'paper';
35
+ /**
36
+ * The run's status, for the items whose facts depend on it: a liquidation (carrying on, closing,
37
+ * or done) and a held account history (which stays after the run ends).
38
+ */
39
+ status?: RunStatus;
40
+ };
41
+ /** A Needs-you item as the strategy service returns it (reya-chain's `Incident`). */
42
+ export type NeedsYouItem = {
43
+ code: string;
44
+ /** The order manager's cause behind an overdue item: its line wins where it has one. */
45
+ sender_code?: string;
46
+ market?: string;
47
+ rule?: string;
48
+ /**
49
+ * The engine's text. Never shown raw: only a max-loss pause's cause and a stopped close's
50
+ * position are read from it, in the engine's exact words.
51
+ */
52
+ detail?: string;
53
+ escalated?: boolean;
54
+ /** The effect (order) the item is about: set when the exchange refused an order. */
55
+ effect?: number | string;
56
+ /** Why an outside action ended the run: `new_order`, `modified`, `cancelled`, `found_at_restart`. */
57
+ cause?: string;
58
+ };
59
+ /** Every Needs-you code reya-chain sends that has a line of its own (the rest show `needs-other`). */
60
+ export declare const NEEDS_YOU_CODES: readonly string[];
61
+ /**
62
+ * The line for a Needs-you item, picked by its code. `vars` fills what the item does not carry (an
63
+ * expiry's `date`, an ended market's `question`, a rule's name as `rule`). Pass the run's `status`
64
+ * in `options`: a liquidation's line depends on it. A code this client has no line for, and
65
+ * `legacy`, show `needs-other` with the code as its reference.
66
+ */
67
+ export declare function needsYouLine(item: NeedsYouItem, vars?: LineVars, options?: Options): SayLine;
68
+ /** An activity entry as the strategy service returns it (reya-chain's `Activity`). */
69
+ export type ActivityEntry = {
70
+ code: string;
71
+ /** Diagnostic text; an entry drop's fixed reason. Shown only as an order refusal's reason. */
72
+ reason?: string;
73
+ rule?: string;
74
+ market?: string;
75
+ event?: string;
76
+ incident?: NeedsYouItem;
77
+ /** The effect (order) the entry is about: set when the exchange refused an order. */
78
+ effect?: number | string;
79
+ };
80
+ /** The engine's fixed reasons for a dropped entry (`runtime/step.rs`), matched exactly. */
81
+ export declare const ENTRY_DROPPED: Readonly<Record<string, LineKey>>;
82
+ /**
83
+ * Activity codes with nothing to show the user: the engine's bookkeeping, a fault written beside
84
+ * the rule's own event, a fill another order owns, and moving the user's own stop into a strategy
85
+ * (not in this release).
86
+ */
87
+ export declare const ACTIVITY_NOT_LISTED: readonly string[];
88
+ /** Every activity code with a line. */
89
+ export declare const ACTIVITY_CODES: readonly string[];
90
+ /**
91
+ * The line for an activity entry, picked by its code, or `null` for one with nothing to show (an
92
+ * event kind whose Needs-you item or effect carries the line, and `ACTIVITY_NOT_LISTED`). A code
93
+ * this client has no line for, and `legacy`, show `activity-other`.
94
+ */
95
+ export declare function activityLine(entry: ActivityEntry, vars?: LineVars, options?: Options): SayLine | null;
96
+ /** Every end reason reya-chain sends. */
97
+ export declare const END_REASONS: readonly string[];
98
+ /**
99
+ * Why a strategy ended, by the engine's reason: for an Ended run only. The engine sets the reason
100
+ * when the run starts to end, while it is still Closing; show `status-closing` until it is Ended.
101
+ * A liquidation, an order from outside and permission gone use their Needs-you line, so one reason
102
+ * has one set of words. With no reason, or one this client does not know, `status-ended`.
103
+ */
104
+ export declare const endedLine: (reason: string | undefined, t?: LineTranslations) => SayLine;
105
+ /**
106
+ * A Paper run's lasting lines, by code (reya-chain's `PaperLine`): shown for good once they happen,
107
+ * never as Needs-you items. `paper-below-zero` takes the `date`; `paper-not-closed` goes beside each
108
+ * position left open.
109
+ */
110
+ export declare const PAPER_LINES: Readonly<Record<string, LineKey>>;
111
+ /** Each read-out's name, by its field in the check result (`result.readouts`). */
112
+ export declare const READ_OUTS: Readonly<Record<string, LineKey>>;
113
+ /** A figure's grade, as the service sends it (`kind`). */
114
+ export type Grade = 'exact' | 'at_most' | 'at_least' | 'unknown';
115
+ /**
116
+ * A figure with its grade, which is part of what is said: "at most 106.43 USDC", "not known yet".
117
+ * `figure` is the value as the client formats it, with its unit.
118
+ */
119
+ export declare const gradedFigure: (grade: Grade, figure: string, t?: LineTranslations) => string;
120
+ /** A "what happens if" row as the service returns it (reya-chain's `WhatIfRow`). */
121
+ export type WhatIfRow = {
122
+ response: string;
123
+ /** The event, by trigger kind or setting name: `source_ended <pin>`, `exchange_stop_loss`, … */
124
+ event: string;
125
+ market?: string;
126
+ basis_after?: unknown;
127
+ };
128
+ /** Every `response` reya-chain sends, `authored` included (it reads as its rule's sentence). */
129
+ export declare const WHAT_IF_RESPONSES: readonly string[];
130
+ /**
131
+ * The line for a "what happens if" row, picked by its `response`, or `null` for `authored`: that
132
+ * row reads as its rule's own sentence (`sentences(doc)[row.rule]`). `vars` holds the figures as the
133
+ * client formats them (`needed`, `have`, `basis`) and an odds row's `question`. An unknown row reads
134
+ * "{its event's 'If …' words}: not known yet." On a Paper run the liquidation row reads
135
+ * `paper-no-liquidation`.
136
+ */
137
+ export declare function whatIfLine(row: WhatIfRow, vars?: LineVars, { t, mode }?: Options): SayLine | null;
138
+ export {};
package/dist/lines.js ADDED
@@ -0,0 +1,516 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.whatIfLine = exports.WHAT_IF_RESPONSES = exports.gradedFigure = exports.READ_OUTS = exports.PAPER_LINES = exports.endedLine = exports.END_REASONS = exports.activityLine = exports.ACTIVITY_CODES = exports.ACTIVITY_NOT_LISTED = exports.ENTRY_DROPPED = exports.needsYouLine = exports.NEEDS_YOU_CODES = exports.FOLLOW_ONS = exports.line = exports.lineId = exports.LINES = void 0;
7
+ const lines_json_1 = __importDefault(require("./lines.json"));
8
+ exports.LINES = lines_json_1.default;
9
+ /** The line id of a key: what comes before its form. */
10
+ const lineId = (key) => key.split('.')[0];
11
+ exports.lineId = lineId;
12
+ /**
13
+ * The line for `key`, filled in one pass, so a `{...}` inside a value (a market's question) stays as
14
+ * text. A placeholder with no value is left as written.
15
+ */
16
+ function line(key, vars = {}, t = exports.LINES) {
17
+ const text = t[key].replace(/\{(\w+)\}/g, (all, name) => name in vars ? String(vars[name]) : all);
18
+ return { id: (0, exports.lineId)(key), text };
19
+ }
20
+ exports.line = line;
21
+ /** Own keys only: a code such as `constructor` is not a line. */
22
+ const own = (table, key) => key !== undefined && Object.prototype.hasOwnProperty.call(table, key)
23
+ ? table[key]
24
+ : undefined;
25
+ /**
26
+ * The follow-on code adds after the service's message, by the issue's code or, for a refused check,
27
+ * its `details.reason`. A code with none is relayed alone.
28
+ */
29
+ exports.FOLLOW_ONS = {
30
+ no_max_loss: 'warn-no-max-loss',
31
+ max_loss_beyond_liquidation: 'warn-max-loss-liquidation',
32
+ positions_held_at_start: 'warn-held',
33
+ only_exit_reads_outside_series: 'warn-outside-exit',
34
+ stop_on_wrong_side: 'refuse-stop-side',
35
+ take_profit_on_wrong_side: 'refuse-stop-side',
36
+ stop_wrong_side_of_entry_by_construction: 'refuse-stop-entry',
37
+ account_has_live_strategy: 'refuse-second-live',
38
+ odds_source_off: 'refuse-odds-off',
39
+ paper_slippage_too_wide: 'refuse-paper-slippage',
40
+ };
41
+ /** On a Paper run every Needs-you and activity line reads "Paper: …". */
42
+ const forMode = (l, { t, mode }) => mode === 'paper'
43
+ ? { id: l.id, text: line('paper-prefix', { line: l.text }, t).text }
44
+ : l;
45
+ const NEEDS_YOU = {
46
+ permission_gone: 'needs-permission',
47
+ deleveraged: 'needs-deleveraged',
48
+ order_unanswered_operator: 'needs-no-answer-team',
49
+ probe_unsigned: 'needs-no-answer-team',
50
+ consecutive_drops: 'needs-dropped',
51
+ expiry_approaching: 'needs-expiry',
52
+ execution_busted: 'needs-busted',
53
+ unsent_at_restart: 'needs-unsent',
54
+ rule_unreadable: 'needs-rule-unreadable',
55
+ refusal_handler_cycle: 'needs-engine-limit',
56
+ structural_transition_limit: 'needs-engine-limit',
57
+ account_suspended: 'needs-account-suspended',
58
+ restart_gap: 'needs-stops-paused',
59
+ stops_paused_service: 'needs-stops-paused',
60
+ position_unprotected: 'needs-unprotected',
61
+ sender_rest_fallback: 'needs-stop-slower',
62
+ entry_refused_kill_switch: 'needs-orders-paused',
63
+ market_catalogue_stale: 'needs-market-data',
64
+ cancel_left_in_place: 'needs-cancel-left',
65
+ round_result_unknown: 'needs-round-unknown',
66
+ feature_gated_at_restart: 'needs-feature-off',
67
+ position_unreadable: 'needs-position-unreadable',
68
+ cancels_pending: 'needs-cancels-pending',
69
+ close_cancel_refused: 'needs-cancel-refused',
70
+ orders_row_unreadable: 'needs-orders-unreadable',
71
+ stop_stale: 'why-stale',
72
+ odds_unreadable_exit: 'why-odds',
73
+ source_ended: 'needs-odds-ended',
74
+ };
75
+ const MAX_LOSS_PAUSED = {
76
+ max_loss_paused_account: 'needs-max-loss-paused.account',
77
+ max_loss_paused_funding: 'needs-max-loss-paused.funding',
78
+ max_loss_paused_error: 'needs-max-loss-paused.error',
79
+ };
80
+ const isCloseReason = (code) => !!code && own(exports.LINES, `close-reason.${code}`) !== undefined;
81
+ /**
82
+ * A max-loss pause's cause: the engine puts its sentence in the item's `detail`
83
+ * (`record_max_loss_readability`), not a code.
84
+ */
85
+ const MAX_LOSS_DETAIL = [
86
+ [
87
+ /^Max loss is paused: the price for (.+) is stale$/,
88
+ 'needs-max-loss-paused.price',
89
+ ],
90
+ [
91
+ /^Max loss is paused: a market's price is stale$/,
92
+ 'needs-max-loss-paused.price-any',
93
+ ],
94
+ [
95
+ /^Max loss is paused: Reya's account data is behind$/,
96
+ 'needs-max-loss-paused.account',
97
+ ],
98
+ [
99
+ /^Max loss is paused: funding data is behind$/,
100
+ 'needs-max-loss-paused.funding',
101
+ ],
102
+ [
103
+ /^Max loss is paused: its figures can't be read$/,
104
+ 'needs-max-loss-paused.error',
105
+ ],
106
+ ];
107
+ /** What a stopped close's `detail` adds after the engine's own sentence: the position left open. */
108
+ const STILL_OPEN = /^(?:The close stopped\. )?Still open with no stop from Reya(?:: )?/;
109
+ /** Every Needs-you code reya-chain sends that has a line of its own (the rest show `needs-other`). */
110
+ exports.NEEDS_YOU_CODES = [
111
+ ...Object.keys(NEEDS_YOU),
112
+ 'outside_order',
113
+ 'liquidated',
114
+ 'account_history_incomplete',
115
+ 'margin_stall',
116
+ 'order_unanswered',
117
+ 'order_refused',
118
+ 'close_stopped_open',
119
+ 'max_loss_unreadable',
120
+ 'max_loss_paused_price',
121
+ ...Object.keys(MAX_LOSS_PAUSED),
122
+ 'close_open_2min',
123
+ ...Object.keys(exports.LINES)
124
+ .filter((k) => k.startsWith('close-reason.'))
125
+ .map((k) => k.slice('close-reason.'.length)),
126
+ ];
127
+ /** The outside causes with a line of their own; `new_order` and any other read as the base line. */
128
+ const OUTSIDE_CAUSES = new Set(['modified', 'cancelled', 'found_at_restart']);
129
+ function needsYouKey(item, status) {
130
+ const { market, rule, detail } = item;
131
+ // An overdue item reads as the order manager's cause where that has a line of its own.
132
+ const cause = item.sender_code;
133
+ const code = cause && (own(NEEDS_YOU, cause) || isCloseReason(cause))
134
+ ? cause
135
+ : item.code;
136
+ const fields = {
137
+ ...(market && { market }),
138
+ ...(rule && { rule }),
139
+ code,
140
+ };
141
+ if (code === 'max_loss_unreadable') {
142
+ for (const [pattern, key] of MAX_LOSS_DETAIL) {
143
+ const hit = detail?.match(pattern);
144
+ if (hit)
145
+ return [key, hit[1] ? { ...fields, market: hit[1] } : fields];
146
+ }
147
+ return ['needs-max-loss-paused', fields];
148
+ }
149
+ // These only explain the max-loss item on main; read alone, each is its cause's line.
150
+ if (code === 'max_loss_paused_price')
151
+ return [
152
+ market
153
+ ? 'needs-max-loss-paused.price'
154
+ : 'needs-max-loss-paused.price-any',
155
+ fields,
156
+ ];
157
+ const paused = own(MAX_LOSS_PAUSED, code);
158
+ if (paused)
159
+ return [paused, fields];
160
+ if (isCloseReason(code))
161
+ return [`close-reason.${code}`, fields];
162
+ switch (code) {
163
+ // With no cause of its own, a close open for 2 minutes reads as "nothing has filled".
164
+ case 'close_open_2min':
165
+ return ['close-reason.close_overdue', fields];
166
+ case 'margin_stall':
167
+ return item.escalated
168
+ ? ['needs-margin.in-a-row', { ...fields, n: 3 }]
169
+ : ['needs-margin', fields];
170
+ case 'order_unanswered':
171
+ return [market ? 'needs-no-answer' : 'needs-no-answer.no-market', fields];
172
+ // With an effect the exchange refused the order; without one the strategy could not build it.
173
+ case 'order_refused':
174
+ if (item.effect !== undefined && item.effect !== null)
175
+ return [
176
+ market ? 'needs-order-refused' : 'needs-order-refused.no-market',
177
+ fields,
178
+ ];
179
+ return [
180
+ market
181
+ ? 'needs-order-refused.strategy'
182
+ : 'needs-order-refused.strategy-no-market',
183
+ fields,
184
+ ];
185
+ case 'outside_order':
186
+ return [
187
+ item.cause && OUTSIDE_CAUSES.has(item.cause)
188
+ ? `needs-outside-order.${item.cause}`
189
+ : 'needs-outside-order',
190
+ fields,
191
+ ];
192
+ // Raised on carry_on (the run goes on) and when the close starts, before anything is closed.
193
+ case 'liquidated':
194
+ return [
195
+ status === 'ended'
196
+ ? 'needs-liquidation.ended'
197
+ : status === 'closing'
198
+ ? 'needs-liquidation.closing'
199
+ : status === 'running' || status === 'holding'
200
+ ? 'needs-liquidation.running'
201
+ : 'needs-liquidation',
202
+ fields,
203
+ ];
204
+ // It stays after the run ends, when nothing waits any more.
205
+ case 'account_history_incomplete':
206
+ return [
207
+ status === 'ended'
208
+ ? 'needs-history-incomplete.ended'
209
+ : 'needs-history-incomplete',
210
+ fields,
211
+ ];
212
+ case 'deleveraged':
213
+ return [
214
+ market ? 'needs-deleveraged' : 'needs-deleveraged.no-market',
215
+ fields,
216
+ ];
217
+ case 'stop_stale':
218
+ return [market ? 'why-stale' : 'why-stale.no-market', fields];
219
+ case 'execution_busted':
220
+ return [market ? 'needs-busted' : 'needs-busted.no-market', fields];
221
+ case 'unsent_at_restart':
222
+ return [market ? 'needs-unsent' : 'needs-unsent.no-market', fields];
223
+ case 'close_stopped_open': {
224
+ const left = detail?.replace(STILL_OPEN, '').trim();
225
+ return left
226
+ ? ['needs-close-stopped.detail', { ...fields, detail: left }]
227
+ : ['needs-close-stopped', fields];
228
+ }
229
+ }
230
+ return [own(NEEDS_YOU, code) ?? 'needs-other', fields];
231
+ }
232
+ /**
233
+ * The line for a Needs-you item, picked by its code. `vars` fills what the item does not carry (an
234
+ * expiry's `date`, an ended market's `question`, a rule's name as `rule`). Pass the run's `status`
235
+ * in `options`: a liquidation's line depends on it. A code this client has no line for, and
236
+ * `legacy`, show `needs-other` with the code as its reference.
237
+ */
238
+ function needsYouLine(item, vars = {}, options = {}) {
239
+ const [key, fields] = needsYouKey(item, options.status);
240
+ return forMode(line(key, { ...fields, ...vars }, options.t), options);
241
+ }
242
+ exports.needsYouLine = needsYouLine;
243
+ /** The engine's fixed reasons for a dropped entry (`runtime/step.rs`), matched exactly. */
244
+ exports.ENTRY_DROPPED = {
245
+ 'late entry': 'act-entry-skipped.late',
246
+ "missed: margin couldn't be checked": 'act-entry-skipped.margin',
247
+ 'missed: the price moved more than 25 bps since the reading': 'act-entry-skipped.price',
248
+ };
249
+ const ACTIVITY = {
250
+ start: 'act-start',
251
+ claimed: 'act-rule',
252
+ order_sent: 'act-order-sent',
253
+ settled: 'act-fill',
254
+ account_fill: 'act-account-fill',
255
+ busted: 'act-busted',
256
+ execution_unresolved: 'act-entry-held',
257
+ condition_unreadable: 'act-condition-unreadable',
258
+ already_flat: 'act-already-flat',
259
+ reduction_below_lot: 'act-reduce-below-lot',
260
+ rounds_exhausted: 'act-rounds-used',
261
+ max_loss_reached: 'act-max-loss',
262
+ expiry: 'act-expiry',
263
+ ended: 'act-ended',
264
+ odds_entry_waiting: 'odds-waiting',
265
+ deleveraged: 'act-deleveraged',
266
+ liquidation: 'act-liquidation',
267
+ position_flipped: 'act-position-flipped',
268
+ };
269
+ const EVENTS = {
270
+ stop_close: 'act-stop-close',
271
+ stop_keep: 'act-stop-keep',
272
+ external_flat: 'act-external-flat',
273
+ };
274
+ const NOTICES = {
275
+ orders_restart: 'act-orders-restart',
276
+ witness_check_order: 'act-check-order',
277
+ close_band_busted: 'act-close-band-busted',
278
+ book_refused: 'act-book-refused',
279
+ };
280
+ /**
281
+ * Activity codes with nothing to show the user: the engine's bookkeeping, a fault written beside
282
+ * the rule's own event, a fill another order owns, and moving the user's own stop into a strategy
283
+ * (not in this release).
284
+ */
285
+ exports.ACTIVITY_NOT_LISTED = [
286
+ 'clock',
287
+ 'observation',
288
+ 'protection',
289
+ 'execution',
290
+ 'account',
291
+ 'handover',
292
+ 'reconciled',
293
+ 'reconciliation_pending',
294
+ 'stale_protective_arm',
295
+ 'evaluator_fault',
296
+ 'fill_owner_conflict',
297
+ // Written beside the external_flat event, which carries the line.
298
+ 'market_left_flat',
299
+ 'stop_transferred',
300
+ 'stop_transfer_pending',
301
+ ];
302
+ /** Every activity code with a line. */
303
+ exports.ACTIVITY_CODES = [
304
+ ...Object.keys(ACTIVITY),
305
+ 'order_refused',
306
+ 'entry_dropped',
307
+ 'event',
308
+ 'order_notice',
309
+ 'needs_you_raised',
310
+ 'needs_you_updated',
311
+ 'needs_you_cleared',
312
+ ];
313
+ /**
314
+ * The line for an activity entry, picked by its code, or `null` for one with nothing to show (an
315
+ * event kind whose Needs-you item or effect carries the line, and `ACTIVITY_NOT_LISTED`). A code
316
+ * this client has no line for, and `legacy`, show `activity-other`.
317
+ */
318
+ function activityLine(entry, vars = {}, options = {}) {
319
+ const { code, reason, rule, market } = entry;
320
+ const fields = {
321
+ ...(rule && { rule }),
322
+ ...(market && { market }),
323
+ code,
324
+ ...vars,
325
+ };
326
+ const pick = (key, extra = {}) => forMode(line(key, { ...fields, ...extra }, options.t), options);
327
+ if (exports.ACTIVITY_NOT_LISTED.includes(code))
328
+ return null;
329
+ const listed = own(ACTIVITY, code);
330
+ if (listed)
331
+ return pick(listed);
332
+ switch (code) {
333
+ // With an effect the exchange refused it; without one the strategy could not build it. The
334
+ // engine's reason is diagnostic text and is not shown.
335
+ case 'order_refused':
336
+ return pick(entry.effect !== undefined && entry.effect !== null
337
+ ? 'act-order-refused'
338
+ : 'act-order-refused.strategy');
339
+ case 'entry_dropped':
340
+ return pick(own(exports.ENTRY_DROPPED, reason) ?? 'act-entry-skipped');
341
+ case 'event': {
342
+ // The engine serializes the kind as written in Rust (`StopClose`); accept both spellings.
343
+ const kind = entry.event
344
+ ?.replace(/(?<=.)[A-Z]/g, (c) => `_${c}`)
345
+ .toLowerCase();
346
+ const key = own(EVENTS, kind);
347
+ return key ? pick(key) : null;
348
+ }
349
+ case 'order_notice': {
350
+ const notice = entry.incident?.code;
351
+ return pick(own(NOTICES, notice) ?? 'activity-other', {
352
+ code: notice ?? code,
353
+ });
354
+ }
355
+ case 'needs_you_raised':
356
+ case 'needs_you_updated':
357
+ case 'needs_you_cleared': {
358
+ const item = entry.incident ?? { code: 'legacy' };
359
+ const itemLine = needsYouLine(item, vars, { t: options.t }).text;
360
+ return pick(code === 'needs_you_cleared'
361
+ ? 'act-needs-you-cleared'
362
+ : 'act-needs-you', {
363
+ line: itemLine,
364
+ });
365
+ }
366
+ }
367
+ return pick('activity-other');
368
+ }
369
+ exports.activityLine = activityLine;
370
+ const ENDED = {
371
+ own_rule: 'ended-rules',
372
+ stop_close: 'ended-stop-close',
373
+ stop_keep: 'ended-stop-keep',
374
+ max_loss: 'ended-max-loss',
375
+ expiry: 'ended-expiry',
376
+ operator: 'ended-operator',
377
+ position_flipped: 'ended-position-flipped',
378
+ liquidated: 'needs-liquidation.ended',
379
+ outside_order: 'needs-outside-order',
380
+ permission_gone: 'needs-permission',
381
+ };
382
+ /** Every end reason reya-chain sends. */
383
+ exports.END_REASONS = Object.keys(ENDED);
384
+ /**
385
+ * Why a strategy ended, by the engine's reason: for an Ended run only. The engine sets the reason
386
+ * when the run starts to end, while it is still Closing; show `status-closing` until it is Ended.
387
+ * A liquidation, an order from outside and permission gone use their Needs-you line, so one reason
388
+ * has one set of words. With no reason, or one this client does not know, `status-ended`.
389
+ */
390
+ const endedLine = (reason, t) => line(own(ENDED, reason) ?? 'status-ended', {}, t);
391
+ exports.endedLine = endedLine;
392
+ /**
393
+ * A Paper run's lasting lines, by code (reya-chain's `PaperLine`): shown for good once they happen,
394
+ * never as Needs-you items. `paper-below-zero` takes the `date`; `paper-not-closed` goes beside each
395
+ * position left open.
396
+ */
397
+ exports.PAPER_LINES = {
398
+ paper_balance_below_zero: 'paper-below-zero',
399
+ not_closed: 'paper-not-closed',
400
+ };
401
+ /** Each read-out's name, by its field in the check result (`result.readouts`). */
402
+ exports.READ_OUTS = {
403
+ 'margin_needed.total': 'read-margin',
404
+ 'margin_needed.margin': 'read-margin-engine',
405
+ 'margin_needed.fees': 'read-fees',
406
+ 'margin_needed.funding': 'read-funding',
407
+ 'margin_needed.funding_excluded': 'read-funding-excluded',
408
+ 'margin_needed.post_expiry_holding_cost': 'read-after-end',
409
+ additional_deposit_needed: 'read-deposit',
410
+ 'loops.fit_now': 'read-rounds',
411
+ /** A loop with no round count (`rounds` absent). */
412
+ 'loops.fit_now.uncounted': 'read-rounds.uncounted',
413
+ 'loops.cost_per_round': 'read-round-cost',
414
+ balance_needed: 'read-balance-all',
415
+ 'loss_at_stop.pnl': 'read-loss-at-stop',
416
+ other_markets_closed: 'read-also-closed',
417
+ worst_deployed: 'read-deployed',
418
+ 'liquidation.per_market.liq_price': 'read-liq-price',
419
+ 'liquidation.per_market.no_price.none': 'read-liq-none',
420
+ 'liquidation.per_market.no_price.underwater': 'read-liq-underwater',
421
+ 'liquidation.account_move_pct': 'read-liq-move',
422
+ orders: 'read-order',
423
+ };
424
+ const GRADES = {
425
+ exact: 'read-exact',
426
+ at_most: 'read-at-most',
427
+ at_least: 'read-at-least',
428
+ unknown: 'read-unknown',
429
+ };
430
+ /**
431
+ * A figure with its grade, which is part of what is said: "at most 106.43 USDC", "not known yet".
432
+ * `figure` is the value as the client formats it, with its unit.
433
+ */
434
+ const gradedFigure = (grade, figure, t) => line(own(GRADES, grade) ?? 'read-unknown', { figure }, t).text;
435
+ exports.gradedFigure = gradedFigure;
436
+ const WHAT_IF = {
437
+ close_and_end: 'set-liquidation',
438
+ carry_on: 'whatif-carry-on',
439
+ keep_running: 'set-margin',
440
+ stop_on_skip: 'whatif-stop-on-skip',
441
+ max_loss_close_all: 'whatif-max-loss',
442
+ expiry_hold: 'whatif-expiry',
443
+ order_refused: 'whatif-order-refused',
444
+ cancelled_at_fill: 'whatif-cancelled',
445
+ inherited_cancelled_at_fill: 'whatif-own-cancelled',
446
+ every_buy_fills: 'whatif-all-fill',
447
+ inherited_fill_moves_basis: 'whatif-own-fill-basis',
448
+ inherited_fill_outside_strategy: 'whatif-own-fill-other',
449
+ not_derived: 'whatif-not-derived',
450
+ };
451
+ const STOP_KIND = {
452
+ exchange_stop_loss: 'stop-loss',
453
+ exchange_take_profit: 'take-profit',
454
+ };
455
+ /** Every `response` reya-chain sends, `authored` included (it reads as its rule's sentence). */
456
+ exports.WHAT_IF_RESPONSES = [
457
+ ...Object.keys(WHAT_IF),
458
+ 'authored',
459
+ 'no_position_change',
460
+ 'inherited_fill_reduces',
461
+ 'exchange_stop_ends_market_part',
462
+ 'exchange_stop_outside_strategy',
463
+ 'unknown',
464
+ ];
465
+ function whatIfKey(row) {
466
+ const { response, event } = row;
467
+ if (response === 'authored')
468
+ return null;
469
+ const listed = own(WHAT_IF, response);
470
+ if (listed)
471
+ return listed;
472
+ switch (response) {
473
+ case 'no_position_change':
474
+ return event.startsWith('source_ended')
475
+ ? 'whatif-odds-ended'
476
+ : 'whatif-odds-unreadable';
477
+ case 'inherited_fill_reduces':
478
+ return row.basis_after
479
+ ? 'whatif-own-fill-reduces.basis'
480
+ : 'whatif-own-fill-reduces';
481
+ case 'exchange_stop_ends_market_part':
482
+ case 'exchange_stop_outside_strategy': {
483
+ const kind = own(STOP_KIND, event) ?? 'stop-loss';
484
+ const base = response === 'exchange_stop_ends_market_part'
485
+ ? 'whatif-own-stop'
486
+ : 'whatif-own-stop-other';
487
+ return `${base}.${kind}`;
488
+ }
489
+ }
490
+ return 'whatif-unknown.plain';
491
+ }
492
+ /**
493
+ * The line for a "what happens if" row, picked by its `response`, or `null` for `authored`: that
494
+ * row reads as its rule's own sentence (`sentences(doc)[row.rule]`). `vars` holds the figures as the
495
+ * client formats them (`needed`, `have`, `basis`) and an odds row's `question`. An unknown row reads
496
+ * "{its event's 'If …' words}: not known yet." On a Paper run the liquidation row reads
497
+ * `paper-no-liquidation`.
498
+ */
499
+ function whatIfLine(row, vars = {}, { t, mode } = {}) {
500
+ const fields = {
501
+ ...(row.market && { market: row.market }),
502
+ ...vars,
503
+ };
504
+ if (row.response === 'unknown') {
505
+ const ifKey = `whatif-if.${row.event}`;
506
+ if (own(exports.LINES, ifKey) === undefined)
507
+ return line('whatif-unknown.plain', fields, t);
508
+ return line('whatif-unknown', { if: line(ifKey, fields, t).text }, t);
509
+ }
510
+ // A Paper run has no liquidation, whatever the setting says.
511
+ if (mode === 'paper' && row.event === 'liquidation')
512
+ return line('paper-no-liquidation', fields, t);
513
+ const key = whatIfKey(row);
514
+ return key && line(key, fields, t);
515
+ }
516
+ exports.whatIfLine = whatIfLine;
@@ -0,0 +1,287 @@
1
+ {
2
+ "start-1": "This strategy takes over what the account already holds: {held}.",
3
+ "start-1.empty": "This strategy takes over whatever the account holds at Start. It holds nothing now.",
4
+ "start-2": "Its result counts from the prices at Start.",
5
+ "start-3": "Stop and close, max loss, and a liquidation close everything on the account.",
6
+ "start-3.listed": "Stop and close, max loss, and a liquidation close everything on the account, {positions} included.",
7
+ "start-4": "No trading by hand on this account while the strategy is live. Use another account, or stop it first.",
8
+ "start-5": "One Live strategy per account.",
9
+ "start-6": "Any of these ends the strategy: a new order on this account, changing or cancelling its orders or the ones it took over, cancelling or moving your own exchange stop, a cancel-all, or a cancel-all-after timer.",
10
+ "end-date-default": "It ends on {date}, the default end date. Renewing is not available yet.",
11
+ "hold-cancels": "When it reaches Holding, it cancels every order, its own or taken over, that would add to a position, and keeps the ones that reduce.",
12
+ "start-now-unknown": "Whether this condition is already true can't be checked right now. If you start, it waits for the next crossing.",
13
+ "set-liquidation": "If the account is liquidated: everything left is closed and the strategy ends.",
14
+ "set-margin": "If an order does not fit the margin: it is skipped, the strategy is marked Needs-you, and it tries again on the next trigger.",
15
+ "stop-gap": "Your stops are run by Reya's service, not the exchange. They pause for a short time when Reya updates the service, and for as long as an outage lasts.",
16
+ "stop-service": "They normally fire within seconds of the level. When many stops fire at once, or the exchange is overloaded, a stop can take longer; the close keeps trying, and you get a Needs-you if it is still open after 2 minutes.",
17
+ "stop-fill": "A fast move can fill worse than this.",
18
+ "stop-liquidation-margin": "Below the account's liquidation margin the exchange refuses every order, so a strategy stop cannot fire there.",
19
+ "pause": "There is no pause. To pause: Stop, keep positions, then Start again. While it is stopped the positions have no stop from us, and the result and max loss start again from zero.",
20
+ "stops-paused-app": "Reya's service can't be reached, so your strategy's stops aren't running.",
21
+ "close-by-hand.unreachable": "Reya's service can't be reached, so your strategy's stops aren't running. Closing by hand ends the strategy and keeps your other positions.",
22
+ "close-by-hand.paused": "Your strategy's stops are paused while Reya's service recovers. Closing by hand ends the strategy and keeps your other positions.",
23
+ "warn-no-max-loss": "Running without a max loss is not recommended.",
24
+ "warn-max-loss-liquidation": "Set a lower max loss, or make the position smaller.",
25
+ "warn-held": "Max loss counts them too: a loss on {list} alone can hit it and close everything.",
26
+ "warn-outside-exit": "Add a price stop or a time exit.",
27
+ "refuse-stop-side": "For a long, a stop-loss goes below the price and a take-profit above. For a short, the other way round.",
28
+ "refuse-stop-entry": "For a long, a stop-loss goes below the price and a take-profit above. For a short, the other way round.",
29
+ "refuse-second-live": "Use another account, or stop it first.",
30
+ "refuse-manual-order": "This account runs {strategy}. No order, cancel or stop change by hand while it is live. Trade from another account, or stop the strategy first.",
31
+ "refuse-limit-far": "A resting order has to sit within {pct}% of the current price, or the exchange refuses it. To trade further away, use a rule that waits for the price.",
32
+ "refuse-odds-off": "To start it, take out the rules that read prediction odds.",
33
+ "refuse-edit": "Editing a running strategy is not available yet.",
34
+ "why-not-reached": "The stop is at {level}. The mark is {mark} as of {time}. It has not been reached.",
35
+ "why-stale": "Your stop can't be watched: the price for {market} is stale. It is checked on the first fresh price.",
36
+ "why-stale.no-market": "Your stop can't be watched: its price is stale. It is checked on the first fresh price.",
37
+ "why-refused": "The stop fired at {time}. The close order was refused: {reason}. It keeps trying.",
38
+ "why-rate-limit": "The stop fired at {time}. The close is held back by the exchange's rate limit.",
39
+ "why-close-open": "The stop fired at {time}. The close is still open: {reason}.",
40
+ "why-odds": "The odds for this market can't be read, so an exit that waits on them can't fire on the odds. It still fires if another of its conditions is met.",
41
+ "why-no-stop": "{market} has no stop from this strategy.",
42
+ "why-nothing": "The strategy's record has no event that explains it. The stop is at {level}; the mark is {mark} as of {time}.",
43
+ "size-from-share": "{pct}% of your balance is {amount} USDC today, so each order is {amount} USDC.",
44
+ "feature-unavailable": "{asked} is not available in strategies.",
45
+ "pin-question": "Which prediction market should this read?",
46
+ "pin-source": "Polymarket, as of {time} UTC",
47
+ "pin-option": "{outcome} · {pct}% now · listed end {date}",
48
+ "pin-thin": " · thin market: ${volume} traded in 24h, ${depth} near the price",
49
+ "pin-past-end.option": " · past its end date, waiting to be resolved",
50
+ "pin-none": "None of these",
51
+ "pin-answer": "Market {n}.",
52
+ "pin-answer.none": "None of these.",
53
+ "pin-left-out": "Left out: \"{question}\". {reason}",
54
+ "pin-label": "Reads Polymarket: \"{question}\" · {outcome} · listed end {date}",
55
+ "pin-past-end": "This market is past its end date and waiting to be resolved. When Polymarket closes it, the rules that read it stop and you get a Needs-you.",
56
+ "pin-ends-early": "This market's listed end date is before your strategy's. When Polymarket closes it, the rules that read it stop and you get a Needs-you.",
57
+ "warn-thin": "\"{question}\" is thinly traded right now: ${depth} near the price. A small trade there can push the odds across your level for a moment, and your rule would fire on it.",
58
+ "odds-can-thin": "A market can turn thin while the strategy runs. Its odds are still used while they pass the liquidity checks.",
59
+ "odds-checks-reya": "The liquidity checks on prediction odds are Reya's and can change while a strategy runs.",
60
+ "odds-no-history": "This strategy reads prediction odds, which are not stored: there is no past-price check and no backtest for it.",
61
+ "odds-jump": "If the odds jump past your level in one move, an entry on that crossing can be missed. An exit still fires on the next usable reading.",
62
+ "odds-band": "After a rule on an odds crossing fires, it can fire again only once the odds have gone back {band} points past its level.",
63
+ "odds-band-once.above": "A rule that fires when the odds cross above {level}% fires at most once: the odds can't go back {band} points past that level. For it to fire again, give a smaller band.",
64
+ "odds-band-once.below": "A rule that fires when the odds cross below {level}% fires at most once: the odds can't go back {band} points past that level. For it to fire again, give a smaller band.",
65
+ "odds-waiting": "waiting: odds unavailable",
66
+ "odds-first-reading": "waiting for a first reading",
67
+ "needs-odds-ended": "The prediction market \"{question}\" has ended. Its odds will not be read again, so a rule that waits on them will not fire.",
68
+ "pin-changed": "This market's wording or end date changed at Polymarket. Confirm it again.",
69
+ "pin-closed": "This market has closed.",
70
+ "pin-unusable": "This market is too thinly traded to use in a strategy right now.",
71
+ "pin-long-shot": "This market's odds are now under 2% or over 98%, so it can't be used in a strategy right now.",
72
+ "pin-not-live": "This outcome is not live at Polymarket, so it can't be used in a strategy.",
73
+ "pin-no-end-date": "This market lists no end date, so it can't be used in a strategy.",
74
+ "pin-text-unsafe.too-long": "This market's question or outcome name is too long to use in a strategy. Its odds can still be quoted.",
75
+ "pin-text-unsafe.address": "This market's wording contains what reads as a web address or a wallet address, so it can't be used in a strategy. Its odds can still be quoted.",
76
+ "pin-text-unsafe.characters": "This market's wording contains a hidden or look-alike character, so it can't be used in a strategy. Its odds can still be quoted.",
77
+ "pin-text-unsafe.spacing": "This market's wording has unusual spacing (extra spaces or a line break), so it can't be used in a strategy. Its odds can still be quoted.",
78
+ "pin-unreadable": "Prediction-market data can't be read right now.",
79
+ "status-running": "Running: the strategy is active.",
80
+ "status-closing": "Closing: a close is in progress. It keeps trying until the account is flat.",
81
+ "status-holding": "Holding: a position is held. Nothing new will be entered. Its stops and its other exits still run.",
82
+ "status-ended": "Ended: nothing more will happen. The account is yours again.",
83
+ "stop-close": "Stop and close: cancels every resting order on the account, closes every position on it and ends the strategy.",
84
+ "stop-keep": "Stop, keep positions: cancels the strategy's own resting orders and stops and ends the strategy. The positions stay open as yours, with no stop-loss from us. A stop you placed on the exchange yourself stays in place.",
85
+ "stop-closing": "A close is in progress. Stop, keep positions stops it: what is still open stays open as yours, with no stop-loss from us.",
86
+ "max-loss-closing": "Max loss is closing every position. If it stalls for 2 minutes, you can take over.",
87
+ "max-loss-take-over": "Close still open: {reason}. Take over: stop closing and keep what's left.",
88
+ "stop-list-unavailable": "This list can't be loaded right now. Stop still works.",
89
+ "catching-up": "Catching up after a restart. New entries wait until the account's orders have been checked.",
90
+ "ended-rules": "Ended by its own rules.",
91
+ "ended-stop-close": "Stopped with Stop and close.",
92
+ "ended-stop-keep": "Stopped with Stop, keep positions.",
93
+ "ended-max-loss": "Ended at max loss. Everything on the account was closed.",
94
+ "ended-expiry": "Ended after its end date.",
95
+ "ended-operator": "Reya's team ended this strategy after a fault it could not recover from. Nothing was cancelled or closed: your positions and orders are as they were, with no stop-loss from us.",
96
+ "ended-position-flipped": "Ended: an order the strategy did not send turned a position to the other side while a stop was closing it. Your positions are open, with no stop-loss from us.",
97
+ "row-not-traded": "not traded by this strategy",
98
+ "row-no-stop": "not covered by any stop",
99
+ "row-rate-limit": "held back by the exchange's rate limit",
100
+ "row-missed": "missed: too late",
101
+ "needs-permission": "Reya can no longer trade for this account. Your positions are open with no stop.",
102
+ "needs-outside-order": "An order placed outside the strategy ended it. Your positions are open, with no stop-loss from us.",
103
+ "needs-outside-order.modified": "An order was changed outside the strategy, which ended it. Your positions are open, with no stop-loss from us.",
104
+ "needs-outside-order.cancelled": "An order was cancelled outside the strategy, which ended it. Your positions are open, with no stop-loss from us.",
105
+ "needs-outside-order.found_at_restart": "A change made outside the strategy was found after a restart, which ended it. Your positions are open, with no stop-loss from us.",
106
+ "needs-liquidation": "The account was liquidated.",
107
+ "needs-liquidation.running": "The account was liquidated. The strategy carries on with what is left.",
108
+ "needs-liquidation.closing": "The account was liquidated. Reya is closing what is left; the strategy then ends.",
109
+ "needs-liquidation.ended": "The account was liquidated. Everything left was closed and the strategy ended.",
110
+ "needs-deleveraged": "The exchange cut your {market} position to cover another account's liquidation. The strategy carries on with what is left.",
111
+ "needs-deleveraged.no-market": "The exchange cut a position to cover another account's liquidation. The strategy carries on with what is left.",
112
+ "needs-margin": "An order did not fit the margin and was skipped. It tries again on the next trigger.",
113
+ "needs-margin.in-a-row": "An order did not fit the margin and was skipped: {n} in a row. It tries again on the next trigger.",
114
+ "needs-no-answer": "No new orders on {market} until the exchange shows what happened to this order. A stop on this market is not held back.",
115
+ "needs-no-answer.no-market": "No new orders until the exchange shows what happened to this order. A stop is not held back.",
116
+ "needs-no-answer-team": "An order has no answer. Reya's team is checking it.",
117
+ "needs-dropped": "Three entries in a row were missed.",
118
+ "needs-expiry": "This strategy expires on {date}. It then stops entering and holds its position. Its stops and its other exits still run.",
119
+ "needs-max-loss-paused.price": "Max loss is paused: the price for {market} is stale.",
120
+ "needs-max-loss-paused.price-any": "Max loss is paused: a market's price is stale.",
121
+ "needs-max-loss-paused.account": "Max loss is paused: Reya's account data is behind.",
122
+ "needs-max-loss-paused.funding": "Max loss is paused: funding data is behind.",
123
+ "needs-max-loss-paused.error": "Max loss is paused: its figures can't be read.",
124
+ "needs-max-loss-paused": "Max loss is paused: it can't be checked right now.",
125
+ "needs-order-refused": "The exchange refused an order on {market}.",
126
+ "needs-order-refused.no-market": "The exchange refused an order.",
127
+ "needs-order-refused.strategy": "The strategy could not place an order on {market}.",
128
+ "needs-order-refused.strategy-no-market": "The strategy could not place an order.",
129
+ "needs-busted": "A fill on {market} did not settle and was undone. The order counts as refused.",
130
+ "needs-busted.no-market": "A fill did not settle and was undone. The order counts as refused.",
131
+ "needs-unsent": "An order on {market} was not sent: the service restarted first.",
132
+ "needs-unsent.no-market": "An order was not sent: the service restarted first.",
133
+ "needs-rule-unreadable": "A rule can't be checked right now: {rule}",
134
+ "needs-engine-limit": "The strategy hit an internal limit and stopped part-way through a step. Reference: {code}.",
135
+ "needs-account-suspended": "The exchange has suspended new orders on this account.",
136
+ "needs-stops-paused": "Stops are paused while Reya's service recovers.",
137
+ "needs-unprotected": "This position has no stop from Reya right now.",
138
+ "needs-stop-slower": "A stop can take longer.",
139
+ "needs-orders-paused": "Reya has paused new orders.",
140
+ "needs-market-data": "Waiting: market data unavailable.",
141
+ "needs-cancel-left": "An order Reya cancelled is still on the exchange.",
142
+ "needs-round-unknown": "A round's result couldn't be read: it counts as neither a win nor a loss.",
143
+ "needs-feature-off": "A feature this strategy uses has been switched off. Nothing new is entered until it is back.",
144
+ "needs-close-stopped": "The close stopped. Still open with no stop from Reya.",
145
+ "needs-close-stopped.detail": "The close stopped. Still open with no stop from Reya: {detail}.",
146
+ "needs-position-unreadable": "Your stop can't be watched: Reya can't read the position right now.",
147
+ "needs-cancels-pending": "The strategy is ending and has waited 2 minutes for its cancels to go through.",
148
+ "needs-history-incomplete": "Reya can't confirm this account's history right now, so nothing new is entered and max loss waits. Its stops and exits still run.",
149
+ "needs-history-incomplete.ended": "Reya can't confirm this account's history right now.",
150
+ "needs-cancel-refused": "The exchange refused a cancel Reya sent for the close.",
151
+ "needs-orders-unreadable": "Reya can't read a stored order, so it set this strategy's orders aside. Reya's team is checking it.",
152
+ "needs-other": "This strategy needs your attention. Reference: {code}.",
153
+ "close-reason.close_open_halted": "Close still open: halted market",
154
+ "close-reason.close_open_no_liquidity": "Close still open: no liquidity within the market's band",
155
+ "close-reason.close_open_margin": "Close still open: refused for margin",
156
+ "close-reason.close_open_overloaded": "Close still open: the exchange is shedding load",
157
+ "close-reason.close_open_refused": "Close still open: order refused",
158
+ "close-reason.close_open_band_unknown": "Close still open: Reya can't read this market's price limits",
159
+ "close-reason.band_copy_invalid": "Close still open: Reya can't read this market's price limits",
160
+ "close-reason.close_open_permission_check": "Close still open: checking whether Reya can still trade for this account",
161
+ "close-reason.close_open_position_unknown": "Close still open: Reya can't read this account's position right now",
162
+ "close-reason.close_open_entry_settlement": "Close still open: waiting for the entry to settle",
163
+ "close-reason.close_open_paused": "Close still open: the exchange isn't taking orders on this market right now",
164
+ "close-reason.close_settling_stuck": "Close still open: waiting for the exchange to settle a fill",
165
+ "close-reason.close_price_out_of_range": "Close still open: its limit price is outside the exchange's price range",
166
+ "close-reason.late_fill_closed": "Close still open: a late fill brought the position back",
167
+ "close-reason.close_overdue": "Close still open: nothing has filled for 2 minutes",
168
+ "close-reason.close_parent_held": "Close still open: waiting for its cancels or another market's close",
169
+ "close-reason.rate_limited": "Close still open: held back by the exchange's rate limit",
170
+ "act-start": "Strategy started.",
171
+ "act-rule": "Rule fired: {rule}",
172
+ "act-order-sent": "Order sent.",
173
+ "act-fill": "Fill received.",
174
+ "act-account-fill": "Fill on the account.",
175
+ "act-busted": "A fill did not settle and was undone.",
176
+ "act-order-refused": "The exchange refused an order.",
177
+ "act-order-refused.strategy": "The strategy could not place an order.",
178
+ "act-entry-skipped.late": "Entry skipped: it came too late.",
179
+ "act-entry-skipped.margin": "Entry missed: the margin couldn't be checked.",
180
+ "act-entry-skipped.price": "Entry missed: the price moved more than 25 bps after the reading.",
181
+ "act-entry-skipped": "Entry skipped.",
182
+ "act-entry-held": "Entry not placed: an earlier order on this market has not finished.",
183
+ "act-condition-unreadable": "Rule not acted on, because its condition could not be read: {rule}",
184
+ "act-already-flat": "Nothing to close: the position was already closed.",
185
+ "act-reduce-below-lot": "A reduce was not sent: it was smaller than the market's smallest order step.",
186
+ "act-rounds-used": "All rounds used.",
187
+ "act-max-loss": "Max loss reached.",
188
+ "act-expiry": "End date reached. Nothing new will be entered. Positions are held; their stops and other exits still run.",
189
+ "act-ended": "Strategy ended.",
190
+ "act-needs-you": "Needs you: {line}",
191
+ "act-needs-you-cleared": "Cleared: {line}",
192
+ "act-stop-close": "Stop and close requested.",
193
+ "act-stop-keep": "Stop, keep positions requested.",
194
+ "act-external-flat": "A position was closed by an order the strategy did not send.",
195
+ "act-deleveraged": "The exchange cut a position to cover another account's liquidation.",
196
+ "act-liquidation": "The exchange started a liquidation on the account.",
197
+ "act-position-flipped": "An order the strategy did not send turned a position to the other side while a stop was closing it.",
198
+ "act-orders-restart": "Reya's order service restarted and picked up its orders again.",
199
+ "act-check-order": "Reya placed and cancelled a check order (1 lot, far from the price) to confirm an earlier order did not go through.",
200
+ "act-close-band-busted": "The exchange undid a close fill for the market's price band. Reya's team is checking it.",
201
+ "act-book-refused": "An order was not sent: Reya's sender does not sign for it. Reya's team is checking it.",
202
+ "activity-other": "An event this version has no description for. Reference: {code}.",
203
+ "read-margin": "Margin needed",
204
+ "read-margin-engine": "Margin at the tightest point",
205
+ "read-fees": "Fees, at the highest taker rate",
206
+ "read-funding": "Funding until the end date",
207
+ "read-funding-excluded": "Funding is not included: no rule closes the position by a set time.",
208
+ "read-after-end": "A position can stay open after the end date. The cost of holding it then is not counted.",
209
+ "read-deposit": "More to deposit",
210
+ "read-rounds": "Rounds that fit now: {n} of {rounds}",
211
+ "read-rounds.uncounted": "Rounds that fit now: {n}",
212
+ "read-round-cost": "Cost of one round",
213
+ "read-balance-all": "Balance at which every round fits",
214
+ "read-loss-at-stop": "Loss at your stop level, {market}",
215
+ "read-also-closed": "Stop and close also closes: {markets}",
216
+ "read-deployed": "Largest position open at once",
217
+ "read-liq-price": "Liquidation price, {market}",
218
+ "read-liq-none": "{market}: a move in this market alone can't liquidate the account.",
219
+ "read-liq-underwater": "{market}: the account is already past its liquidation point.",
220
+ "read-liq-move": "Liquidation is {pct}% away, nearest on {market}",
221
+ "read-order": "{quantity} {market}, max slippage {bound} bps: worst price {price} now",
222
+ "read-exact": "{figure}",
223
+ "read-at-most": "at most {figure}",
224
+ "read-at-least": "at least {figure}",
225
+ "read-unknown": "not known yet",
226
+ "whatif-max-loss": "If the loss reaches max loss: everything on the account is closed and the strategy ends.",
227
+ "whatif-expiry": "At the end date: nothing new is entered. Positions are held; their stops and other exits still run.",
228
+ "whatif-odds-unreadable": "If the odds for \"{question}\" can't be read: no rule answers it, so nothing changes and no position is closed.",
229
+ "whatif-odds-ended": "If the market \"{question}\" ends: no rule answers it, so nothing changes and no position is closed.",
230
+ "whatif-order-refused": "If the exchange refuses an order: it shows as refused, and nothing else changes unless a rule answers it.",
231
+ "whatif-cancelled": "If the exchange cancels this resting order when it would fill: what is left of it never fills, its round still counts, and it is not placed again.",
232
+ "whatif-own-cancelled": "If the exchange cancels your own resting order on {market} when it would fill: what is left of it never fills. The strategy does not place it again.",
233
+ "whatif-all-fill": "If every order that adds to a position fills: it needs {needed} of margin. The account has {have}.",
234
+ "whatif-own-stop.stop-loss": "If your exchange stop-loss on {market} fires: the exchange closes your whole {market} position, the strategy's part included, and the strategy's {market} part ends.",
235
+ "whatif-own-stop.take-profit": "If your exchange take-profit on {market} fires: the exchange closes your whole {market} position, the strategy's part included, and the strategy's {market} part ends.",
236
+ "whatif-own-stop-other.stop-loss": "If your exchange stop-loss on {market} fires: the exchange closes that position and the strategy carries on.",
237
+ "whatif-own-stop-other.take-profit": "If your exchange take-profit on {market} fires: the exchange closes that position and the strategy carries on.",
238
+ "whatif-own-fill-basis": "If your own resting order on {market} fills: the strategy's entry price on {market} moves to {basis}, and the levels set from the entry move with it.",
239
+ "whatif-own-fill-reduces": "If your own resting order on {market} fills: the {market} position gets smaller and its entry price stays.",
240
+ "whatif-own-fill-reduces.basis": "If your own resting order on {market} fills: the {market} position gets smaller and its entry price stays at {basis}.",
241
+ "whatif-own-fill-other": "If your own resting order on {market} fills: your {market} position changes. The strategy does not read that market.",
242
+ "whatif-carry-on": "If the account is liquidated: the strategy carries on with what is left.",
243
+ "whatif-stop-on-skip": "If an order does not fit the margin: the strategy stops.",
244
+ "whatif-unknown": "{if}: not known yet.",
245
+ "whatif-unknown.plain": "What happens here is not known yet.",
246
+ "whatif-if.exchange_stops": "If one of your exchange stops fires",
247
+ "whatif-if.every_buy_fills": "If every order that adds to a position fills",
248
+ "whatif-if.inherited_fill": "If one of your own resting orders fills",
249
+ "whatif-if.cancelled_at_fill": "If the exchange cancels one of your own resting orders when it would fill",
250
+ "whatif-not-derived": "What happens here could not be worked out.",
251
+ "paper-what": "Paper places no real orders. Fills are simulated at the mark, with the assumed slippage, the fee at the run's fee tier, and funding charged.",
252
+ "paper-optimistic": "Paper fills at the mark; a real order can fill worse.",
253
+ "paper-start-empty": "This Paper run starts with no positions.",
254
+ "paper-start-empty.held": "This Paper run starts with no positions. Paper margin ignores the account's positions, where Live would take them over.",
255
+ "paper-start-copy": "Paper started from your account's positions: {positions}. Not copied: {left}.",
256
+ "paper-margin.set": "Paper margin: {amount} USDC, set by you.",
257
+ "paper-margin.balance": "Paper margin: your balance at Start, {amount} USDC.",
258
+ "paper-balance-ask": "This account holds no funds. What paper balance, in USDC, should this Paper run check its margin against?",
259
+ "paper-costs": "Assumed slippage {bps} bps, {slippage}. Fees: {tier}, {fee}.",
260
+ "paper-costs.slippage-set": "set by you",
261
+ "paper-costs.slippage-default": "the default",
262
+ "paper-costs.fee-current": "your current rate",
263
+ "paper-costs.fee-set": "set by you",
264
+ "paper-costs.fee-standard": "the standard rate, before discounts",
265
+ "paper-no-liquidation": "Paper has no liquidation: nothing forces a Paper position closed. If the paper margin runs out, new orders are skipped and exits keep running.",
266
+ "paper-live-refuses": "Live would refuse this.",
267
+ "paper-prefix": "Paper: {line}",
268
+ "paper-below-zero": "The paper balance went below zero on {date}. A Live account would have been liquidated before this, so results after it are not realistic.",
269
+ "paper-not-closed": "not closed: valued at the last price",
270
+ "paper-to-live": "Going Live runs every check again on your real account, counting what it holds. The assumed slippage and fee tier no longer apply: Live uses real fees and real fills.",
271
+ "paper-stop": "Stop closes this Paper run's positions at simulated prices, with fees and the assumed slippage, and ends it. Nothing on your real account changes.",
272
+ "paper-stop-stalled": "Nothing has filled for 2 minutes. Stop ends this Paper run now, and what is left is valued at the last price.",
273
+ "paper-unavailable": "Paper is not available for this strategy yet. Start on the card starts it Live, with real orders.",
274
+ "paper-cutover": "Paper now charges fees, an assumed slippage and funding, as Live does, so a Paper result will look lower than before.",
275
+ "refuse-paper-keep": "A Paper run can't be stopped with its positions kept: nobody could close them afterwards. Stop closes them.",
276
+ "refuse-paper-limit": "Stop one to start another.",
277
+ "refuse-paper-limit.fallback": "This account already has {n} active Paper runs, the most allowed. Stop one to start another.",
278
+ "refuse-paper-slippage": "Set a lower assumed slippage.",
279
+ "v2-card": "This was made on the previous version of strategies and can't be started.",
280
+ "v2-run-gone": "This strategy ran on the previous version and is no longer shown.",
281
+ "v2-closing-notice.close": "Strategies move to a new version on {date}. A strategy still running then is stopped and its positions closed.",
282
+ "v2-closing-notice.keep": "Strategies move to a new version on {date}. A strategy still running then is stopped and its positions stay open as yours, with no stop-loss from us.",
283
+ "card-unavailable": "I can't prepare the strategy card right now. The team has been alerted. Your draft is saved, so try again shortly.",
284
+ "step-building": "Building your strategy…",
285
+ "renewal-unavailable": "Renewing a strategy is not available yet.",
286
+ "no-history-release": "There is no past-price check or backtest in this release."
287
+ }
package/dist/sentences.js CHANGED
@@ -49,7 +49,9 @@ class Builder {
49
49
  }
50
50
  for (const [id, pin] of Object.entries(doc.series ?? {})) {
51
51
  this.lines[id] = this.f('pin.line', {
52
- pin: this.pin(pin),
52
+ // The question is in quotes, the outcome is not: only the question is escaped.
53
+ outcome: pin.label.outcome,
54
+ question: quoted(pin.label.question),
53
55
  ends: this.time(pin.label.ends),
54
56
  });
55
57
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reyaxyz/strategy-format",
3
- "version": "0.2.0",
4
- "description": "The v3 strategy format for TypeScript: reya-chain's schema and accepted kinds, the reader, the version hash and the block sentences",
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
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "registry": "https://registry.npmjs.org"
@@ -41,5 +41,5 @@
41
41
  "devDependencies": {
42
42
  "typescript": "5.3.3"
43
43
  },
44
- "gitHead": "2ff1e7a9fdef7526d88ba428b6a1b63559749fe0"
44
+ "gitHead": "a9ea58ff44b41c862a7ce23bc69fa9d977242f0d"
45
45
  }