@vordium/sdk 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +109 -2
- package/dist/cjs/account.js +126 -0
- package/dist/cjs/agents.js +237 -0
- package/dist/cjs/client.js +526 -0
- package/dist/cjs/domains.js +37 -0
- package/dist/cjs/errors.js +39 -0
- package/dist/cjs/feeds.js +278 -0
- package/dist/cjs/http.js +97 -0
- package/dist/cjs/index.js +37 -0
- package/dist/cjs/network.js +114 -0
- package/dist/cjs/nonce.js +36 -0
- package/dist/cjs/orders.js +260 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/reads.js +121 -0
- package/dist/cjs/rounding.js +252 -0
- package/dist/cjs/sign.js +49 -0
- package/dist/cjs/types.js +57 -0
- package/dist/cjs/units.js +78 -0
- package/dist/esm/account.d.ts +61 -0
- package/dist/esm/account.js +114 -0
- package/dist/esm/agents.d.ts +71 -0
- package/dist/esm/agents.js +225 -0
- package/dist/esm/client.d.ts +239 -0
- package/dist/esm/client.js +520 -0
- package/dist/esm/domains.d.ts +21 -0
- package/dist/esm/domains.js +30 -0
- package/dist/esm/errors.d.ts +18 -0
- package/dist/esm/errors.js +32 -0
- package/dist/esm/feeds.d.ts +97 -0
- package/dist/esm/feeds.js +267 -0
- package/dist/esm/http.d.ts +24 -0
- package/dist/esm/http.js +93 -0
- package/dist/esm/index.d.ts +15 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/network.d.ts +44 -0
- package/dist/esm/network.js +107 -0
- package/dist/esm/nonce.d.ts +15 -0
- package/dist/esm/nonce.js +31 -0
- package/dist/esm/orders.d.ts +141 -0
- package/dist/esm/orders.js +238 -0
- package/dist/esm/reads.d.ts +59 -0
- package/dist/esm/reads.js +113 -0
- package/dist/esm/rounding.d.ts +70 -0
- package/dist/esm/rounding.js +229 -0
- package/dist/esm/sign.d.ts +27 -0
- package/dist/esm/sign.js +43 -0
- package/dist/esm/types.d.ts +41 -0
- package/dist/esm/types.js +51 -0
- package/dist/esm/units.d.ts +16 -0
- package/dist/esm/units.js +70 -0
- package/package.json +53 -4
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rising millisecond nonces. The chain admits an account's batch nonces, client nonces and dead-man-switch nonces
|
|
3
|
+
* through ONE window (milliseconds, within 2 days before / 1 day after block time, each used once), so a client takes
|
|
4
|
+
* them all from one clock per account: never the same twice, never below the wall clock.
|
|
5
|
+
*/
|
|
6
|
+
export class NonceClock {
|
|
7
|
+
now;
|
|
8
|
+
last = 0;
|
|
9
|
+
constructor(now = Date.now) {
|
|
10
|
+
this.now = now;
|
|
11
|
+
}
|
|
12
|
+
next(atLeast = 0) {
|
|
13
|
+
this.last = Math.max(Math.floor(this.now()), this.last + 1, Math.floor(atLeast));
|
|
14
|
+
return this.last;
|
|
15
|
+
}
|
|
16
|
+
/** Note a nonce the chain already holds, so the next one is above it. */
|
|
17
|
+
seen(nonce) {
|
|
18
|
+
this.last = Math.max(this.last, Math.floor(nonce));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const clocks = new Map();
|
|
22
|
+
/** The one nonce clock of `owner` in this process. */
|
|
23
|
+
export function nonceClock(owner) {
|
|
24
|
+
const k = owner.toLowerCase();
|
|
25
|
+
let c = clocks.get(k);
|
|
26
|
+
if (!c) {
|
|
27
|
+
c = new NonceClock();
|
|
28
|
+
clocks.set(k, c);
|
|
29
|
+
}
|
|
30
|
+
return c;
|
|
31
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { type PairSpec } from './rounding.js';
|
|
2
|
+
/**
|
|
3
|
+
* Orders on the Vordex central limit order book.
|
|
4
|
+
*
|
|
5
|
+
* Units — signed fields use two scales: prices are 8-decimal integers (`price8`), sizes 18-decimal integers (`size18`).
|
|
6
|
+
* The chain keeps a limit price at 6 decimals, so a signed price must be a multiple of 100.
|
|
7
|
+
*
|
|
8
|
+
* Single orders (`/order/place`) carry `side` and `orderType` by NAME ("buy"/"sell"; "Market"/"Limit", case-sensitive)
|
|
9
|
+
* and the limit price as a decimal number; the signed digest carries the numbers. Stop orders are not available.
|
|
10
|
+
*/
|
|
11
|
+
export declare const SIDE: {
|
|
12
|
+
readonly buy: 0;
|
|
13
|
+
readonly sell: 1;
|
|
14
|
+
};
|
|
15
|
+
export declare const ORDER_TYPE: {
|
|
16
|
+
readonly Market: 0;
|
|
17
|
+
readonly Limit: 1;
|
|
18
|
+
};
|
|
19
|
+
export type Side = keyof typeof SIDE;
|
|
20
|
+
export type OrderType = keyof typeof ORDER_TYPE;
|
|
21
|
+
export declare const PRICE_DECIMALS = 8;
|
|
22
|
+
export declare const SIZE_DECIMALS = 18;
|
|
23
|
+
export declare const PRICE_STEP_8DEC = 100n;
|
|
24
|
+
export declare const STOP_REFUSAL = "Stop orders are not available: set a take-profit or stop-loss on the position instead.";
|
|
25
|
+
/** A limit price as signed: at most 6 decimals (the precision the chain keeps), as the 8-decimal integer. */
|
|
26
|
+
export declare function limitPrice8(price: string | number): bigint;
|
|
27
|
+
export declare function size18(size: string | number): bigint;
|
|
28
|
+
/** Leverage as basis points, exactly from its decimal form (10x = 100000). */
|
|
29
|
+
export declare function leverageBps(leverage: number | string): number;
|
|
30
|
+
export interface PlaceOrderValue {
|
|
31
|
+
owner: string;
|
|
32
|
+
pairId: number;
|
|
33
|
+
side: number;
|
|
34
|
+
size: bigint;
|
|
35
|
+
price: bigint;
|
|
36
|
+
leverageBps: number;
|
|
37
|
+
orderType: number;
|
|
38
|
+
reduceOnly: boolean;
|
|
39
|
+
postOnly: boolean;
|
|
40
|
+
triggerPrice8dec: bigint;
|
|
41
|
+
triggerDir: number;
|
|
42
|
+
clientNonce: number;
|
|
43
|
+
}
|
|
44
|
+
export interface OrderInput {
|
|
45
|
+
owner: string;
|
|
46
|
+
pairId: number;
|
|
47
|
+
side: Side;
|
|
48
|
+
/** Decimal size in the market's base unit, e.g. "0.05" (a bigint is a whole number of the base unit). */
|
|
49
|
+
size: string | number | bigint;
|
|
50
|
+
orderType: OrderType;
|
|
51
|
+
/** Decimal limit price; required for Limit, refused for Market. */
|
|
52
|
+
price?: string | number | bigint;
|
|
53
|
+
leverage?: number | string;
|
|
54
|
+
reduceOnly?: boolean;
|
|
55
|
+
postOnly?: boolean;
|
|
56
|
+
clientNonce: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The signed PlaceOrder value. Refuses stop orders, a priced market order and an unpriced limit order. The size and a
|
|
60
|
+
* limit price go onto the market's lot and tick (`spec`; none = only the signed units): a buy's price rounds down and a
|
|
61
|
+
* sell's up (at most 6 decimals), the size rounds down. A size that rounds to 0, below the market's smallest size, or a
|
|
62
|
+
* limit order below the network's smallest order value is refused before signing.
|
|
63
|
+
*/
|
|
64
|
+
export declare function placeOrderValue(o: OrderInput, spec?: PairSpec | null): PlaceOrderValue;
|
|
65
|
+
/** The `/order/place` body for a signed PlaceOrder (`signature` = the 64-byte r‖s form). */
|
|
66
|
+
export declare function placeOrderBody(v: PlaceOrderValue, sessionKey: string, signature: string): Record<string, unknown>;
|
|
67
|
+
export declare function cancelOrderBody(owner: string, sessionKey: string, orderId: bigint | number, signature: string): Record<string, unknown>;
|
|
68
|
+
/** The `/tpsl/set` body (prices are 8-decimal integers; 0 leaves a leg unset). */
|
|
69
|
+
export declare function setTpSlBody(owner: string, sessionKey: string, pairId: number, positionId: bigint | number, tp8: bigint, sl8: bigint, signature: string): Record<string, unknown>;
|
|
70
|
+
export declare const ACTION_KIND: {
|
|
71
|
+
readonly place: 0;
|
|
72
|
+
readonly cancel: 1;
|
|
73
|
+
readonly cancelByClientNonce: 2;
|
|
74
|
+
};
|
|
75
|
+
/** Batch order types: limit (good till cancelled), ioc, fok, market. */
|
|
76
|
+
export declare const BATCH_ORDER_TYPE: {
|
|
77
|
+
readonly market: 0;
|
|
78
|
+
readonly limit: 1;
|
|
79
|
+
readonly ioc: 4;
|
|
80
|
+
readonly fok: 5;
|
|
81
|
+
};
|
|
82
|
+
export type BatchOrderType = keyof typeof BATCH_ORDER_TYPE;
|
|
83
|
+
export declare const BATCH_MAX = 50;
|
|
84
|
+
export interface BatchAction {
|
|
85
|
+
kind: number;
|
|
86
|
+
pairId: number;
|
|
87
|
+
side: number;
|
|
88
|
+
size: bigint;
|
|
89
|
+
price: bigint;
|
|
90
|
+
leverageBps: number;
|
|
91
|
+
orderType: number;
|
|
92
|
+
reduceOnly: boolean;
|
|
93
|
+
postOnly: boolean;
|
|
94
|
+
clientNonce: number;
|
|
95
|
+
orderId: bigint;
|
|
96
|
+
}
|
|
97
|
+
export declare function batchPlace(a: {
|
|
98
|
+
pairId: number;
|
|
99
|
+
side: Side;
|
|
100
|
+
size18: bigint | string;
|
|
101
|
+
price8: bigint | string;
|
|
102
|
+
clientNonce: number;
|
|
103
|
+
orderType?: BatchOrderType;
|
|
104
|
+
postOnly?: boolean;
|
|
105
|
+
reduceOnly?: boolean;
|
|
106
|
+
leverageBps?: number;
|
|
107
|
+
}): BatchAction;
|
|
108
|
+
export declare function batchCancel(orderId: bigint | number): BatchAction;
|
|
109
|
+
export declare function batchCancelByClientNonce(clientNonce: number): BatchAction;
|
|
110
|
+
export declare function batchActionBody(a: BatchAction): Record<string, unknown>;
|
|
111
|
+
export declare function batchBody(owner: string, nonce: number, actions: BatchAction[], signature: string): Record<string, unknown>;
|
|
112
|
+
export declare function cancelAllBody(owner: string, pairId: number, nonce: number, signature: string): Record<string, unknown>;
|
|
113
|
+
export declare function modifyBody(owner: string, orderId: bigint, newPrice8: bigint, newSize18: bigint, clientNonce: number, signature: string): Record<string, unknown>;
|
|
114
|
+
export declare function scheduleCancelBody(owner: string, cancelAtMs: number, nonce: number, signature: string): Record<string, unknown>;
|
|
115
|
+
/** A price onto the pair's tick: a bid rounds down, an ask up (never more aggressive). Tick 0 = not enforced. */
|
|
116
|
+
export declare function roundPrice(price8: bigint, tick8: bigint, side: Side): bigint;
|
|
117
|
+
/** A size down onto the pair's lot (never more than asked). Lot 0 = not enforced. */
|
|
118
|
+
export declare function roundSize(size18v: bigint, lot18: bigint): bigint;
|
|
119
|
+
export declare const MESSAGES: Record<string, string>;
|
|
120
|
+
export interface Refusal {
|
|
121
|
+
code: string;
|
|
122
|
+
message: string;
|
|
123
|
+
detail: string;
|
|
124
|
+
retryAfter: number | null;
|
|
125
|
+
}
|
|
126
|
+
export interface ActionStatus {
|
|
127
|
+
index: number;
|
|
128
|
+
accepted: boolean;
|
|
129
|
+
refusal: Refusal | null;
|
|
130
|
+
}
|
|
131
|
+
/** The answer to one write. `submitted` = accepted for a coming block (HTTP 202) — not applied. */
|
|
132
|
+
export interface Submitted {
|
|
133
|
+
submitted: boolean;
|
|
134
|
+
status: number;
|
|
135
|
+
refusal: Refusal | null;
|
|
136
|
+
actions: ActionStatus[];
|
|
137
|
+
answer: unknown;
|
|
138
|
+
}
|
|
139
|
+
export declare function refusal(code: string | null | undefined, error?: unknown, retryAfter?: number | null): Refusal;
|
|
140
|
+
/** Read a write's answer by its published shape. Anything else is a refusal, never a success. */
|
|
141
|
+
export declare function readAnswer(status: number, body: unknown, retryAfter?: string | null, meanings?: Map<string, string>): Submitted;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { InvalidRequest, NotAvailable } from './errors.js';
|
|
2
|
+
import { U32, U64, U128, fromUnits, safeNumber, toUnits, uint } from './units.js';
|
|
3
|
+
import { checkNotional, leverageBpsExact, price8OnTick, size18OnLot } from './rounding.js';
|
|
4
|
+
/**
|
|
5
|
+
* Orders on the Vordex central limit order book.
|
|
6
|
+
*
|
|
7
|
+
* Units — signed fields use two scales: prices are 8-decimal integers (`price8`), sizes 18-decimal integers (`size18`).
|
|
8
|
+
* The chain keeps a limit price at 6 decimals, so a signed price must be a multiple of 100.
|
|
9
|
+
*
|
|
10
|
+
* Single orders (`/order/place`) carry `side` and `orderType` by NAME ("buy"/"sell"; "Market"/"Limit", case-sensitive)
|
|
11
|
+
* and the limit price as a decimal number; the signed digest carries the numbers. Stop orders are not available.
|
|
12
|
+
*/
|
|
13
|
+
export const SIDE = { buy: 0, sell: 1 };
|
|
14
|
+
export const ORDER_TYPE = { Market: 0, Limit: 1 };
|
|
15
|
+
export const PRICE_DECIMALS = 8;
|
|
16
|
+
export const SIZE_DECIMALS = 18;
|
|
17
|
+
export const PRICE_STEP_8DEC = 100n;
|
|
18
|
+
export const STOP_REFUSAL = 'Stop orders are not available: set a take-profit or stop-loss on the position instead.';
|
|
19
|
+
/** A limit price as signed: at most 6 decimals (the precision the chain keeps), as the 8-decimal integer. */
|
|
20
|
+
export function limitPrice8(price) {
|
|
21
|
+
const p = toUnits(price, 6, 'A limit price') * PRICE_STEP_8DEC;
|
|
22
|
+
if (p <= 0n || p > U64)
|
|
23
|
+
throw new InvalidRequest('A limit price must be above zero.');
|
|
24
|
+
return p;
|
|
25
|
+
}
|
|
26
|
+
export function size18(size) {
|
|
27
|
+
const s = toUnits(size, SIZE_DECIMALS, 'A size');
|
|
28
|
+
if (s <= 0n || s > U128)
|
|
29
|
+
throw new InvalidRequest('A size must be above zero.');
|
|
30
|
+
return s;
|
|
31
|
+
}
|
|
32
|
+
/** Leverage as basis points, exactly from its decimal form (10x = 100000). */
|
|
33
|
+
export function leverageBps(leverage) {
|
|
34
|
+
if (typeof leverage === 'number' && !Number.isFinite(leverage))
|
|
35
|
+
throw new InvalidRequest('Leverage is at least 1x.');
|
|
36
|
+
const b = leverageBpsExact(leverage);
|
|
37
|
+
if (b < 10000n || b > U32)
|
|
38
|
+
throw new InvalidRequest('Leverage is at least 1x.');
|
|
39
|
+
return Number(b);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The signed PlaceOrder value. Refuses stop orders, a priced market order and an unpriced limit order. The size and a
|
|
43
|
+
* limit price go onto the market's lot and tick (`spec`; none = only the signed units): a buy's price rounds down and a
|
|
44
|
+
* sell's up (at most 6 decimals), the size rounds down. A size that rounds to 0, below the market's smallest size, or a
|
|
45
|
+
* limit order below the network's smallest order value is refused before signing.
|
|
46
|
+
*/
|
|
47
|
+
export function placeOrderValue(o, spec = null) {
|
|
48
|
+
if (!(o.side in SIDE))
|
|
49
|
+
throw new InvalidRequest(`side is buy or sell, not ${String(o.side)}.`);
|
|
50
|
+
if (!(o.orderType in ORDER_TYPE))
|
|
51
|
+
throw new NotAvailable(STOP_REFUSAL);
|
|
52
|
+
const priced = o.orderType === 'Limit';
|
|
53
|
+
if (priced && (o.price === undefined || o.price === null))
|
|
54
|
+
throw new InvalidRequest('A limit order needs a price.');
|
|
55
|
+
if (!priced && o.price !== undefined && o.price !== null)
|
|
56
|
+
throw new InvalidRequest('A market order carries no price (it is signed with price 0).');
|
|
57
|
+
if (o.postOnly && !priced)
|
|
58
|
+
throw new InvalidRequest('Post-only applies to a limit order.');
|
|
59
|
+
const size = size18OnLot(o.size, spec);
|
|
60
|
+
const price = priced ? price8OnTick(o.price, spec, o.side, true) : 0n;
|
|
61
|
+
checkNotional(size, price, spec);
|
|
62
|
+
return {
|
|
63
|
+
owner: o.owner,
|
|
64
|
+
pairId: safeNumber(uint(o.pairId, U32, 'pairId'), 'pairId'),
|
|
65
|
+
side: SIDE[o.side],
|
|
66
|
+
size,
|
|
67
|
+
price,
|
|
68
|
+
leverageBps: leverageBps(o.leverage ?? 1),
|
|
69
|
+
orderType: ORDER_TYPE[o.orderType],
|
|
70
|
+
reduceOnly: !!o.reduceOnly,
|
|
71
|
+
postOnly: !!o.postOnly,
|
|
72
|
+
triggerPrice8dec: 0n,
|
|
73
|
+
triggerDir: 0,
|
|
74
|
+
clientNonce: safeNumber(uint(o.clientNonce, U64, 'clientNonce'), 'clientNonce'),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const SIDE_NAME = ['buy', 'sell'];
|
|
78
|
+
const TYPE_NAME = ['Market', 'Limit'];
|
|
79
|
+
/** The `/order/place` body for a signed PlaceOrder (`signature` = the 64-byte r‖s form). */
|
|
80
|
+
export function placeOrderBody(v, sessionKey, signature) {
|
|
81
|
+
if (v.orderType !== 0 && v.orderType !== 1)
|
|
82
|
+
throw new NotAvailable(STOP_REFUSAL);
|
|
83
|
+
if (v.triggerPrice8dec !== 0n || v.triggerDir !== 0)
|
|
84
|
+
throw new NotAvailable('Trigger price and direction belong to stop orders, which are not available; send 0 for both.');
|
|
85
|
+
const body = {
|
|
86
|
+
owner: v.owner,
|
|
87
|
+
pairId: v.pairId,
|
|
88
|
+
side: SIDE_NAME[v.side],
|
|
89
|
+
size_18dec: v.size.toString(),
|
|
90
|
+
orderType: TYPE_NAME[v.orderType],
|
|
91
|
+
reduceOnly: v.reduceOnly,
|
|
92
|
+
leverageBps: v.leverageBps,
|
|
93
|
+
clientNonce: v.clientNonce,
|
|
94
|
+
sessionKey,
|
|
95
|
+
post_only: v.postOnly,
|
|
96
|
+
trigger_price_8dec: 0,
|
|
97
|
+
trigger_dir: 0,
|
|
98
|
+
signature,
|
|
99
|
+
};
|
|
100
|
+
if (v.orderType === 1) {
|
|
101
|
+
if (v.price <= 0n || v.price % PRICE_STEP_8DEC !== 0n)
|
|
102
|
+
throw new InvalidRequest('A limit price has at most 6 decimals.');
|
|
103
|
+
body.price = Number(fromUnits(v.price, PRICE_DECIMALS));
|
|
104
|
+
}
|
|
105
|
+
else if (v.price !== 0n) {
|
|
106
|
+
throw new InvalidRequest('A market order carries no price (it is signed with price 0).');
|
|
107
|
+
}
|
|
108
|
+
return body;
|
|
109
|
+
}
|
|
110
|
+
export function cancelOrderBody(owner, sessionKey, orderId, signature) {
|
|
111
|
+
return { order_id: safeNumber(uint(orderId, U64, 'orderId'), 'orderId'), owner, session_key: sessionKey, signature };
|
|
112
|
+
}
|
|
113
|
+
/** The `/tpsl/set` body (prices are 8-decimal integers; 0 leaves a leg unset). */
|
|
114
|
+
export function setTpSlBody(owner, sessionKey, pairId, positionId, tp8, sl8, signature) {
|
|
115
|
+
return {
|
|
116
|
+
action: 'perp_tpsl', owner, pair_id: pairId, position_id: safeNumber(uint(positionId, U64, 'positionId'), 'positionId'),
|
|
117
|
+
take_profit_8dec: safeNumber(uint(tp8, U64, 'takeProfit'), 'takeProfit'), stop_loss_8dec: safeNumber(uint(sl8, U64, 'stopLoss'), 'stopLoss'),
|
|
118
|
+
session_key: sessionKey, signature,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
// ── Batches (market makers) ─────────────────────────────────────────────────────────────────────────────────────────
|
|
122
|
+
export const ACTION_KIND = { place: 0, cancel: 1, cancelByClientNonce: 2 };
|
|
123
|
+
/** Batch order types: limit (good till cancelled), ioc, fok, market. */
|
|
124
|
+
export const BATCH_ORDER_TYPE = { market: 0, limit: 1, ioc: 4, fok: 5 };
|
|
125
|
+
export const BATCH_MAX = 50;
|
|
126
|
+
export function batchPlace(a) {
|
|
127
|
+
const ot = a.orderType ?? 'limit';
|
|
128
|
+
if (!(a.side in SIDE))
|
|
129
|
+
throw new InvalidRequest(`side is buy or sell, not ${String(a.side)}.`);
|
|
130
|
+
if (!(ot in BATCH_ORDER_TYPE))
|
|
131
|
+
throw new InvalidRequest(`order type is one of fok, ioc, limit, market; not ${String(ot)}.`);
|
|
132
|
+
if (a.postOnly && ot !== 'limit')
|
|
133
|
+
throw new InvalidRequest('Post-only applies to a resting limit order only.');
|
|
134
|
+
const size = uint(a.size18, U128, 'size18');
|
|
135
|
+
if (size === 0n)
|
|
136
|
+
throw new InvalidRequest('size18 is zero.');
|
|
137
|
+
const price = uint(a.price8, U64, 'price8');
|
|
138
|
+
if (ot === 'market' && price !== 0n)
|
|
139
|
+
throw new InvalidRequest('A market order carries no price (price8 0).');
|
|
140
|
+
if (ot !== 'market' && price === 0n)
|
|
141
|
+
throw new InvalidRequest(`A ${ot} order needs a price.`);
|
|
142
|
+
return {
|
|
143
|
+
kind: 0, pairId: safeNumber(uint(a.pairId, U32, 'pairId'), 'pairId'), side: SIDE[a.side], size, price,
|
|
144
|
+
leverageBps: safeNumber(uint(a.leverageBps ?? 10000, U32, 'leverageBps'), 'leverageBps'), orderType: BATCH_ORDER_TYPE[ot],
|
|
145
|
+
reduceOnly: !!a.reduceOnly, postOnly: !!a.postOnly, clientNonce: safeNumber(uint(a.clientNonce, U64, 'clientNonce'), 'clientNonce'), orderId: 0n,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
export function batchCancel(orderId) {
|
|
149
|
+
return { kind: 1, pairId: 0, side: 0, size: 0n, price: 0n, leverageBps: 0, orderType: 0, reduceOnly: false, postOnly: false, clientNonce: 0, orderId: uint(orderId, U64, 'orderId') };
|
|
150
|
+
}
|
|
151
|
+
export function batchCancelByClientNonce(clientNonce) {
|
|
152
|
+
return { kind: 2, pairId: 0, side: 0, size: 0n, price: 0n, leverageBps: 0, orderType: 0, reduceOnly: false, postOnly: false, clientNonce: safeNumber(uint(clientNonce, U64, 'clientNonce'), 'clientNonce'), orderId: 0n };
|
|
153
|
+
}
|
|
154
|
+
const BATCH_TYPE_NAME = { 0: 'market', 1: 'limit', 4: 'ioc', 5: 'fok' };
|
|
155
|
+
export function batchActionBody(a) {
|
|
156
|
+
if (a.kind === 1)
|
|
157
|
+
return { kind: 'cancel', orderId: safeNumber(a.orderId, 'orderId') };
|
|
158
|
+
if (a.kind === 2)
|
|
159
|
+
return { kind: 'cancelByClientNonce', clientNonce: a.clientNonce };
|
|
160
|
+
return {
|
|
161
|
+
kind: 'place', pairId: a.pairId, side: SIDE_NAME[a.side], size_18dec: a.size.toString(), price_8dec: safeNumber(a.price, 'price8'),
|
|
162
|
+
leverageBps: a.leverageBps, orderType: BATCH_TYPE_NAME[a.orderType], postOnly: a.postOnly, reduceOnly: a.reduceOnly, clientNonce: a.clientNonce,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
export function batchBody(owner, nonce, actions, signature) {
|
|
166
|
+
return { owner, nonce, signature, actions: actions.map(batchActionBody) };
|
|
167
|
+
}
|
|
168
|
+
export function cancelAllBody(owner, pairId, nonce, signature) {
|
|
169
|
+
return { owner, pairId, nonce, signature };
|
|
170
|
+
}
|
|
171
|
+
export function modifyBody(owner, orderId, newPrice8, newSize18, clientNonce, signature) {
|
|
172
|
+
return { owner, orderId: safeNumber(orderId, 'orderId'), newPrice8dec: safeNumber(newPrice8, 'newPrice8'), newSize18dec: newSize18.toString(), clientNonce, signature };
|
|
173
|
+
}
|
|
174
|
+
export function scheduleCancelBody(owner, cancelAtMs, nonce, signature) {
|
|
175
|
+
return { owner, cancel_at_ms: cancelAtMs, nonce, signature };
|
|
176
|
+
}
|
|
177
|
+
// ── Tick and lot ────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
178
|
+
/** A price onto the pair's tick: a bid rounds down, an ask up (never more aggressive). Tick 0 = not enforced. */
|
|
179
|
+
export function roundPrice(price8, tick8, side) {
|
|
180
|
+
if (tick8 <= 0n || price8 === 0n)
|
|
181
|
+
return price8;
|
|
182
|
+
const r = price8 % tick8;
|
|
183
|
+
if (r === 0n)
|
|
184
|
+
return price8;
|
|
185
|
+
return side === 'buy' ? price8 - r : price8 - r + tick8;
|
|
186
|
+
}
|
|
187
|
+
/** A size down onto the pair's lot (never more than asked). Lot 0 = not enforced. */
|
|
188
|
+
export function roundSize(size18v, lot18) {
|
|
189
|
+
return lot18 <= 0n ? size18v : size18v - (size18v % lot18);
|
|
190
|
+
}
|
|
191
|
+
// ── Answers ─────────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
192
|
+
export const MESSAGES = {
|
|
193
|
+
invalid_body: 'The request was refused before any signature check; a field is missing or malformed.',
|
|
194
|
+
batch_size: 'A batch holds between 1 and the published maximum of actions.',
|
|
195
|
+
unknown_order: 'That order is not open on this account.',
|
|
196
|
+
insufficient_balance: "The account's free balance is too small for this.",
|
|
197
|
+
bad_signature: 'The signature does not belong to the account or to a live session key of it.',
|
|
198
|
+
not_active: 'This is not active on this network yet.',
|
|
199
|
+
mempool_full: 'The network is busy; try again in a moment.',
|
|
200
|
+
rate_limited: 'Order rate limit reached; this order was not placed. Cancels are never limited.',
|
|
201
|
+
rate_burst: 'Too many orders in one block; spread them over the next blocks.',
|
|
202
|
+
min_notional: 'The order is below the smallest order size.',
|
|
203
|
+
too_many_open_orders: 'The account has reached its open-order limit.',
|
|
204
|
+
price_band: 'The price is too far from the mark price.',
|
|
205
|
+
price: 'The price is not accepted (it may be too far from the mark price or off the tick size).',
|
|
206
|
+
};
|
|
207
|
+
export function refusal(code, error = '', retryAfter = null) {
|
|
208
|
+
const text = error === null || error === undefined ? '' : String(error);
|
|
209
|
+
if ((code ?? '') === 'price_band' || /too far from (the )?mark/i.test(text))
|
|
210
|
+
return { code: 'price_band', message: MESSAGES.price_band, detail: text, retryAfter };
|
|
211
|
+
const c = code || (text ? 'refused' : 'http_error');
|
|
212
|
+
return { code: c, message: MESSAGES[c] ?? (text || 'The request was refused.'), detail: text, retryAfter };
|
|
213
|
+
}
|
|
214
|
+
/** Read a write's answer by its published shape. Anything else is a refusal, never a success. */
|
|
215
|
+
export function readAnswer(status, body, retryAfter = null, meanings) {
|
|
216
|
+
const j = body && typeof body === 'object' && !Array.isArray(body) ? body : {};
|
|
217
|
+
const ra = retryAfter !== null && Number.isFinite(Number(retryAfter)) ? Number(retryAfter) : null;
|
|
218
|
+
if (status === 202 && j.status === 'submitted') {
|
|
219
|
+
const actions = [];
|
|
220
|
+
for (const a of Array.isArray(j.actions) ? j.actions : []) {
|
|
221
|
+
if (!a || typeof a !== 'object' || typeof a.index !== 'number')
|
|
222
|
+
continue;
|
|
223
|
+
const x = a;
|
|
224
|
+
actions.push(x.status === 'accepted' ? { index: x.index, accepted: true, refusal: null } : { index: x.index, accepted: false, refusal: refusal(x.code, x.error) });
|
|
225
|
+
}
|
|
226
|
+
return { submitted: true, status, refusal: null, actions, answer: body };
|
|
227
|
+
}
|
|
228
|
+
let code = typeof j.code === 'string' ? j.code : null;
|
|
229
|
+
if (status === 429 && !code)
|
|
230
|
+
code = 'mempool_full';
|
|
231
|
+
if (code === 'agent_refused') { // an agent check at intake: the reason key and its meaning, as the chain gives them
|
|
232
|
+
const reason = typeof j.reason === 'string' ? j.reason : '';
|
|
233
|
+
const meaning = typeof j.meaning === 'string' ? j.meaning : (meanings?.get(reason) ?? '');
|
|
234
|
+
return { submitted: false, status, refusal: { code: 'agent_refused', message: meaning || `The agent's action was refused (${reason || 'no reason given'}).`, detail: reason, retryAfter: ra }, actions: [], answer: body };
|
|
235
|
+
}
|
|
236
|
+
const err = j.error ?? j.reason ?? (status ? `HTTP ${status}` : '');
|
|
237
|
+
return { submitted: false, status, refusal: refusal(code, err, ra), actions: [], answer: body };
|
|
238
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export interface OpenOrder {
|
|
2
|
+
orderId: bigint;
|
|
3
|
+
clientNonce: number | null;
|
|
4
|
+
pairId: number;
|
|
5
|
+
side: 'buy' | 'sell';
|
|
6
|
+
size18: bigint;
|
|
7
|
+
/** 0 for an order without a price. */
|
|
8
|
+
price8: bigint;
|
|
9
|
+
status: string | null;
|
|
10
|
+
/** The key that signed it, as the node names it. */
|
|
11
|
+
signer: string | null;
|
|
12
|
+
timestampMs: number | null;
|
|
13
|
+
}
|
|
14
|
+
export declare function readOpenOrders(j: unknown): OpenOrder[];
|
|
15
|
+
export interface Position {
|
|
16
|
+
positionId: bigint;
|
|
17
|
+
pairId: number;
|
|
18
|
+
isLong: boolean;
|
|
19
|
+
/** Exact at any size. */
|
|
20
|
+
size18: bigint;
|
|
21
|
+
/** As the node gives it (6-decimal integer). */
|
|
22
|
+
entryPrice: bigint;
|
|
23
|
+
leverage: bigint;
|
|
24
|
+
margin6: bigint;
|
|
25
|
+
unrealizedPnl6: bigint;
|
|
26
|
+
/** As the node computed it (6-decimal integer); see {@link saneLiquidationPrice}. */
|
|
27
|
+
liquidationPrice: bigint;
|
|
28
|
+
}
|
|
29
|
+
export declare function readPositions(j: unknown): Position[];
|
|
30
|
+
/**
|
|
31
|
+
* The chain's liquidation price, only when it makes sense for the position: below the entry for a long (and no lower
|
|
32
|
+
* than the entry at its leverage less 5%), above it for a short. Otherwise null — "not available", never a guess.
|
|
33
|
+
*/
|
|
34
|
+
export declare function saneLiquidationPrice(p: Position): bigint | null;
|
|
35
|
+
export interface Equity {
|
|
36
|
+
usdcBalance6: bigint;
|
|
37
|
+
reservedOrders6: bigint;
|
|
38
|
+
inPositions6: bigint;
|
|
39
|
+
/** What a new order can use as margin. */
|
|
40
|
+
freeBalance6: bigint;
|
|
41
|
+
unrealizedPnl6: bigint;
|
|
42
|
+
totalEquity6: bigint;
|
|
43
|
+
}
|
|
44
|
+
export declare function readEquity(j: unknown): Equity;
|
|
45
|
+
/**
|
|
46
|
+
* The meaning of each agent refusal reason, from the network spec's `agents.refusalCodes.reasons` (key → plain
|
|
47
|
+
* sentence). Empty when the network does not publish them; a reason without a published meaning is then shown as the
|
|
48
|
+
* chain wrote it.
|
|
49
|
+
*/
|
|
50
|
+
export declare function refusalMeanings(spec: unknown): Map<string, string>;
|
|
51
|
+
/** One action the chain refused for an agent (from `/events/agent/{agent}`): the reason key and, when the network publishes it, its meaning. */
|
|
52
|
+
export interface AgentRefusal {
|
|
53
|
+
reason: string;
|
|
54
|
+
meaning: string | null;
|
|
55
|
+
height: number | null;
|
|
56
|
+
timestampMs: number | null;
|
|
57
|
+
record: Record<string, unknown>;
|
|
58
|
+
}
|
|
59
|
+
export declare function readAgentRefusals(j: unknown, meanings?: Map<string, string>): AgentRefusal[];
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { VordiumError } from './errors.js';
|
|
2
|
+
/** Parsers for the account reads. Anything without the published shape raises, never a guess. */
|
|
3
|
+
const big = (v, what, allowNull = false) => {
|
|
4
|
+
if (v === null || v === undefined) {
|
|
5
|
+
if (allowNull)
|
|
6
|
+
return null;
|
|
7
|
+
throw new VordiumError('bad_read', `${what} is missing from the read.`);
|
|
8
|
+
}
|
|
9
|
+
if (typeof v === 'number' && Number.isSafeInteger(v))
|
|
10
|
+
return BigInt(v);
|
|
11
|
+
if (typeof v === 'string' && /^-?\d+$/.test(v))
|
|
12
|
+
return BigInt(v);
|
|
13
|
+
throw new VordiumError('bad_read', `${what} is not a whole number in the read.`);
|
|
14
|
+
};
|
|
15
|
+
export function readOpenOrders(j) {
|
|
16
|
+
if (!Array.isArray(j))
|
|
17
|
+
throw new VordiumError('bad_read', 'The open-orders read is not a list.');
|
|
18
|
+
return j.map((o) => {
|
|
19
|
+
if (!o || typeof o !== 'object')
|
|
20
|
+
throw new VordiumError('bad_read', 'An open order is not an object.');
|
|
21
|
+
const r = o;
|
|
22
|
+
const side = String(r.side ?? '').toLowerCase();
|
|
23
|
+
if (side !== 'buy' && side !== 'sell')
|
|
24
|
+
throw new VordiumError('bad_read', `An open order has no side (${String(r.side)}).`);
|
|
25
|
+
const cn = big(r.client_nonce, 'client_nonce', true);
|
|
26
|
+
const ts = big(r.timestamp_ms, 'timestamp_ms', true);
|
|
27
|
+
return {
|
|
28
|
+
orderId: big(r.id, 'id'), clientNonce: cn === null ? null : Number(cn), pairId: Number(big(r.pair_id, 'pair_id')), side,
|
|
29
|
+
size18: big(r.size, 'size'), price8: big(r.price_8dec ?? 0, 'price_8dec'),
|
|
30
|
+
status: typeof r.status === 'string' ? r.status.toLowerCase() : null, signer: typeof r.agent === 'string' ? r.agent : null,
|
|
31
|
+
timestampMs: ts === null ? null : Number(ts),
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export function readPositions(j) {
|
|
36
|
+
if (!Array.isArray(j))
|
|
37
|
+
throw new VordiumError('bad_read', 'The positions read is not a list.');
|
|
38
|
+
return j.map((p) => {
|
|
39
|
+
if (!p || typeof p !== 'object' || typeof p.is_long !== 'boolean')
|
|
40
|
+
throw new VordiumError('bad_read', 'A position does not have the published shape.');
|
|
41
|
+
const r = p;
|
|
42
|
+
return {
|
|
43
|
+
positionId: big(r.id, 'id'), pairId: Number(big(r.pair_id, 'pair_id')), isLong: r.is_long, size18: big(r.size, 'size'),
|
|
44
|
+
entryPrice: big(r.entry_price, 'entry_price'), leverage: big(r.leverage, 'leverage'), margin6: big(r.margin, 'margin'),
|
|
45
|
+
unrealizedPnl6: big(r.unrealized_pnl, 'unrealized_pnl'), liquidationPrice: big(r.liquidation_price, 'liquidation_price'),
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The chain's liquidation price, only when it makes sense for the position: below the entry for a long (and no lower
|
|
51
|
+
* than the entry at its leverage less 5%), above it for a short. Otherwise null — "not available", never a guess.
|
|
52
|
+
*/
|
|
53
|
+
export function saneLiquidationPrice(p) {
|
|
54
|
+
const lev = p.leverage >= 1n ? p.leverage : 1n;
|
|
55
|
+
const e = p.entryPrice, l = p.liquidationPrice;
|
|
56
|
+
if (e <= 0n || l <= 0n)
|
|
57
|
+
return null;
|
|
58
|
+
// long: entry × (1 − 1/lev) − 5% ≤ liq < entry ; short: entry < liq ≤ entry × (1 + 1/lev) + 5%
|
|
59
|
+
if (p.isLong) {
|
|
60
|
+
const floor = (e * (lev - 1n) * 100n) / (lev * 100n) - e / 20n;
|
|
61
|
+
return l < e && l >= floor ? l : null;
|
|
62
|
+
}
|
|
63
|
+
const ceil = (e * (lev + 1n)) / lev + e / 20n;
|
|
64
|
+
return l > e && l <= ceil ? l : null;
|
|
65
|
+
}
|
|
66
|
+
export function readEquity(j) {
|
|
67
|
+
if (!j || typeof j !== 'object')
|
|
68
|
+
throw new VordiumError('bad_read', 'The equity read is not an object.');
|
|
69
|
+
const r = j;
|
|
70
|
+
return {
|
|
71
|
+
usdcBalance6: big(r.usdc_balance, 'usdc_balance'), reservedOrders6: big(r.reserved_orders, 'reserved_orders'),
|
|
72
|
+
inPositions6: big(r.in_positions, 'in_positions'), freeBalance6: big(r.free_balance, 'free_balance'),
|
|
73
|
+
unrealizedPnl6: big(r.unrealized_pnl, 'unrealized_pnl'), totalEquity6: big(r.total_equity, 'total_equity'),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The meaning of each agent refusal reason, from the network spec's `agents.refusalCodes.reasons` (key → plain
|
|
78
|
+
* sentence). Empty when the network does not publish them; a reason without a published meaning is then shown as the
|
|
79
|
+
* chain wrote it.
|
|
80
|
+
*/
|
|
81
|
+
export function refusalMeanings(spec) {
|
|
82
|
+
const out = new Map();
|
|
83
|
+
const rc = spec && typeof spec === 'object' ? spec.agents?.refusalCodes : undefined;
|
|
84
|
+
const reasons = rc && typeof rc === 'object' ? rc.reasons : undefined;
|
|
85
|
+
if (Array.isArray(reasons)) {
|
|
86
|
+
for (const r of reasons) {
|
|
87
|
+
if (r && typeof r === 'object' && typeof r.key === 'string' && typeof r.meaning === 'string') {
|
|
88
|
+
out.set(r.key, r.meaning);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
export function readAgentRefusals(j, meanings = new Map()) {
|
|
95
|
+
const list = j && typeof j === 'object' ? (j.events ?? j.records ?? j.items) : null;
|
|
96
|
+
if (!Array.isArray(list))
|
|
97
|
+
return [];
|
|
98
|
+
const out = [];
|
|
99
|
+
for (const e of list) {
|
|
100
|
+
if (!e || typeof e !== 'object')
|
|
101
|
+
continue;
|
|
102
|
+
const r = e;
|
|
103
|
+
if (r.kind !== 'agent_refused')
|
|
104
|
+
continue;
|
|
105
|
+
const data = (r.data && typeof r.data === 'object' ? r.data : r);
|
|
106
|
+
const reason = String(data.reason ?? r.reason ?? '');
|
|
107
|
+
out.push({
|
|
108
|
+
reason, meaning: meanings.get(reason) ?? null, height: typeof r.height === 'number' ? r.height : null,
|
|
109
|
+
timestampMs: typeof r.at_ms === 'number' ? r.at_ms : typeof r.timestamp_ms === 'number' ? r.timestamp_ms : null, record: r,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { InvalidRequest } from './errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* Exact order units on each market's tick and lot.
|
|
4
|
+
*
|
|
5
|
+
* The chain keeps a price step (`tick_8dec`) and a size step (`lot_18dec`) per market, published in `GET /markets/specs`,
|
|
6
|
+
* and does not apply an order that is off them. Every order this SDK signs is put on them first:
|
|
7
|
+
*
|
|
8
|
+
* - a number is read exactly from its decimal form: a decimal string ("2420.5", ".5", "1e-4"), a bigint, or a number from
|
|
9
|
+
* its shortest decimal form (0.1 is 0.1). Nothing is multiplied as a floating-point number;
|
|
10
|
+
* - a limit price rounds toward the passive side: a buy's DOWN, a sell's UP onto the tick (never a worse price than
|
|
11
|
+
* asked). On `/order/place` it is also kept at 6 decimals (a multiple of 100 in 8-decimal units);
|
|
12
|
+
* - a take-profit / stop-loss trigger goes to the NEAREST tick (a half tick rounds up);
|
|
13
|
+
* - a size rounds DOWN onto the lot (never more than asked);
|
|
14
|
+
* - a tick or lot of 0 means the network sets none: only the signed unit applies.
|
|
15
|
+
*
|
|
16
|
+
* Refused before anything is signed ({@link OrderValueError}): a size that rounds to 0 or is below the market's smallest
|
|
17
|
+
* size, a limit price that rounds to 0, a priced order below the network's smallest order value, a market the network does
|
|
18
|
+
* not list.
|
|
19
|
+
*/
|
|
20
|
+
export declare class OrderValueError extends InvalidRequest {
|
|
21
|
+
constructor(message: string);
|
|
22
|
+
}
|
|
23
|
+
/** The market rules (`GET /markets/specs`) could not be read, so no order value can be put on its step. */
|
|
24
|
+
export declare class SpecsUnavailable extends OrderValueError {
|
|
25
|
+
constructor(message: string);
|
|
26
|
+
}
|
|
27
|
+
export interface PairSpec {
|
|
28
|
+
pairId: number;
|
|
29
|
+
symbol: string;
|
|
30
|
+
tick8: bigint;
|
|
31
|
+
lot18: bigint;
|
|
32
|
+
minSize18: bigint;
|
|
33
|
+
minNotional6: bigint;
|
|
34
|
+
}
|
|
35
|
+
export declare const PLACE_PRICE_STEP_8DEC = 100n;
|
|
36
|
+
/** `x` × 10^`decimals` as an exact fraction [numerator, denominator]. */
|
|
37
|
+
export declare function scaled(x: unknown, decimals: number, what?: string): [bigint, bigint];
|
|
38
|
+
/** A count of base units: a whole number (bigint, safe-integer number, digit string, or an integral decimal). */
|
|
39
|
+
export declare function whole(x: unknown, what?: string): bigint;
|
|
40
|
+
/** num/den onto a multiple of `step`: down, up, or nearest (a half step rounds up). */
|
|
41
|
+
export declare function onStep(num: bigint, den: bigint, step: bigint, mode: 'down' | 'up' | 'nearest'): bigint;
|
|
42
|
+
export declare function priceStep(spec: PairSpec | null, placeRoute?: boolean): bigint;
|
|
43
|
+
export declare function sizeStep(spec: PairSpec | null): bigint;
|
|
44
|
+
/** A limit price as the signed 8-decimal integer on the tick: a buy's rounds down, a sell's up. */
|
|
45
|
+
export declare function price8OnTick(price: unknown, spec: PairSpec | null, side: unknown, placeRoute?: boolean): bigint;
|
|
46
|
+
/** A size as the signed 18-decimal integer, down onto the lot. */
|
|
47
|
+
export declare function size18OnLot(size: unknown, spec: PairSpec | null): bigint;
|
|
48
|
+
/** A take-profit / stop-loss trigger as the 8-decimal integer, to the nearest tick (0 = no trigger). */
|
|
49
|
+
export declare function trigger8OnTick(price: unknown, spec: PairSpec | null): bigint;
|
|
50
|
+
/** A signed 8-decimal price already in base units, onto the tick by the passive rule (0 stays 0: no price). */
|
|
51
|
+
export declare function snapPrice8(price8: unknown, spec: PairSpec | null, side: unknown, placeRoute?: boolean): bigint;
|
|
52
|
+
export declare function snapSize18(size18: unknown, spec: PairSpec | null): bigint;
|
|
53
|
+
export declare function snapTrigger8(price8: unknown, spec: PairSpec | null): bigint;
|
|
54
|
+
export declare function checkSize(size18: bigint, spec: PairSpec | null, asked?: unknown): bigint;
|
|
55
|
+
/** size × price in USDC base units (6 decimals), rounded down. */
|
|
56
|
+
export declare function notional6(size18: bigint, price8: bigint): bigint;
|
|
57
|
+
export declare function checkNotional(size18: bigint, price8: bigint, spec: PairSpec | null): void;
|
|
58
|
+
/** Leverage (2 or "2.5") as basis points, exactly (half to even). */
|
|
59
|
+
export declare function leverageBpsExact(leverage: unknown): bigint;
|
|
60
|
+
/** Every market without a tick, lot or minimum: for dry runs and offline tests. Never what a network publishes. */
|
|
61
|
+
export declare const NO_RULES: Readonly<{
|
|
62
|
+
noRules: true;
|
|
63
|
+
}>;
|
|
64
|
+
export type MarketRules = Map<number, PairSpec> | typeof NO_RULES;
|
|
65
|
+
/** Each market's tick, lot and smallest size from a `/markets/specs` read, with the network's smallest order value. */
|
|
66
|
+
export declare function pairSpecs(read: unknown): Map<number, PairSpec>;
|
|
67
|
+
/** One market's rules; a market the read does not list is refused. */
|
|
68
|
+
export declare function selectSpec(rules: MarketRules, pairId: number): PairSpec;
|
|
69
|
+
/** A /markets/specs read, a parsed map, or NO_RULES, as market rules. */
|
|
70
|
+
export declare function marketRules(x: unknown): MarketRules;
|