wickra-exchange-wasm 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # wickra-exchange-wasm
2
+
3
+ WebAssembly bindings for [`wickra-exchange`](https://github.com/wickra-lib/wickra-exchange):
4
+ the offline **paper** and **replay** simulators, in the browser.
5
+
6
+ ## What this package is, and what it is not
7
+
8
+ The other bindings — Node, Python, C, C#, Go, Java, R — connect to live venues.
9
+ This one cannot, and that is a property of the target rather than a gap in the
10
+ work: `wasm32-unknown-unknown` has no TCP sockets and no TLS stack, and the
11
+ transport crate is built on tokio, reqwest and tokio-tungstenite, none of which
12
+ target the browser. A `connect()` here would compile and then fail at the first
13
+ request.
14
+
15
+ So this package carries the part of the library that is pure computation and
16
+ therefore genuinely runs in a page:
17
+
18
+ | exposed | absent |
19
+ | --- | --- |
20
+ | `Exchange.paper` — offline account with fees and slippage | `connect` — needs sockets |
21
+ | `Exchange.replayTrades` — recorded price tape | user-data streams, WebSocket execution |
22
+ | `placeOrder`, `cancelOrder`, `queryOrder`, `openOrders` | derivatives (live-only) |
23
+ | `balances`, `ticker`, `setPrice`, `pollEvents` | `klines` (needs a venue) |
24
+ | `OrderRequest` factories, `version()` | depth — see below |
25
+
26
+ There is no `orderBook`. The paper account has no depth feed and answers
27
+ `unsupported`; the replay backend delegates straight to it. On both backends
28
+ reachable from here the call cannot succeed, so exposing it would only add a
29
+ method that type-checks and always throws.
30
+
31
+ The surface that *is* here is the one a backtest uses, which is the point: a
32
+ strategy written against this runs unchanged against a live venue once it moves
33
+ off the browser.
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ npm install wickra-exchange-wasm
39
+ ```
40
+
41
+ ## Use
42
+
43
+ ```js
44
+ import init, { Exchange, OrderRequest } from "wickra-exchange-wasm";
45
+
46
+ await init();
47
+
48
+ const ex = Exchange.paper({ USDT: 100_000 }, 1, 5, 10); // maker/taker/slippage bps
49
+ ex.setPrice("BTC/USDT", 20_000);
50
+
51
+ // A number is fine; a string is exact, which is what a size with more than
52
+ // about fifteen significant digits needs -- JS has one number type and it is a
53
+ // double.
54
+ const order = ex.placeOrder(OrderRequest.marketBuy("BTC/USDT", 1));
55
+ console.log(order.status, order.averagePrice); // "filled" 20020
56
+
57
+ console.log(ex.balances()); // { BTC: 1, USDT: 79980 }
58
+ ```
59
+
60
+ Replaying a recorded tape, one frame per `pollEvents()`:
61
+
62
+ ```js
63
+ const replay = Exchange.replayTrades(
64
+ "BTC/USDT",
65
+ Float64Array.from([100, 101, 102, 110, 112]),
66
+ { USDT: 100_000 },
67
+ );
68
+
69
+ for (;;) {
70
+ const events = replay.pollEvents();
71
+ if (events.length === 0) break; // an exhausted tape yields nothing further
72
+ for (const event of events) {
73
+ if (event.kind === "trade") {
74
+ // ... your strategy sees the same events a live feed produces
75
+ }
76
+ }
77
+ }
78
+ ```
79
+
80
+ ## Build from source
81
+
82
+ ```bash
83
+ wasm-pack build bindings/wasm --target web --release --features panic-hook # browsers
84
+ wasm-pack build bindings/wasm --target nodejs --release --out-dir pkg # Node
85
+ node --test bindings/wasm/tests/
86
+ ```
87
+
88
+ The `panic-hook` feature routes Rust panics to `console.error` with a readable
89
+ stack; without it a panic surfaces as "unreachable executed" and nothing points
90
+ at the cause. It costs a little size, which is why it is off by default and on
91
+ for the browser build.
92
+
93
+ ## Licence
94
+
95
+ `MIT OR Apache-2.0`, the same as the workspace.
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "wickra-exchange-wasm",
3
+ "type": "module",
4
+ "collaborators": [
5
+ "kingchenc"
6
+ ],
7
+ "description": "WebAssembly bindings for wickra-exchange: the offline paper and replay simulators, in the browser.",
8
+ "version": "0.1.0",
9
+ "license": "MIT OR Apache-2.0",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/wickra-lib/wickra-exchange"
13
+ },
14
+ "files": [
15
+ "wickra_exchange_wasm_bg.wasm",
16
+ "wickra_exchange_wasm.js",
17
+ "wickra_exchange_wasm_bg.js",
18
+ "wickra_exchange_wasm.d.ts"
19
+ ],
20
+ "main": "wickra_exchange_wasm.js",
21
+ "homepage": "https://github.com/wickra-lib/wickra-exchange",
22
+ "types": "wickra_exchange_wasm.d.ts",
23
+ "sideEffects": [
24
+ "./wickra_exchange_wasm.js",
25
+ "./snippets/*"
26
+ ],
27
+ "keywords": [
28
+ "crypto",
29
+ "exchange",
30
+ "trading",
31
+ "connectivity",
32
+ "streaming"
33
+ ],
34
+ "author": "kingchenc <support@wickra.org>",
35
+ "bugs": {
36
+ "url": "https://github.com/wickra-lib/wickra-exchange/issues"
37
+ }
38
+ }
@@ -0,0 +1,115 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * An offline exchange: a paper account, or a replay tape filled against one.
6
+ *
7
+ * Both implement the same `Exchange` API the live clients do in the other
8
+ * bindings, so a strategy written against this runs unchanged on a live venue
9
+ * once it moves off the browser.
10
+ */
11
+ export class Exchange {
12
+ private constructor();
13
+ free(): void;
14
+ [Symbol.dispose](): void;
15
+ /**
16
+ * Account balances as an `asset -> free amount` object.
17
+ */
18
+ balances(): any;
19
+ /**
20
+ * Cancel an open order by id.
21
+ */
22
+ cancelOrder(market: string, order_id: string): void;
23
+ /**
24
+ * The backend's lowercase identifier (`"paper"` or `"replay"`).
25
+ */
26
+ name(): string;
27
+ /**
28
+ * Open orders, optionally filtered to one `market`.
29
+ */
30
+ openOrders(market?: string | null): any;
31
+ /**
32
+ * An offline paper account seeded from `balances` (asset -> amount), with
33
+ * optional maker/taker fees and slippage in basis points.
34
+ */
35
+ static paper(balances: any, maker_bps?: number | null, taker_bps?: number | null, slippage_bps?: number | null): Exchange;
36
+ /**
37
+ * Place an order; returns the resulting order.
38
+ */
39
+ placeOrder(request: OrderRequest): any;
40
+ /**
41
+ * Drain all events buffered since the last call.
42
+ */
43
+ pollEvents(): any;
44
+ /**
45
+ * Look up a single order by id.
46
+ */
47
+ queryOrder(market: string, order_id: string): any;
48
+ /**
49
+ * A replay account driven by a recorded price `tape` of `market` trades,
50
+ * filling against a paper book seeded from `balances`.
51
+ */
52
+ static replayTrades(market: string, tape: Float64Array, balances: any, maker_bps?: number | null, taker_bps?: number | null, slippage_bps?: number | null): Exchange;
53
+ /**
54
+ * Set the mark price a paper account fills against (paper backend only).
55
+ */
56
+ setPrice(market: string, price: number): void;
57
+ /**
58
+ * The current ticker for `market`.
59
+ */
60
+ ticker(market: string): any;
61
+ }
62
+
63
+ /**
64
+ * An order request, built with the market/limit factory methods.
65
+ */
66
+ export class OrderRequest {
67
+ private constructor();
68
+ free(): void;
69
+ [Symbol.dispose](): void;
70
+ static limitBuy(market: string, quantity: any, price: any): OrderRequest;
71
+ static limitSell(market: string, quantity: any, price: any): OrderRequest;
72
+ static marketBuy(market: string, quantity: any): OrderRequest;
73
+ static marketSell(market: string, quantity: any): OrderRequest;
74
+ /**
75
+ * Maker-only: the order is cancelled rather than crossing the spread.
76
+ */
77
+ postOnly(): OrderRequest;
78
+ /**
79
+ * Close-only: the order may not increase a position.
80
+ */
81
+ reduceOnly(): OrderRequest;
82
+ /**
83
+ * Attach a client order id, so a retried placement is recognised by the
84
+ * venue as the same order rather than placed twice.
85
+ */
86
+ withClientOrderId(id: string): OrderRequest;
87
+ /**
88
+ * Rest until the market reaches `stopPrice`, then fire: a market order
89
+ * becomes a stop-loss, a limit order a stop-limit.
90
+ */
91
+ withStopPrice(stop_price: any): OrderRequest;
92
+ /**
93
+ * Self-trade prevention: `"none"`, `"expire_maker"`, `"expire_taker"` or
94
+ * `"expire_both"` (case-insensitive). Throws on anything else.
95
+ */
96
+ withStp(stp: string): OrderRequest;
97
+ /**
98
+ * `"GTC"`, `"IOC"` or `"FOK"` (case-insensitive). Throws on anything else
99
+ * rather than falling back to GTC.
100
+ */
101
+ withTimeInForce(tif: string): OrderRequest;
102
+ }
103
+
104
+ /**
105
+ * Route Rust panics to `console.error` with a readable stack.
106
+ *
107
+ * Enabled by the `panic-hook` feature; without it a panic surfaces in JS as
108
+ * "unreachable executed" with nothing pointing at the cause.
109
+ */
110
+ export function start(): void;
111
+
112
+ /**
113
+ * Library version (matches the Rust crate version).
114
+ */
115
+ export function version(): string;
@@ -0,0 +1,9 @@
1
+ /* @ts-self-types="./wickra_exchange_wasm.d.ts" */
2
+ import * as wasm from "./wickra_exchange_wasm_bg.wasm";
3
+ import { __wbg_set_wasm } from "./wickra_exchange_wasm_bg.js";
4
+
5
+ __wbg_set_wasm(wasm);
6
+ wasm.__wbindgen_start();
7
+ export {
8
+ Exchange, OrderRequest, start, version
9
+ } from "./wickra_exchange_wasm_bg.js";
@@ -0,0 +1,781 @@
1
+ /**
2
+ * An offline exchange: a paper account, or a replay tape filled against one.
3
+ *
4
+ * Both implement the same `Exchange` API the live clients do in the other
5
+ * bindings, so a strategy written against this runs unchanged on a live venue
6
+ * once it moves off the browser.
7
+ */
8
+ export class Exchange {
9
+ static __wrap(ptr) {
10
+ const obj = Object.create(Exchange.prototype);
11
+ obj.__wbg_ptr = ptr;
12
+ ExchangeFinalization.register(obj, obj.__wbg_ptr, obj);
13
+ return obj;
14
+ }
15
+ __destroy_into_raw() {
16
+ const ptr = this.__wbg_ptr;
17
+ this.__wbg_ptr = 0;
18
+ ExchangeFinalization.unregister(this);
19
+ return ptr;
20
+ }
21
+ free() {
22
+ const ptr = this.__destroy_into_raw();
23
+ wasm.__wbg_exchange_free(ptr, 0);
24
+ }
25
+ /**
26
+ * Account balances as an `asset -> free amount` object.
27
+ * @returns {any}
28
+ */
29
+ balances() {
30
+ const ret = wasm.exchange_balances(this.__wbg_ptr);
31
+ if (ret[2]) {
32
+ throw takeFromExternrefTable0(ret[1]);
33
+ }
34
+ return takeFromExternrefTable0(ret[0]);
35
+ }
36
+ /**
37
+ * Cancel an open order by id.
38
+ * @param {string} market
39
+ * @param {string} order_id
40
+ */
41
+ cancelOrder(market, order_id) {
42
+ const ptr0 = passStringToWasm0(market, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
43
+ const len0 = WASM_VECTOR_LEN;
44
+ const ptr1 = passStringToWasm0(order_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
45
+ const len1 = WASM_VECTOR_LEN;
46
+ const ret = wasm.exchange_cancelOrder(this.__wbg_ptr, ptr0, len0, ptr1, len1);
47
+ if (ret[1]) {
48
+ throw takeFromExternrefTable0(ret[0]);
49
+ }
50
+ }
51
+ /**
52
+ * The backend's lowercase identifier (`"paper"` or `"replay"`).
53
+ * @returns {string}
54
+ */
55
+ name() {
56
+ let deferred1_0;
57
+ let deferred1_1;
58
+ try {
59
+ const ret = wasm.exchange_name(this.__wbg_ptr);
60
+ deferred1_0 = ret[0];
61
+ deferred1_1 = ret[1];
62
+ return getStringFromWasm0(ret[0], ret[1]);
63
+ } finally {
64
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
65
+ }
66
+ }
67
+ /**
68
+ * Open orders, optionally filtered to one `market`.
69
+ * @param {string | null} [market]
70
+ * @returns {any}
71
+ */
72
+ openOrders(market) {
73
+ var ptr0 = isLikeNone(market) ? 0 : passStringToWasm0(market, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
74
+ var len0 = WASM_VECTOR_LEN;
75
+ const ret = wasm.exchange_openOrders(this.__wbg_ptr, ptr0, len0);
76
+ if (ret[2]) {
77
+ throw takeFromExternrefTable0(ret[1]);
78
+ }
79
+ return takeFromExternrefTable0(ret[0]);
80
+ }
81
+ /**
82
+ * An offline paper account seeded from `balances` (asset -> amount), with
83
+ * optional maker/taker fees and slippage in basis points.
84
+ * @param {any} balances
85
+ * @param {number | null} [maker_bps]
86
+ * @param {number | null} [taker_bps]
87
+ * @param {number | null} [slippage_bps]
88
+ * @returns {Exchange}
89
+ */
90
+ static paper(balances, maker_bps, taker_bps, slippage_bps) {
91
+ const ret = wasm.exchange_paper(balances, !isLikeNone(maker_bps), isLikeNone(maker_bps) ? 0 : maker_bps, !isLikeNone(taker_bps), isLikeNone(taker_bps) ? 0 : taker_bps, !isLikeNone(slippage_bps), isLikeNone(slippage_bps) ? 0 : slippage_bps);
92
+ if (ret[2]) {
93
+ throw takeFromExternrefTable0(ret[1]);
94
+ }
95
+ return Exchange.__wrap(ret[0]);
96
+ }
97
+ /**
98
+ * Place an order; returns the resulting order.
99
+ * @param {OrderRequest} request
100
+ * @returns {any}
101
+ */
102
+ placeOrder(request) {
103
+ _assertClass(request, OrderRequest);
104
+ const ret = wasm.exchange_placeOrder(this.__wbg_ptr, request.__wbg_ptr);
105
+ if (ret[2]) {
106
+ throw takeFromExternrefTable0(ret[1]);
107
+ }
108
+ return takeFromExternrefTable0(ret[0]);
109
+ }
110
+ /**
111
+ * Drain all events buffered since the last call.
112
+ * @returns {any}
113
+ */
114
+ pollEvents() {
115
+ const ret = wasm.exchange_pollEvents(this.__wbg_ptr);
116
+ if (ret[2]) {
117
+ throw takeFromExternrefTable0(ret[1]);
118
+ }
119
+ return takeFromExternrefTable0(ret[0]);
120
+ }
121
+ /**
122
+ * Look up a single order by id.
123
+ * @param {string} market
124
+ * @param {string} order_id
125
+ * @returns {any}
126
+ */
127
+ queryOrder(market, order_id) {
128
+ const ptr0 = passStringToWasm0(market, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
129
+ const len0 = WASM_VECTOR_LEN;
130
+ const ptr1 = passStringToWasm0(order_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
131
+ const len1 = WASM_VECTOR_LEN;
132
+ const ret = wasm.exchange_queryOrder(this.__wbg_ptr, ptr0, len0, ptr1, len1);
133
+ if (ret[2]) {
134
+ throw takeFromExternrefTable0(ret[1]);
135
+ }
136
+ return takeFromExternrefTable0(ret[0]);
137
+ }
138
+ /**
139
+ * A replay account driven by a recorded price `tape` of `market` trades,
140
+ * filling against a paper book seeded from `balances`.
141
+ * @param {string} market
142
+ * @param {Float64Array} tape
143
+ * @param {any} balances
144
+ * @param {number | null} [maker_bps]
145
+ * @param {number | null} [taker_bps]
146
+ * @param {number | null} [slippage_bps]
147
+ * @returns {Exchange}
148
+ */
149
+ static replayTrades(market, tape, balances, maker_bps, taker_bps, slippage_bps) {
150
+ const ptr0 = passStringToWasm0(market, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
151
+ const len0 = WASM_VECTOR_LEN;
152
+ const ptr1 = passArrayF64ToWasm0(tape, wasm.__wbindgen_malloc);
153
+ const len1 = WASM_VECTOR_LEN;
154
+ const ret = wasm.exchange_replayTrades(ptr0, len0, ptr1, len1, balances, !isLikeNone(maker_bps), isLikeNone(maker_bps) ? 0 : maker_bps, !isLikeNone(taker_bps), isLikeNone(taker_bps) ? 0 : taker_bps, !isLikeNone(slippage_bps), isLikeNone(slippage_bps) ? 0 : slippage_bps);
155
+ if (ret[2]) {
156
+ throw takeFromExternrefTable0(ret[1]);
157
+ }
158
+ return Exchange.__wrap(ret[0]);
159
+ }
160
+ /**
161
+ * Set the mark price a paper account fills against (paper backend only).
162
+ * @param {string} market
163
+ * @param {number} price
164
+ */
165
+ setPrice(market, price) {
166
+ const ptr0 = passStringToWasm0(market, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
167
+ const len0 = WASM_VECTOR_LEN;
168
+ const ret = wasm.exchange_setPrice(this.__wbg_ptr, ptr0, len0, price);
169
+ if (ret[1]) {
170
+ throw takeFromExternrefTable0(ret[0]);
171
+ }
172
+ }
173
+ /**
174
+ * The current ticker for `market`.
175
+ * @param {string} market
176
+ * @returns {any}
177
+ */
178
+ ticker(market) {
179
+ const ptr0 = passStringToWasm0(market, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
180
+ const len0 = WASM_VECTOR_LEN;
181
+ const ret = wasm.exchange_ticker(this.__wbg_ptr, ptr0, len0);
182
+ if (ret[2]) {
183
+ throw takeFromExternrefTable0(ret[1]);
184
+ }
185
+ return takeFromExternrefTable0(ret[0]);
186
+ }
187
+ }
188
+ if (Symbol.dispose) Exchange.prototype[Symbol.dispose] = Exchange.prototype.free;
189
+
190
+ /**
191
+ * An order request, built with the market/limit factory methods.
192
+ */
193
+ export class OrderRequest {
194
+ static __wrap(ptr) {
195
+ const obj = Object.create(OrderRequest.prototype);
196
+ obj.__wbg_ptr = ptr;
197
+ OrderRequestFinalization.register(obj, obj.__wbg_ptr, obj);
198
+ return obj;
199
+ }
200
+ __destroy_into_raw() {
201
+ const ptr = this.__wbg_ptr;
202
+ this.__wbg_ptr = 0;
203
+ OrderRequestFinalization.unregister(this);
204
+ return ptr;
205
+ }
206
+ free() {
207
+ const ptr = this.__destroy_into_raw();
208
+ wasm.__wbg_orderrequest_free(ptr, 0);
209
+ }
210
+ /**
211
+ * @param {string} market
212
+ * @param {any} quantity
213
+ * @param {any} price
214
+ * @returns {OrderRequest}
215
+ */
216
+ static limitBuy(market, quantity, price) {
217
+ const ptr0 = passStringToWasm0(market, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
218
+ const len0 = WASM_VECTOR_LEN;
219
+ const ret = wasm.orderrequest_limitBuy(ptr0, len0, quantity, price);
220
+ if (ret[2]) {
221
+ throw takeFromExternrefTable0(ret[1]);
222
+ }
223
+ return OrderRequest.__wrap(ret[0]);
224
+ }
225
+ /**
226
+ * @param {string} market
227
+ * @param {any} quantity
228
+ * @param {any} price
229
+ * @returns {OrderRequest}
230
+ */
231
+ static limitSell(market, quantity, price) {
232
+ const ptr0 = passStringToWasm0(market, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
233
+ const len0 = WASM_VECTOR_LEN;
234
+ const ret = wasm.orderrequest_limitSell(ptr0, len0, quantity, price);
235
+ if (ret[2]) {
236
+ throw takeFromExternrefTable0(ret[1]);
237
+ }
238
+ return OrderRequest.__wrap(ret[0]);
239
+ }
240
+ /**
241
+ * @param {string} market
242
+ * @param {any} quantity
243
+ * @returns {OrderRequest}
244
+ */
245
+ static marketBuy(market, quantity) {
246
+ const ptr0 = passStringToWasm0(market, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
247
+ const len0 = WASM_VECTOR_LEN;
248
+ const ret = wasm.orderrequest_marketBuy(ptr0, len0, quantity);
249
+ if (ret[2]) {
250
+ throw takeFromExternrefTable0(ret[1]);
251
+ }
252
+ return OrderRequest.__wrap(ret[0]);
253
+ }
254
+ /**
255
+ * @param {string} market
256
+ * @param {any} quantity
257
+ * @returns {OrderRequest}
258
+ */
259
+ static marketSell(market, quantity) {
260
+ const ptr0 = passStringToWasm0(market, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
261
+ const len0 = WASM_VECTOR_LEN;
262
+ const ret = wasm.orderrequest_marketSell(ptr0, len0, quantity);
263
+ if (ret[2]) {
264
+ throw takeFromExternrefTable0(ret[1]);
265
+ }
266
+ return OrderRequest.__wrap(ret[0]);
267
+ }
268
+ /**
269
+ * Maker-only: the order is cancelled rather than crossing the spread.
270
+ * @returns {OrderRequest}
271
+ */
272
+ postOnly() {
273
+ const ret = wasm.orderrequest_postOnly(this.__wbg_ptr);
274
+ return OrderRequest.__wrap(ret);
275
+ }
276
+ /**
277
+ * Close-only: the order may not increase a position.
278
+ * @returns {OrderRequest}
279
+ */
280
+ reduceOnly() {
281
+ const ret = wasm.orderrequest_reduceOnly(this.__wbg_ptr);
282
+ return OrderRequest.__wrap(ret);
283
+ }
284
+ /**
285
+ * Attach a client order id, so a retried placement is recognised by the
286
+ * venue as the same order rather than placed twice.
287
+ * @param {string} id
288
+ * @returns {OrderRequest}
289
+ */
290
+ withClientOrderId(id) {
291
+ const ptr0 = passStringToWasm0(id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
292
+ const len0 = WASM_VECTOR_LEN;
293
+ const ret = wasm.orderrequest_withClientOrderId(this.__wbg_ptr, ptr0, len0);
294
+ return OrderRequest.__wrap(ret);
295
+ }
296
+ /**
297
+ * Rest until the market reaches `stopPrice`, then fire: a market order
298
+ * becomes a stop-loss, a limit order a stop-limit.
299
+ * @param {any} stop_price
300
+ * @returns {OrderRequest}
301
+ */
302
+ withStopPrice(stop_price) {
303
+ const ret = wasm.orderrequest_withStopPrice(this.__wbg_ptr, stop_price);
304
+ if (ret[2]) {
305
+ throw takeFromExternrefTable0(ret[1]);
306
+ }
307
+ return OrderRequest.__wrap(ret[0]);
308
+ }
309
+ /**
310
+ * Self-trade prevention: `"none"`, `"expire_maker"`, `"expire_taker"` or
311
+ * `"expire_both"` (case-insensitive). Throws on anything else.
312
+ * @param {string} stp
313
+ * @returns {OrderRequest}
314
+ */
315
+ withStp(stp) {
316
+ const ptr0 = passStringToWasm0(stp, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
317
+ const len0 = WASM_VECTOR_LEN;
318
+ const ret = wasm.orderrequest_withStp(this.__wbg_ptr, ptr0, len0);
319
+ if (ret[2]) {
320
+ throw takeFromExternrefTable0(ret[1]);
321
+ }
322
+ return OrderRequest.__wrap(ret[0]);
323
+ }
324
+ /**
325
+ * `"GTC"`, `"IOC"` or `"FOK"` (case-insensitive). Throws on anything else
326
+ * rather than falling back to GTC.
327
+ * @param {string} tif
328
+ * @returns {OrderRequest}
329
+ */
330
+ withTimeInForce(tif) {
331
+ const ptr0 = passStringToWasm0(tif, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
332
+ const len0 = WASM_VECTOR_LEN;
333
+ const ret = wasm.orderrequest_withTimeInForce(this.__wbg_ptr, ptr0, len0);
334
+ if (ret[2]) {
335
+ throw takeFromExternrefTable0(ret[1]);
336
+ }
337
+ return OrderRequest.__wrap(ret[0]);
338
+ }
339
+ }
340
+ if (Symbol.dispose) OrderRequest.prototype[Symbol.dispose] = OrderRequest.prototype.free;
341
+
342
+ /**
343
+ * Route Rust panics to `console.error` with a readable stack.
344
+ *
345
+ * Enabled by the `panic-hook` feature; without it a panic surfaces in JS as
346
+ * "unreachable executed" with nothing pointing at the cause.
347
+ */
348
+ export function start() {
349
+ wasm.start();
350
+ }
351
+
352
+ /**
353
+ * Library version (matches the Rust crate version).
354
+ * @returns {string}
355
+ */
356
+ export function version() {
357
+ let deferred1_0;
358
+ let deferred1_1;
359
+ try {
360
+ const ret = wasm.version();
361
+ deferred1_0 = ret[0];
362
+ deferred1_1 = ret[1];
363
+ return getStringFromWasm0(ret[0], ret[1]);
364
+ } finally {
365
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
366
+ }
367
+ }
368
+ export function __wbg_Error_92b29b0548f8b746(arg0, arg1) {
369
+ const ret = Error(getStringFromWasm0(arg0, arg1));
370
+ return ret;
371
+ }
372
+ export function __wbg_String_8564e559799eccda(arg0, arg1) {
373
+ const ret = String(arg1);
374
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
375
+ const len1 = WASM_VECTOR_LEN;
376
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
377
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
378
+ }
379
+ export function __wbg___wbindgen_boolean_get_fa956cfa2d1bd751(arg0) {
380
+ const v = arg0;
381
+ const ret = typeof(v) === 'boolean' ? v : undefined;
382
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
383
+ }
384
+ export function __wbg___wbindgen_debug_string_c25d447a39f5578f(arg0, arg1) {
385
+ const ret = debugString(arg1);
386
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
387
+ const len1 = WASM_VECTOR_LEN;
388
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
389
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
390
+ }
391
+ export function __wbg___wbindgen_is_function_1ff95bcc5517c252(arg0) {
392
+ const ret = typeof(arg0) === 'function';
393
+ return ret;
394
+ }
395
+ export function __wbg___wbindgen_is_object_a27215656b807791(arg0) {
396
+ const val = arg0;
397
+ const ret = typeof(val) === 'object' && val !== null;
398
+ return ret;
399
+ }
400
+ export function __wbg___wbindgen_is_string_ea5e6cc2e4141dfe(arg0) {
401
+ const ret = typeof(arg0) === 'string';
402
+ return ret;
403
+ }
404
+ export function __wbg___wbindgen_jsval_loose_eq_db4c3b15f63fc170(arg0, arg1) {
405
+ const ret = arg0 == arg1;
406
+ return ret;
407
+ }
408
+ export function __wbg___wbindgen_number_get_394265ed1e1b84ee(arg0, arg1) {
409
+ const obj = arg1;
410
+ const ret = typeof(obj) === 'number' ? obj : undefined;
411
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
412
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
413
+ }
414
+ export function __wbg___wbindgen_string_get_b0ca35b86a603356(arg0, arg1) {
415
+ const obj = arg1;
416
+ const ret = typeof(obj) === 'string' ? obj : undefined;
417
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
418
+ var len1 = WASM_VECTOR_LEN;
419
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
420
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
421
+ }
422
+ export function __wbg___wbindgen_throw_344f42d3211c4765(arg0, arg1) {
423
+ throw new Error(getStringFromWasm0(arg0, arg1));
424
+ }
425
+ export function __wbg_call_8a2dd23819f8a60a() { return handleError(function (arg0, arg1) {
426
+ const ret = arg0.call(arg1);
427
+ return ret;
428
+ }, arguments); }
429
+ export function __wbg_done_89b2b13e91a60321(arg0) {
430
+ const ret = arg0.done;
431
+ return ret;
432
+ }
433
+ export function __wbg_entries_015dc610cd81ede0(arg0) {
434
+ const ret = Object.entries(arg0);
435
+ return ret;
436
+ }
437
+ export function __wbg_error_a6fa202b58aa1cd3(arg0, arg1) {
438
+ let deferred0_0;
439
+ let deferred0_1;
440
+ try {
441
+ deferred0_0 = arg0;
442
+ deferred0_1 = arg1;
443
+ console.error(getStringFromWasm0(arg0, arg1));
444
+ } finally {
445
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
446
+ }
447
+ }
448
+ export function __wbg_get_507a50627bffa49b(arg0, arg1) {
449
+ const ret = arg0[arg1 >>> 0];
450
+ return ret;
451
+ }
452
+ export function __wbg_get_c7eb1f358a7654df() { return handleError(function (arg0, arg1) {
453
+ const ret = Reflect.get(arg0, arg1);
454
+ return ret;
455
+ }, arguments); }
456
+ export function __wbg_get_unchecked_6e0ad6d2a41b06f6(arg0, arg1) {
457
+ const ret = arg0[arg1 >>> 0];
458
+ return ret;
459
+ }
460
+ export function __wbg_instanceof_ArrayBuffer_4480b9e0068a8adb(arg0) {
461
+ let result;
462
+ try {
463
+ result = arg0 instanceof ArrayBuffer;
464
+ } catch (_) {
465
+ result = false;
466
+ }
467
+ const ret = result;
468
+ return ret;
469
+ }
470
+ export function __wbg_instanceof_Uint8Array_309b927aaf7a3fc7(arg0) {
471
+ let result;
472
+ try {
473
+ result = arg0 instanceof Uint8Array;
474
+ } catch (_) {
475
+ result = false;
476
+ }
477
+ const ret = result;
478
+ return ret;
479
+ }
480
+ export function __wbg_iterator_6f722e4a93058b71() {
481
+ const ret = Symbol.iterator;
482
+ return ret;
483
+ }
484
+ export function __wbg_length_1f0964f4a5e2c6d8(arg0) {
485
+ const ret = arg0.length;
486
+ return ret;
487
+ }
488
+ export function __wbg_length_370319915dc99107(arg0) {
489
+ const ret = arg0.length;
490
+ return ret;
491
+ }
492
+ export function __wbg_new_227d7c05414eb861() {
493
+ const ret = new Error();
494
+ return ret;
495
+ }
496
+ export function __wbg_new_32b398fb48b6d94a() {
497
+ const ret = new Array();
498
+ return ret;
499
+ }
500
+ export function __wbg_new_7796ffc7ed656783() {
501
+ const ret = new Map();
502
+ return ret;
503
+ }
504
+ export function __wbg_new_cd45aabdf6073e84(arg0) {
505
+ const ret = new Uint8Array(arg0);
506
+ return ret;
507
+ }
508
+ export function __wbg_new_da52cf8fe3429cb2() {
509
+ const ret = new Object();
510
+ return ret;
511
+ }
512
+ export function __wbg_next_6dbf2c0ac8cde20f(arg0) {
513
+ const ret = arg0.next;
514
+ return ret;
515
+ }
516
+ export function __wbg_next_71f2aa1cb3d1e37e() { return handleError(function (arg0) {
517
+ const ret = arg0.next();
518
+ return ret;
519
+ }, arguments); }
520
+ export function __wbg_prototypesetcall_4770620bbe4688a0(arg0, arg1, arg2) {
521
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
522
+ }
523
+ export function __wbg_set_575dd786d51585f8(arg0, arg1, arg2) {
524
+ const ret = arg0.set(arg1, arg2);
525
+ return ret;
526
+ }
527
+ export function __wbg_set_6be42768c690e380(arg0, arg1, arg2) {
528
+ arg0[arg1] = arg2;
529
+ }
530
+ export function __wbg_set_8a16b38e4805b298(arg0, arg1, arg2) {
531
+ arg0[arg1 >>> 0] = arg2;
532
+ }
533
+ export function __wbg_stack_3b0d974bbf31e44f(arg0, arg1) {
534
+ const ret = arg1.stack;
535
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
536
+ const len1 = WASM_VECTOR_LEN;
537
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
538
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
539
+ }
540
+ export function __wbg_value_a5d5488a9589444a(arg0) {
541
+ const ret = arg0.value;
542
+ return ret;
543
+ }
544
+ export function __wbindgen_cast_0000000000000001(arg0) {
545
+ // Cast intrinsic for `F64 -> Externref`.
546
+ const ret = arg0;
547
+ return ret;
548
+ }
549
+ export function __wbindgen_cast_0000000000000002(arg0) {
550
+ // Cast intrinsic for `I64 -> Externref`.
551
+ const ret = arg0;
552
+ return ret;
553
+ }
554
+ export function __wbindgen_cast_0000000000000003(arg0, arg1) {
555
+ // Cast intrinsic for `Ref(String) -> Externref`.
556
+ const ret = getStringFromWasm0(arg0, arg1);
557
+ return ret;
558
+ }
559
+ export function __wbindgen_init_externref_table() {
560
+ const table = wasm.__wbindgen_externrefs;
561
+ const offset = table.grow(4);
562
+ table.set(0, undefined);
563
+ table.set(offset + 0, undefined);
564
+ table.set(offset + 1, null);
565
+ table.set(offset + 2, true);
566
+ table.set(offset + 3, false);
567
+ }
568
+ const ExchangeFinalization = (typeof FinalizationRegistry === 'undefined')
569
+ ? { register: () => {}, unregister: () => {} }
570
+ : new FinalizationRegistry(ptr => wasm.__wbg_exchange_free(ptr, 1));
571
+ const OrderRequestFinalization = (typeof FinalizationRegistry === 'undefined')
572
+ ? { register: () => {}, unregister: () => {} }
573
+ : new FinalizationRegistry(ptr => wasm.__wbg_orderrequest_free(ptr, 1));
574
+
575
+ function addToExternrefTable0(obj) {
576
+ const idx = wasm.__externref_table_alloc();
577
+ wasm.__wbindgen_externrefs.set(idx, obj);
578
+ return idx;
579
+ }
580
+
581
+ function _assertClass(instance, klass) {
582
+ if (!(instance instanceof klass)) {
583
+ throw new Error(`expected instance of ${klass.name}`);
584
+ }
585
+ }
586
+
587
+ function debugString(val) {
588
+ // primitive types
589
+ const type = typeof val;
590
+ if (type == 'number' || type == 'boolean' || val == null) {
591
+ return `${val}`;
592
+ }
593
+ if (type == 'string') {
594
+ return `"${val}"`;
595
+ }
596
+ if (type == 'symbol') {
597
+ const description = val.description;
598
+ if (description == null) {
599
+ return 'Symbol';
600
+ } else {
601
+ return `Symbol(${description})`;
602
+ }
603
+ }
604
+ if (type == 'function') {
605
+ const name = val.name;
606
+ if (typeof name == 'string' && name.length > 0) {
607
+ return `Function(${name})`;
608
+ } else {
609
+ return 'Function';
610
+ }
611
+ }
612
+ // objects
613
+ if (Array.isArray(val)) {
614
+ const length = val.length;
615
+ let debug = '[';
616
+ if (length > 0) {
617
+ debug += debugString(val[0]);
618
+ }
619
+ for(let i = 1; i < length; i++) {
620
+ debug += ', ' + debugString(val[i]);
621
+ }
622
+ debug += ']';
623
+ return debug;
624
+ }
625
+ // Test for built-in
626
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
627
+ let className;
628
+ if (builtInMatches && builtInMatches.length > 1) {
629
+ className = builtInMatches[1];
630
+ } else {
631
+ // Failed to match the standard '[object ClassName]'
632
+ return toString.call(val);
633
+ }
634
+ if (className == 'Object') {
635
+ // we're a user defined class or Object
636
+ // JSON.stringify avoids problems with cycles, and is generally much
637
+ // easier than looping through ownProperties of `val`.
638
+ try {
639
+ return 'Object(' + JSON.stringify(val) + ')';
640
+ } catch (_) {
641
+ return 'Object';
642
+ }
643
+ }
644
+ // errors
645
+ if (val instanceof Error) {
646
+ return `${val.name}: ${val.message}\n${val.stack}`;
647
+ }
648
+ // TODO we could test for more things here, like `Set`s and `Map`s.
649
+ return className;
650
+ }
651
+
652
+ function getArrayU8FromWasm0(ptr, len) {
653
+ ptr = ptr >>> 0;
654
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
655
+ }
656
+
657
+ let cachedDataViewMemory0 = null;
658
+ function getDataViewMemory0() {
659
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
660
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
661
+ }
662
+ return cachedDataViewMemory0;
663
+ }
664
+
665
+ let cachedFloat64ArrayMemory0 = null;
666
+ function getFloat64ArrayMemory0() {
667
+ if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
668
+ cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
669
+ }
670
+ return cachedFloat64ArrayMemory0;
671
+ }
672
+
673
+ function getStringFromWasm0(ptr, len) {
674
+ return decodeText(ptr >>> 0, len);
675
+ }
676
+
677
+ let cachedUint8ArrayMemory0 = null;
678
+ function getUint8ArrayMemory0() {
679
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
680
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
681
+ }
682
+ return cachedUint8ArrayMemory0;
683
+ }
684
+
685
+ function handleError(f, args) {
686
+ try {
687
+ return f.apply(this, args);
688
+ } catch (e) {
689
+ const idx = addToExternrefTable0(e);
690
+ wasm.__wbindgen_exn_store(idx);
691
+ }
692
+ }
693
+
694
+ function isLikeNone(x) {
695
+ return x === undefined || x === null;
696
+ }
697
+
698
+ function passArrayF64ToWasm0(arg, malloc) {
699
+ const ptr = malloc(arg.length * 8, 8) >>> 0;
700
+ getFloat64ArrayMemory0().set(arg, ptr / 8);
701
+ WASM_VECTOR_LEN = arg.length;
702
+ return ptr;
703
+ }
704
+
705
+ function passStringToWasm0(arg, malloc, realloc) {
706
+ if (realloc === undefined) {
707
+ const buf = cachedTextEncoder.encode(arg);
708
+ const ptr = malloc(buf.length, 1) >>> 0;
709
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
710
+ WASM_VECTOR_LEN = buf.length;
711
+ return ptr;
712
+ }
713
+
714
+ let len = arg.length;
715
+ let ptr = malloc(len, 1) >>> 0;
716
+
717
+ const mem = getUint8ArrayMemory0();
718
+
719
+ let offset = 0;
720
+
721
+ for (; offset < len; offset++) {
722
+ const code = arg.charCodeAt(offset);
723
+ if (code > 0x7F) break;
724
+ mem[ptr + offset] = code;
725
+ }
726
+ if (offset !== len) {
727
+ if (offset !== 0) {
728
+ arg = arg.slice(offset);
729
+ }
730
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
731
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
732
+ const ret = cachedTextEncoder.encodeInto(arg, view);
733
+
734
+ offset += ret.written;
735
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
736
+ }
737
+
738
+ WASM_VECTOR_LEN = offset;
739
+ return ptr;
740
+ }
741
+
742
+ function takeFromExternrefTable0(idx) {
743
+ const value = wasm.__wbindgen_externrefs.get(idx);
744
+ wasm.__externref_table_dealloc(idx);
745
+ return value;
746
+ }
747
+
748
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
749
+ cachedTextDecoder.decode();
750
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
751
+ let numBytesDecoded = 0;
752
+ function decodeText(ptr, len) {
753
+ numBytesDecoded += len;
754
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
755
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
756
+ cachedTextDecoder.decode();
757
+ numBytesDecoded = len;
758
+ }
759
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
760
+ }
761
+
762
+ const cachedTextEncoder = new TextEncoder();
763
+
764
+ if (!('encodeInto' in cachedTextEncoder)) {
765
+ cachedTextEncoder.encodeInto = function (arg, view) {
766
+ const buf = cachedTextEncoder.encode(arg);
767
+ view.set(buf);
768
+ return {
769
+ read: arg.length,
770
+ written: buf.length
771
+ };
772
+ };
773
+ }
774
+
775
+ let WASM_VECTOR_LEN = 0;
776
+
777
+
778
+ let wasm;
779
+ export function __wbg_set_wasm(val) {
780
+ wasm = val;
781
+ }
Binary file