@stryke-xyz/premarket-sdk 1.0.8 → 1.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 +5 -36
- package/dist/cjs/api/orderbook-api/index.js +25 -61
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/shared/types.js +1 -1
- package/dist/cjs/sync/clients/activity-client.js +11 -17
- package/dist/cjs/sync/clients/order-client.js +84 -150
- package/dist/cjs/sync/index.js +0 -4
- package/dist/esm/api/orderbook-api/index.js +25 -61
- package/dist/esm/package.json +1 -1
- package/dist/esm/shared/types.js +1 -1
- package/dist/esm/sync/clients/activity-client.js +11 -17
- package/dist/esm/sync/clients/order-client.js +84 -150
- package/dist/esm/sync/index.js +0 -1
- package/dist/esm/sync/types.js +1 -3
- package/dist/types/api/orderbook-api/index.d.ts +16 -12
- package/dist/types/shared/types.d.ts +4 -27
- package/dist/types/sync/clients/order-client.d.ts +9 -12
- package/dist/types/sync/index.d.ts +2 -3
- package/dist/types/sync/types.d.ts +0 -23
- package/package.json +1 -1
- package/dist/cjs/api/README.md +0 -296
- package/dist/cjs/config/README.md +0 -112
- package/dist/cjs/exchange/README.md +0 -280
- package/dist/cjs/registry/README.md +0 -150
- package/dist/cjs/shared/README.md +0 -235
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/sync/README.md +0 -215
- package/dist/cjs/sync/clients/base-client.js +0 -518
- package/dist/cjs/sync/redis-ws-client.js +0 -235
- package/dist/cjs/utils/README.md +0 -89
- package/dist/cjs/vault/README.md +0 -268
- package/dist/esm/api/README.md +0 -296
- package/dist/esm/config/README.md +0 -112
- package/dist/esm/exchange/README.md +0 -280
- package/dist/esm/registry/README.md +0 -150
- package/dist/esm/shared/README.md +0 -235
- package/dist/esm/shared/utils.js +0 -0
- package/dist/esm/sync/README.md +0 -215
- package/dist/esm/sync/clients/base-client.js +0 -508
- package/dist/esm/sync/redis-ws-client.js +0 -225
- package/dist/esm/utils/README.md +0 -89
- package/dist/esm/vault/README.md +0 -268
- package/dist/types/shared/utils.d.ts +0 -0
- package/dist/types/sync/clients/base-client.d.ts +0 -56
- package/dist/types/sync/redis-ws-client.d.ts +0 -21
package/README.md
CHANGED
|
@@ -315,9 +315,8 @@ Public order methods:
|
|
|
315
315
|
|
|
316
316
|
- `createOrder(params, bearerToken)`
|
|
317
317
|
- `getOrder(orderHash)`
|
|
318
|
-
- `
|
|
319
|
-
- `getUserOrders(maker, marketId)`
|
|
320
|
-
- `getDepthSnapshot(marketId, tokenId)`
|
|
318
|
+
- `getOrders(marketId, maker?)` — active orders for a market, optionally scoped to a maker
|
|
319
|
+
- `getUserOrders(maker, marketId)` — convenience wrapper around `getOrders`
|
|
321
320
|
|
|
322
321
|
Public market methods:
|
|
323
322
|
|
|
@@ -349,9 +348,9 @@ Auth-related methods also exposed by the SDK:
|
|
|
349
348
|
|
|
350
349
|
Integration note:
|
|
351
350
|
|
|
352
|
-
- `getUserOrders`
|
|
353
|
-
|
|
354
|
-
|
|
351
|
+
- `getOrders` and `getUserOrders` both require a `marketId`. Returned orders
|
|
352
|
+
are restricted to active and partially-filled (cancelled / fully-filled
|
|
353
|
+
/ expired are filtered server-side).
|
|
355
354
|
|
|
356
355
|
### Deserializers
|
|
357
356
|
|
|
@@ -361,8 +360,6 @@ The API returns string-heavy DTOs because JSON cannot safely transport
|
|
|
361
360
|
- `orderToBigInt`
|
|
362
361
|
- `storedOrderToBigInt`
|
|
363
362
|
- `ordersSnapshotToBigInt`
|
|
364
|
-
- `queryOrdersResponseToBigInt`
|
|
365
|
-
- `depthSnapshotToBigInt`
|
|
366
363
|
- `marketInstrumentToBigInt`
|
|
367
364
|
- `marketToBigInt`
|
|
368
365
|
- `marketsToBigInt`
|
|
@@ -573,9 +570,6 @@ Public exports:
|
|
|
573
570
|
|
|
574
571
|
- `SyncStatus`
|
|
575
572
|
- `"connecting" | "syncing" | "synced" | "recovering" | "disconnected" | "error"`
|
|
576
|
-
- `OrderChange`
|
|
577
|
-
- `SequencedMessage`
|
|
578
|
-
- `SyncClientConfig`
|
|
579
573
|
|
|
580
574
|
### MarketDepthSyncClient
|
|
581
575
|
|
|
@@ -620,7 +614,6 @@ Public event types:
|
|
|
620
614
|
- `DepthLevel`
|
|
621
615
|
- `TokenDepthSnapshot`
|
|
622
616
|
- `DepthLevelUpdate`
|
|
623
|
-
- `DepthChangeEvent`
|
|
624
617
|
- `DepthUpdate`
|
|
625
618
|
|
|
626
619
|
Implementation details captured by the client:
|
|
@@ -662,27 +655,6 @@ Public event type:
|
|
|
662
655
|
|
|
663
656
|
- `OrderFillEvent`
|
|
664
657
|
|
|
665
|
-
### BaseSyncClient
|
|
666
|
-
|
|
667
|
-
This is the advanced extension point for custom sequenced Redis-backed clients.
|
|
668
|
-
|
|
669
|
-
Public methods:
|
|
670
|
-
|
|
671
|
-
- `connect()`
|
|
672
|
-
- `disconnect()`
|
|
673
|
-
- `getStatus()`
|
|
674
|
-
- `isSynced()`
|
|
675
|
-
- `getLastSequence()`
|
|
676
|
-
- `getBufferedCount()`
|
|
677
|
-
- `onStatus(callback)`
|
|
678
|
-
- `onChange(callback)`
|
|
679
|
-
- `onSnapshot(callback)`
|
|
680
|
-
|
|
681
|
-
Subclass responsibilities:
|
|
682
|
-
|
|
683
|
-
- provide `fetchSnapshot()`
|
|
684
|
-
- provide `applyMessage(message)`
|
|
685
|
-
|
|
686
658
|
## Config Module
|
|
687
659
|
|
|
688
660
|
Source files:
|
|
@@ -772,11 +744,8 @@ Main exports:
|
|
|
772
744
|
- `MatchedOrder`
|
|
773
745
|
- `MatchResult`
|
|
774
746
|
- `CreateOrderResult`
|
|
775
|
-
- `OrderQueryParams`
|
|
776
747
|
- `OrderResponse`
|
|
777
748
|
- `OrdersSnapshot`
|
|
778
|
-
- `QueryOrdersResponse`
|
|
779
|
-
- `DepthSnapshot`
|
|
780
749
|
|
|
781
750
|
Main order write shape:
|
|
782
751
|
|
|
@@ -409,7 +409,14 @@ function _ts_generator(thisArg, body) {
|
|
|
409
409
|
// ORDERBOOK METHODS
|
|
410
410
|
// ============================================================================
|
|
411
411
|
/**
|
|
412
|
-
*
|
|
412
|
+
* Submits a new order and synchronously returns the engine's match outcome.
|
|
413
|
+
*
|
|
414
|
+
* The backend awaits the matching engine's reply (up to ~2s) before
|
|
415
|
+
* responding, so callers get the full `matchResult` (`matches`, totals,
|
|
416
|
+
* `createdOrder`) inline. If the engine reply does not arrive in time
|
|
417
|
+
* `matchResult.message === "awaiting match"` and `matches` is empty —
|
|
418
|
+
* clients should then poll `getOrder(orderHash)` or watch the user
|
|
419
|
+
* activity WS for the eventual fill.
|
|
413
420
|
*/ function createOrder(params, bearerToken) {
|
|
414
421
|
return _async_to_generator(function() {
|
|
415
422
|
return _ts_generator(this, function(_state) {
|
|
@@ -454,30 +461,28 @@ function _ts_generator(thisArg, body) {
|
|
|
454
461
|
}
|
|
455
462
|
},
|
|
456
463
|
{
|
|
457
|
-
key: "
|
|
464
|
+
key: "getOrders",
|
|
458
465
|
value: /**
|
|
459
|
-
*
|
|
460
|
-
|
|
466
|
+
* Returns active (non-cancelled, non-fully-filled, non-expired) orders for a market.
|
|
467
|
+
* If `maker` is provided, scopes to a single user's open orders.
|
|
468
|
+
*/ function getOrders(marketId, maker) {
|
|
461
469
|
return _async_to_generator(function() {
|
|
462
|
-
var
|
|
470
|
+
var _ref, data;
|
|
463
471
|
return _ts_generator(this, function(_state) {
|
|
464
472
|
switch(_state.label){
|
|
465
473
|
case 0:
|
|
466
|
-
url = this.buildUrl("/orderbook/api/orders", {
|
|
467
|
-
marketId: params.marketId,
|
|
468
|
-
maker: params.maker,
|
|
469
|
-
status: params.status,
|
|
470
|
-
limit: params.limit,
|
|
471
|
-
offset: params.offset
|
|
472
|
-
});
|
|
473
474
|
return [
|
|
474
475
|
4,
|
|
475
|
-
this.requestEnvelope(
|
|
476
|
+
this.requestEnvelope(this.buildUrl("/orderbook/api/orders", {
|
|
477
|
+
marketId: marketId,
|
|
478
|
+
maker: maker
|
|
479
|
+
}), undefined, "Failed to fetch orders")
|
|
476
480
|
];
|
|
477
481
|
case 1:
|
|
482
|
+
data = _state.sent();
|
|
478
483
|
return [
|
|
479
484
|
2,
|
|
480
|
-
|
|
485
|
+
(_ref = data === null || data === void 0 ? void 0 : data.orders) !== null && _ref !== void 0 ? _ref : []
|
|
481
486
|
];
|
|
482
487
|
}
|
|
483
488
|
});
|
|
@@ -487,56 +492,15 @@ function _ts_generator(thisArg, body) {
|
|
|
487
492
|
{
|
|
488
493
|
key: "getUserOrders",
|
|
489
494
|
value: /**
|
|
490
|
-
*
|
|
491
|
-
*
|
|
495
|
+
* Returns active orders for a single user in a market.
|
|
496
|
+
* Convenience wrapper around `getOrders(marketId, maker)`.
|
|
492
497
|
*/ function getUserOrders(maker, marketId) {
|
|
493
|
-
return _async_to_generator(function() {
|
|
494
|
-
var data;
|
|
495
|
-
return _ts_generator(this, function(_state) {
|
|
496
|
-
switch(_state.label){
|
|
497
|
-
case 0:
|
|
498
|
-
if (!marketId) {
|
|
499
|
-
throw new Error("marketId is required to fetch user orders");
|
|
500
|
-
}
|
|
501
|
-
return [
|
|
502
|
-
4,
|
|
503
|
-
this.requestEnvelope(this.buildUrl("/orderbook/api/orders/user/".concat(encodeURIComponent(maker)), {
|
|
504
|
-
marketId: marketId
|
|
505
|
-
}), undefined, "Failed to get orders snapshot")
|
|
506
|
-
];
|
|
507
|
-
case 1:
|
|
508
|
-
data = _state.sent();
|
|
509
|
-
return [
|
|
510
|
-
2,
|
|
511
|
-
(data === null || data === void 0 ? void 0 : data.orders) || []
|
|
512
|
-
];
|
|
513
|
-
}
|
|
514
|
-
});
|
|
515
|
-
}).call(this);
|
|
516
|
-
}
|
|
517
|
-
},
|
|
518
|
-
{
|
|
519
|
-
key: "getDepthSnapshot",
|
|
520
|
-
value: /**
|
|
521
|
-
* Fetches the current depth snapshot for one market and token pair.
|
|
522
|
-
*/ function getDepthSnapshot(marketId, tokenId) {
|
|
523
498
|
return _async_to_generator(function() {
|
|
524
499
|
return _ts_generator(this, function(_state) {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
this.requestEnvelope(this.buildUrl("/orderbook/api/depth", {
|
|
530
|
-
marketId: marketId,
|
|
531
|
-
tokenId: tokenId
|
|
532
|
-
}), undefined, "Failed to get depth snapshot")
|
|
533
|
-
];
|
|
534
|
-
case 1:
|
|
535
|
-
return [
|
|
536
|
-
2,
|
|
537
|
-
_state.sent()
|
|
538
|
-
];
|
|
539
|
-
}
|
|
500
|
+
return [
|
|
501
|
+
2,
|
|
502
|
+
this.getOrders(marketId, maker)
|
|
503
|
+
];
|
|
540
504
|
});
|
|
541
505
|
}).call(this);
|
|
542
506
|
}
|
package/dist/cjs/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@stryke-xyz/premarket-sdk","version":"1.0
|
|
1
|
+
{"name":"@stryke-xyz/premarket-sdk","version":"1.1.0","type":"commonjs"}
|
package/dist/cjs/shared/types.js
CHANGED
|
@@ -21,7 +21,7 @@ Object.defineProperty(exports, "OrderStatus", {
|
|
|
21
21
|
OrderStatus["CANCELLED"] = "CANCELLED";
|
|
22
22
|
OrderStatus["EXPIRED"] = "EXPIRED";
|
|
23
23
|
return OrderStatus;
|
|
24
|
-
}({})/** If true, amount is in maker's makingAmount units. If false, amount is in maker's takingAmount units. */ /** The amount to pass to Exchange.fillOrder */ /** Whether fillAmount is in maker's makingAmount units (true) or takingAmount units (false) */ // ============================================================================
|
|
24
|
+
}({})/** If true, amount is in maker's makingAmount units. If false, amount is in maker's takingAmount units. */ /** The amount to pass to Exchange.fillOrder */ /** Whether fillAmount is in maker's makingAmount units (true) or takingAmount units (false) */ /** True if the user-submitted order's `amount` is in maker's makingAmount units. */ /** Set to "awaiting match" when the engine's match tail did not arrive within the API's wait window. */ // ============================================================================
|
|
25
25
|
// MARKET TYPES
|
|
26
26
|
// ============================================================================
|
|
27
27
|
// ============================================================================
|
|
@@ -250,8 +250,8 @@ function _ts_generator(thisArg, body) {
|
|
|
250
250
|
new Promise(function(resolve, reject) {
|
|
251
251
|
var settled = false;
|
|
252
252
|
var expectedSubscriptions = new Set();
|
|
253
|
-
if (_this.config.marketId) expectedSubscriptions.add("
|
|
254
|
-
if (_this.config.userAddress) expectedSubscriptions.add("
|
|
253
|
+
if (_this.config.marketId) expectedSubscriptions.add("subscribed_fills");
|
|
254
|
+
if (_this.config.userAddress) expectedSubscriptions.add("subscribed_user");
|
|
255
255
|
var resolveOnce = function() {
|
|
256
256
|
if (settled) return;
|
|
257
257
|
settled = true;
|
|
@@ -268,16 +268,14 @@ function _ts_generator(thisArg, body) {
|
|
|
268
268
|
_this.lastPongTime = Date.now();
|
|
269
269
|
if (_this.config.marketId) {
|
|
270
270
|
_this.ws.send(JSON.stringify({
|
|
271
|
-
type: "
|
|
272
|
-
channel: "orders_matched",
|
|
271
|
+
type: "subscribe_fills",
|
|
273
272
|
marketId: _this.config.marketId
|
|
274
273
|
}));
|
|
275
274
|
}
|
|
276
275
|
if (_this.config.userAddress) {
|
|
277
276
|
_this.ws.send(JSON.stringify({
|
|
278
|
-
type: "
|
|
279
|
-
|
|
280
|
-
userAddress: _this.config.userAddress
|
|
277
|
+
type: "subscribe_user",
|
|
278
|
+
address: _this.config.userAddress
|
|
281
279
|
}));
|
|
282
280
|
}
|
|
283
281
|
_this.startHeartbeat();
|
|
@@ -290,17 +288,15 @@ function _ts_generator(thisArg, body) {
|
|
|
290
288
|
_this.clearHeartbeatTimeout();
|
|
291
289
|
return;
|
|
292
290
|
}
|
|
293
|
-
if (msg.type === "
|
|
294
|
-
|
|
295
|
-
expectedSubscriptions.delete(msg.channel);
|
|
296
|
-
}
|
|
291
|
+
if (msg.type === "subscribed_fills" || msg.type === "subscribed_user") {
|
|
292
|
+
expectedSubscriptions.delete(msg.type);
|
|
297
293
|
if (expectedSubscriptions.size === 0) {
|
|
298
294
|
_this.setStatus("synced");
|
|
299
295
|
resolveOnce();
|
|
300
296
|
}
|
|
301
297
|
return;
|
|
302
298
|
}
|
|
303
|
-
if (msg.type === "
|
|
299
|
+
if (msg.type === "unsubscribed_fills" || msg.type === "unsubscribed_user") {
|
|
304
300
|
return;
|
|
305
301
|
}
|
|
306
302
|
if (msg.type === "error") {
|
|
@@ -594,8 +590,7 @@ function _ts_generator(thisArg, body) {
|
|
|
594
590
|
if (this.config.marketId) {
|
|
595
591
|
try {
|
|
596
592
|
this.ws.send(JSON.stringify({
|
|
597
|
-
type: "
|
|
598
|
-
channel: "orders_matched",
|
|
593
|
+
type: "unsubscribe_fills",
|
|
599
594
|
marketId: this.config.marketId
|
|
600
595
|
}));
|
|
601
596
|
} catch (unused) {}
|
|
@@ -603,9 +598,8 @@ function _ts_generator(thisArg, body) {
|
|
|
603
598
|
/* ignore */ if (this.config.userAddress) {
|
|
604
599
|
try {
|
|
605
600
|
this.ws.send(JSON.stringify({
|
|
606
|
-
type: "
|
|
607
|
-
|
|
608
|
-
userAddress: this.config.userAddress
|
|
601
|
+
type: "unsubscribe_user",
|
|
602
|
+
address: this.config.userAddress
|
|
609
603
|
}));
|
|
610
604
|
} catch (unused) {}
|
|
611
605
|
}
|