@alpha-arcade/sdk 0.3.1 → 0.3.6
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 +167 -4
- package/dist/index.cjs +339 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +189 -2
- package/dist/index.d.ts +189 -2
- package/dist/index.js +338 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -49,6 +49,7 @@ type Market = {
|
|
|
49
49
|
feeBase?: number;
|
|
50
50
|
/** Liquidty Rewards Info */
|
|
51
51
|
totalRewards?: number;
|
|
52
|
+
totalPregameRewards?: number;
|
|
52
53
|
rewardsPaidOut?: number;
|
|
53
54
|
rewardsSpreadDistance?: number;
|
|
54
55
|
rewardsMinContracts?: number;
|
|
@@ -67,6 +68,13 @@ type MarketOption = {
|
|
|
67
68
|
noAssetId: number;
|
|
68
69
|
yesProb: number;
|
|
69
70
|
noProb: number;
|
|
71
|
+
totalRewards?: number;
|
|
72
|
+
totalPregameRewards?: number;
|
|
73
|
+
rewardsPaidOut?: number;
|
|
74
|
+
rewardsSpreadDistance?: number;
|
|
75
|
+
rewardsMinContracts?: number;
|
|
76
|
+
lastRewardAmount?: number;
|
|
77
|
+
lastRewardTs?: number;
|
|
70
78
|
[key: string]: unknown;
|
|
71
79
|
};
|
|
72
80
|
/** Global state of a market app read from on-chain */
|
|
@@ -276,6 +284,11 @@ type AggregatedOrderbook = {
|
|
|
276
284
|
yes: AggregatedOrderbookSide;
|
|
277
285
|
no: AggregatedOrderbookSide;
|
|
278
286
|
};
|
|
287
|
+
/**
|
|
288
|
+
* Full processed market orderbook keyed by marketAppId.
|
|
289
|
+
* Matches the REST `/get-full-orderbook` response and `orderbook_changed.orderbook`.
|
|
290
|
+
*/
|
|
291
|
+
type FullOrderbookSnapshot = Record<string, WsOrderbookApp>;
|
|
279
292
|
/** Parameters for split shares */
|
|
280
293
|
type SplitSharesParams = {
|
|
281
294
|
/** Market app ID */
|
|
@@ -362,6 +375,78 @@ type EscrowGlobalState = {
|
|
|
362
375
|
asset_listed?: number;
|
|
363
376
|
fee_timer_start?: number;
|
|
364
377
|
};
|
|
378
|
+
/** Configuration for AlphaWebSocket */
|
|
379
|
+
type AlphaWebSocketConfig = {
|
|
380
|
+
/** WebSocket URL override (default: wss://wss.platform.alphaarcade.com) */
|
|
381
|
+
url?: string;
|
|
382
|
+
/** Enable auto-reconnect on unexpected disconnect (default: true) */
|
|
383
|
+
reconnect?: boolean;
|
|
384
|
+
/** Maximum reconnect attempts before giving up (default: Infinity) */
|
|
385
|
+
maxReconnectAttempts?: number;
|
|
386
|
+
/** Heartbeat interval in ms (default: 60000) */
|
|
387
|
+
heartbeatIntervalMs?: number;
|
|
388
|
+
/**
|
|
389
|
+
* WebSocket constructor to use. Defaults to the global `WebSocket`.
|
|
390
|
+
* On Node.js < 22, pass the `ws` package: `import WebSocket from 'ws'; new AlphaWebSocket({ WebSocket })`
|
|
391
|
+
*/
|
|
392
|
+
WebSocket?: unknown;
|
|
393
|
+
};
|
|
394
|
+
/** Orderbook bid/ask entry at the top level (decimal cents) */
|
|
395
|
+
type WsOrderbookAggregatedEntry = {
|
|
396
|
+
price: number;
|
|
397
|
+
quantity: number;
|
|
398
|
+
total: number;
|
|
399
|
+
};
|
|
400
|
+
/** Orderbook bid/ask entry with escrow details (raw microunit prices) */
|
|
401
|
+
type WsOrderbookDetailEntry = {
|
|
402
|
+
price: number;
|
|
403
|
+
quantity: number;
|
|
404
|
+
total: number;
|
|
405
|
+
escrowAppId: number;
|
|
406
|
+
owner: string;
|
|
407
|
+
};
|
|
408
|
+
/** Per-side orderbook detail (yes or no) */
|
|
409
|
+
type WsOrderbookDetailSide = {
|
|
410
|
+
bids: WsOrderbookDetailEntry[];
|
|
411
|
+
asks: WsOrderbookDetailEntry[];
|
|
412
|
+
};
|
|
413
|
+
/** Orderbook data for a single app within the orderbook payload */
|
|
414
|
+
type WsOrderbookApp = {
|
|
415
|
+
bids: WsOrderbookAggregatedEntry[];
|
|
416
|
+
asks: WsOrderbookAggregatedEntry[];
|
|
417
|
+
spread: number;
|
|
418
|
+
yes: WsOrderbookDetailSide;
|
|
419
|
+
no: WsOrderbookDetailSide;
|
|
420
|
+
};
|
|
421
|
+
/** Payload for orderbook_changed events */
|
|
422
|
+
type OrderbookChangedEvent = {
|
|
423
|
+
type: 'orderbook_changed';
|
|
424
|
+
ts: number;
|
|
425
|
+
marketId: string;
|
|
426
|
+
slug?: string;
|
|
427
|
+
version: number;
|
|
428
|
+
orderbook: FullOrderbookSnapshot;
|
|
429
|
+
};
|
|
430
|
+
/** Payload for markets_changed events (incremental diffs) */
|
|
431
|
+
type MarketsChangedEvent = {
|
|
432
|
+
type: 'markets_changed';
|
|
433
|
+
ts: number;
|
|
434
|
+
[key: string]: unknown;
|
|
435
|
+
};
|
|
436
|
+
/** Payload for market_changed events (single market) */
|
|
437
|
+
type MarketChangedEvent = {
|
|
438
|
+
type: 'market_changed';
|
|
439
|
+
ts: number;
|
|
440
|
+
[key: string]: unknown;
|
|
441
|
+
};
|
|
442
|
+
/** Payload for wallet_orders_changed events */
|
|
443
|
+
type WalletOrdersChangedEvent = {
|
|
444
|
+
type: 'wallet_orders_changed';
|
|
445
|
+
ts: number;
|
|
446
|
+
[key: string]: unknown;
|
|
447
|
+
};
|
|
448
|
+
/** Discriminated union of all WebSocket stream events */
|
|
449
|
+
type WebSocketStreamEvent = MarketsChangedEvent | MarketChangedEvent | OrderbookChangedEvent | WalletOrdersChangedEvent;
|
|
365
450
|
|
|
366
451
|
/**
|
|
367
452
|
* The main client for interacting with Alpha Market prediction markets on Algorand.
|
|
@@ -369,7 +454,7 @@ type EscrowGlobalState = {
|
|
|
369
454
|
* Provides methods for:
|
|
370
455
|
* - **Trading**: Create limit/market orders, cancel orders, propose matches
|
|
371
456
|
* - **Positions**: Split/merge shares, claim resolved tokens, view positions
|
|
372
|
-
* - **Orderbook**: Read on-chain
|
|
457
|
+
* - **Orderbook**: Read on-chain orderbooks or fetch full API-backed market snapshots
|
|
373
458
|
* - **Markets**: Fetch live markets from the Alpha API
|
|
374
459
|
*
|
|
375
460
|
* @example
|
|
@@ -523,6 +608,17 @@ declare class AlphaClient {
|
|
|
523
608
|
* @returns Orderbook with yes and no sides, each having bids and asks
|
|
524
609
|
*/
|
|
525
610
|
getOrderbook(marketAppId: number): Promise<Orderbook>;
|
|
611
|
+
/**
|
|
612
|
+
* Fetches the full processed orderbook snapshot for a market from the Alpha REST API.
|
|
613
|
+
*
|
|
614
|
+
* Returns the same shape as websocket `orderbook_changed.orderbook`: a record keyed by
|
|
615
|
+
* `marketAppId`, where each value includes aggregated bids/asks plus detailed yes/no orders.
|
|
616
|
+
* Requires `apiKey`.
|
|
617
|
+
*
|
|
618
|
+
* @param marketId - The Alpha market UUID
|
|
619
|
+
* @returns Full processed market orderbook keyed by marketAppId
|
|
620
|
+
*/
|
|
621
|
+
getFullOrderbookFromApi(marketId: string): Promise<FullOrderbookSnapshot>;
|
|
526
622
|
/**
|
|
527
623
|
* Gets open orders for a specific wallet on a market.
|
|
528
624
|
*
|
|
@@ -597,6 +693,96 @@ declare class AlphaClient {
|
|
|
597
693
|
getMarketFromApi(marketId: string): Promise<Market | null>;
|
|
598
694
|
}
|
|
599
695
|
|
|
696
|
+
/**
|
|
697
|
+
* Real-time WebSocket client for Alpha Market platform streams.
|
|
698
|
+
*
|
|
699
|
+
* Connects to `wss://wss.platform.alphaarcade.com` and provides typed,
|
|
700
|
+
* callback-based subscriptions for live market data. No auth required.
|
|
701
|
+
*
|
|
702
|
+
* @example
|
|
703
|
+
* ```typescript
|
|
704
|
+
* // Node.js 22+ or browser (native WebSocket)
|
|
705
|
+
* const ws = new AlphaWebSocket();
|
|
706
|
+
*
|
|
707
|
+
* // Node.js < 22 — pass the `ws` package
|
|
708
|
+
* import WebSocket from 'ws';
|
|
709
|
+
* const ws = new AlphaWebSocket({ WebSocket });
|
|
710
|
+
*
|
|
711
|
+
* const unsub = ws.subscribeOrderbook('will-btc-hit-100k', (event) => {
|
|
712
|
+
* console.log('Orderbook:', event.orderbook);
|
|
713
|
+
* });
|
|
714
|
+
*
|
|
715
|
+
* // Later
|
|
716
|
+
* unsub();
|
|
717
|
+
* ws.close();
|
|
718
|
+
* ```
|
|
719
|
+
*/
|
|
720
|
+
declare class AlphaWebSocket {
|
|
721
|
+
private url;
|
|
722
|
+
private reconnectEnabled;
|
|
723
|
+
private maxReconnectAttempts;
|
|
724
|
+
private heartbeatIntervalMs;
|
|
725
|
+
private WebSocketImpl;
|
|
726
|
+
private ws;
|
|
727
|
+
private subscriptions;
|
|
728
|
+
private pendingRequests;
|
|
729
|
+
private lastOrderbookVersionBySubscription;
|
|
730
|
+
private heartbeatTimer;
|
|
731
|
+
private reconnectTimer;
|
|
732
|
+
private reconnectAttempts;
|
|
733
|
+
private intentionallyClosed;
|
|
734
|
+
private connectPromise;
|
|
735
|
+
constructor(config?: AlphaWebSocketConfig);
|
|
736
|
+
/** Whether the WebSocket is currently open and connected */
|
|
737
|
+
get connected(): boolean;
|
|
738
|
+
/**
|
|
739
|
+
* Subscribe to live market probability updates (incremental diffs).
|
|
740
|
+
* @returns An unsubscribe function
|
|
741
|
+
*/
|
|
742
|
+
subscribeLiveMarkets(callback: (event: MarketsChangedEvent) => void): () => void;
|
|
743
|
+
/**
|
|
744
|
+
* Subscribe to change events for a single market.
|
|
745
|
+
* @param slug - The market slug
|
|
746
|
+
* @returns An unsubscribe function
|
|
747
|
+
*/
|
|
748
|
+
subscribeMarket(slug: string, callback: (event: MarketChangedEvent) => void): () => void;
|
|
749
|
+
/**
|
|
750
|
+
* Subscribe to full orderbook snapshots (~5s interval on changes).
|
|
751
|
+
* @param slug - The market slug
|
|
752
|
+
* @returns An unsubscribe function
|
|
753
|
+
*/
|
|
754
|
+
subscribeOrderbook(slug: string, callback: (event: OrderbookChangedEvent) => void): () => void;
|
|
755
|
+
/**
|
|
756
|
+
* Subscribe to wallet order updates.
|
|
757
|
+
* @param wallet - The wallet address
|
|
758
|
+
* @returns An unsubscribe function
|
|
759
|
+
*/
|
|
760
|
+
subscribeWalletOrders(wallet: string, callback: (event: WalletOrdersChangedEvent) => void): () => void;
|
|
761
|
+
/** Query the server for the list of active subscriptions on this connection */
|
|
762
|
+
listSubscriptions(): Promise<unknown>;
|
|
763
|
+
/** Query a server property (e.g. "heartbeat", "limits") */
|
|
764
|
+
getProperty(property: string): Promise<unknown>;
|
|
765
|
+
/** Open the WebSocket connection. Called automatically on first subscribe. */
|
|
766
|
+
connect(): Promise<void>;
|
|
767
|
+
/** Close the connection and clean up all resources */
|
|
768
|
+
close(): void;
|
|
769
|
+
private buildStreamKey;
|
|
770
|
+
private buildQueryString;
|
|
771
|
+
private subscribe;
|
|
772
|
+
private doConnect;
|
|
773
|
+
private handleMessage;
|
|
774
|
+
private matchesSubscriptionMessage;
|
|
775
|
+
private shouldDispatchSubscriptionMessage;
|
|
776
|
+
private sendSubscribe;
|
|
777
|
+
private sendUnsubscribe;
|
|
778
|
+
private sendRequest;
|
|
779
|
+
private send;
|
|
780
|
+
private startHeartbeat;
|
|
781
|
+
private stopHeartbeat;
|
|
782
|
+
private scheduleReconnect;
|
|
783
|
+
private clearTimers;
|
|
784
|
+
}
|
|
785
|
+
|
|
600
786
|
/**
|
|
601
787
|
* Fetches all live, tradeable markets directly from the Algorand blockchain.
|
|
602
788
|
*
|
|
@@ -639,6 +825,7 @@ declare const getLiveMarketsFromApi: (config: AlphaClientConfig) => Promise<Mark
|
|
|
639
825
|
declare const getMarketFromApi: (config: AlphaClientConfig, marketId: string) => Promise<Market | null>;
|
|
640
826
|
|
|
641
827
|
declare const DEFAULT_API_BASE_URL = "https://platform.alphaarcade.com/api";
|
|
828
|
+
declare const DEFAULT_WSS_BASE_URL = "wss://wss.platform.alphaarcade.com";
|
|
642
829
|
declare const DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
|
|
643
830
|
|
|
644
831
|
/**
|
|
@@ -720,4 +907,4 @@ declare const getEscrowGlobalState: (indexerClient: algosdk.Indexer, escrowAppId
|
|
|
720
907
|
*/
|
|
721
908
|
declare const checkAssetOptIn: (algodClient: algosdk.Algodv2, address: string, assetId: number) => Promise<boolean>;
|
|
722
909
|
|
|
723
|
-
export { type AggregatedOrderbook, type AggregatedOrderbookEntry, type AggregatedOrderbookSide, AlphaClient, type AlphaClientConfig, type AmendOrderParams, type AmendOrderResult, type CancelOrderParams, type CancelOrderResult, type ClaimParams, type ClaimResult, type CounterpartyMatch, type CreateLimitOrderParams, type CreateMarketOrderParams, type CreateOrderResult, DEFAULT_API_BASE_URL, DEFAULT_MARKET_CREATOR_ADDRESS, type EscrowGlobalState, type Market, type MarketGlobalState, type MarketOption, type MergeSharesParams, type OpenOrder, type OrderSide, type Orderbook, type OrderbookEntry, type OrderbookSide, type Position, type ProcessMatchParams, type ProcessMatchResult, type ProposeMatchParams, type ProposeMatchResult, type SplitMergeResult, type SplitSharesParams, type WalletPosition, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getLiveMarketsFromApi, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsOnChain };
|
|
910
|
+
export { type AggregatedOrderbook, type AggregatedOrderbookEntry, type AggregatedOrderbookSide, AlphaClient, type AlphaClientConfig, AlphaWebSocket, type AlphaWebSocketConfig, type AmendOrderParams, type AmendOrderResult, type CancelOrderParams, type CancelOrderResult, type ClaimParams, type ClaimResult, type CounterpartyMatch, type CreateLimitOrderParams, type CreateMarketOrderParams, type CreateOrderResult, DEFAULT_API_BASE_URL, DEFAULT_MARKET_CREATOR_ADDRESS, DEFAULT_WSS_BASE_URL, type EscrowGlobalState, type FullOrderbookSnapshot, type Market, type MarketChangedEvent, type MarketGlobalState, type MarketOption, type MarketsChangedEvent, type MergeSharesParams, type OpenOrder, type OrderSide, type Orderbook, type OrderbookChangedEvent, type OrderbookEntry, type OrderbookSide, type Position, type ProcessMatchParams, type ProcessMatchResult, type ProposeMatchParams, type ProposeMatchResult, type SplitMergeResult, type SplitSharesParams, type WalletOrdersChangedEvent, type WalletPosition, type WebSocketStreamEvent, type WsOrderbookAggregatedEntry, type WsOrderbookApp, type WsOrderbookDetailEntry, type WsOrderbookDetailSide, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getLiveMarketsFromApi, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsOnChain };
|
package/dist/index.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ type Market = {
|
|
|
49
49
|
feeBase?: number;
|
|
50
50
|
/** Liquidty Rewards Info */
|
|
51
51
|
totalRewards?: number;
|
|
52
|
+
totalPregameRewards?: number;
|
|
52
53
|
rewardsPaidOut?: number;
|
|
53
54
|
rewardsSpreadDistance?: number;
|
|
54
55
|
rewardsMinContracts?: number;
|
|
@@ -67,6 +68,13 @@ type MarketOption = {
|
|
|
67
68
|
noAssetId: number;
|
|
68
69
|
yesProb: number;
|
|
69
70
|
noProb: number;
|
|
71
|
+
totalRewards?: number;
|
|
72
|
+
totalPregameRewards?: number;
|
|
73
|
+
rewardsPaidOut?: number;
|
|
74
|
+
rewardsSpreadDistance?: number;
|
|
75
|
+
rewardsMinContracts?: number;
|
|
76
|
+
lastRewardAmount?: number;
|
|
77
|
+
lastRewardTs?: number;
|
|
70
78
|
[key: string]: unknown;
|
|
71
79
|
};
|
|
72
80
|
/** Global state of a market app read from on-chain */
|
|
@@ -276,6 +284,11 @@ type AggregatedOrderbook = {
|
|
|
276
284
|
yes: AggregatedOrderbookSide;
|
|
277
285
|
no: AggregatedOrderbookSide;
|
|
278
286
|
};
|
|
287
|
+
/**
|
|
288
|
+
* Full processed market orderbook keyed by marketAppId.
|
|
289
|
+
* Matches the REST `/get-full-orderbook` response and `orderbook_changed.orderbook`.
|
|
290
|
+
*/
|
|
291
|
+
type FullOrderbookSnapshot = Record<string, WsOrderbookApp>;
|
|
279
292
|
/** Parameters for split shares */
|
|
280
293
|
type SplitSharesParams = {
|
|
281
294
|
/** Market app ID */
|
|
@@ -362,6 +375,78 @@ type EscrowGlobalState = {
|
|
|
362
375
|
asset_listed?: number;
|
|
363
376
|
fee_timer_start?: number;
|
|
364
377
|
};
|
|
378
|
+
/** Configuration for AlphaWebSocket */
|
|
379
|
+
type AlphaWebSocketConfig = {
|
|
380
|
+
/** WebSocket URL override (default: wss://wss.platform.alphaarcade.com) */
|
|
381
|
+
url?: string;
|
|
382
|
+
/** Enable auto-reconnect on unexpected disconnect (default: true) */
|
|
383
|
+
reconnect?: boolean;
|
|
384
|
+
/** Maximum reconnect attempts before giving up (default: Infinity) */
|
|
385
|
+
maxReconnectAttempts?: number;
|
|
386
|
+
/** Heartbeat interval in ms (default: 60000) */
|
|
387
|
+
heartbeatIntervalMs?: number;
|
|
388
|
+
/**
|
|
389
|
+
* WebSocket constructor to use. Defaults to the global `WebSocket`.
|
|
390
|
+
* On Node.js < 22, pass the `ws` package: `import WebSocket from 'ws'; new AlphaWebSocket({ WebSocket })`
|
|
391
|
+
*/
|
|
392
|
+
WebSocket?: unknown;
|
|
393
|
+
};
|
|
394
|
+
/** Orderbook bid/ask entry at the top level (decimal cents) */
|
|
395
|
+
type WsOrderbookAggregatedEntry = {
|
|
396
|
+
price: number;
|
|
397
|
+
quantity: number;
|
|
398
|
+
total: number;
|
|
399
|
+
};
|
|
400
|
+
/** Orderbook bid/ask entry with escrow details (raw microunit prices) */
|
|
401
|
+
type WsOrderbookDetailEntry = {
|
|
402
|
+
price: number;
|
|
403
|
+
quantity: number;
|
|
404
|
+
total: number;
|
|
405
|
+
escrowAppId: number;
|
|
406
|
+
owner: string;
|
|
407
|
+
};
|
|
408
|
+
/** Per-side orderbook detail (yes or no) */
|
|
409
|
+
type WsOrderbookDetailSide = {
|
|
410
|
+
bids: WsOrderbookDetailEntry[];
|
|
411
|
+
asks: WsOrderbookDetailEntry[];
|
|
412
|
+
};
|
|
413
|
+
/** Orderbook data for a single app within the orderbook payload */
|
|
414
|
+
type WsOrderbookApp = {
|
|
415
|
+
bids: WsOrderbookAggregatedEntry[];
|
|
416
|
+
asks: WsOrderbookAggregatedEntry[];
|
|
417
|
+
spread: number;
|
|
418
|
+
yes: WsOrderbookDetailSide;
|
|
419
|
+
no: WsOrderbookDetailSide;
|
|
420
|
+
};
|
|
421
|
+
/** Payload for orderbook_changed events */
|
|
422
|
+
type OrderbookChangedEvent = {
|
|
423
|
+
type: 'orderbook_changed';
|
|
424
|
+
ts: number;
|
|
425
|
+
marketId: string;
|
|
426
|
+
slug?: string;
|
|
427
|
+
version: number;
|
|
428
|
+
orderbook: FullOrderbookSnapshot;
|
|
429
|
+
};
|
|
430
|
+
/** Payload for markets_changed events (incremental diffs) */
|
|
431
|
+
type MarketsChangedEvent = {
|
|
432
|
+
type: 'markets_changed';
|
|
433
|
+
ts: number;
|
|
434
|
+
[key: string]: unknown;
|
|
435
|
+
};
|
|
436
|
+
/** Payload for market_changed events (single market) */
|
|
437
|
+
type MarketChangedEvent = {
|
|
438
|
+
type: 'market_changed';
|
|
439
|
+
ts: number;
|
|
440
|
+
[key: string]: unknown;
|
|
441
|
+
};
|
|
442
|
+
/** Payload for wallet_orders_changed events */
|
|
443
|
+
type WalletOrdersChangedEvent = {
|
|
444
|
+
type: 'wallet_orders_changed';
|
|
445
|
+
ts: number;
|
|
446
|
+
[key: string]: unknown;
|
|
447
|
+
};
|
|
448
|
+
/** Discriminated union of all WebSocket stream events */
|
|
449
|
+
type WebSocketStreamEvent = MarketsChangedEvent | MarketChangedEvent | OrderbookChangedEvent | WalletOrdersChangedEvent;
|
|
365
450
|
|
|
366
451
|
/**
|
|
367
452
|
* The main client for interacting with Alpha Market prediction markets on Algorand.
|
|
@@ -369,7 +454,7 @@ type EscrowGlobalState = {
|
|
|
369
454
|
* Provides methods for:
|
|
370
455
|
* - **Trading**: Create limit/market orders, cancel orders, propose matches
|
|
371
456
|
* - **Positions**: Split/merge shares, claim resolved tokens, view positions
|
|
372
|
-
* - **Orderbook**: Read on-chain
|
|
457
|
+
* - **Orderbook**: Read on-chain orderbooks or fetch full API-backed market snapshots
|
|
373
458
|
* - **Markets**: Fetch live markets from the Alpha API
|
|
374
459
|
*
|
|
375
460
|
* @example
|
|
@@ -523,6 +608,17 @@ declare class AlphaClient {
|
|
|
523
608
|
* @returns Orderbook with yes and no sides, each having bids and asks
|
|
524
609
|
*/
|
|
525
610
|
getOrderbook(marketAppId: number): Promise<Orderbook>;
|
|
611
|
+
/**
|
|
612
|
+
* Fetches the full processed orderbook snapshot for a market from the Alpha REST API.
|
|
613
|
+
*
|
|
614
|
+
* Returns the same shape as websocket `orderbook_changed.orderbook`: a record keyed by
|
|
615
|
+
* `marketAppId`, where each value includes aggregated bids/asks plus detailed yes/no orders.
|
|
616
|
+
* Requires `apiKey`.
|
|
617
|
+
*
|
|
618
|
+
* @param marketId - The Alpha market UUID
|
|
619
|
+
* @returns Full processed market orderbook keyed by marketAppId
|
|
620
|
+
*/
|
|
621
|
+
getFullOrderbookFromApi(marketId: string): Promise<FullOrderbookSnapshot>;
|
|
526
622
|
/**
|
|
527
623
|
* Gets open orders for a specific wallet on a market.
|
|
528
624
|
*
|
|
@@ -597,6 +693,96 @@ declare class AlphaClient {
|
|
|
597
693
|
getMarketFromApi(marketId: string): Promise<Market | null>;
|
|
598
694
|
}
|
|
599
695
|
|
|
696
|
+
/**
|
|
697
|
+
* Real-time WebSocket client for Alpha Market platform streams.
|
|
698
|
+
*
|
|
699
|
+
* Connects to `wss://wss.platform.alphaarcade.com` and provides typed,
|
|
700
|
+
* callback-based subscriptions for live market data. No auth required.
|
|
701
|
+
*
|
|
702
|
+
* @example
|
|
703
|
+
* ```typescript
|
|
704
|
+
* // Node.js 22+ or browser (native WebSocket)
|
|
705
|
+
* const ws = new AlphaWebSocket();
|
|
706
|
+
*
|
|
707
|
+
* // Node.js < 22 — pass the `ws` package
|
|
708
|
+
* import WebSocket from 'ws';
|
|
709
|
+
* const ws = new AlphaWebSocket({ WebSocket });
|
|
710
|
+
*
|
|
711
|
+
* const unsub = ws.subscribeOrderbook('will-btc-hit-100k', (event) => {
|
|
712
|
+
* console.log('Orderbook:', event.orderbook);
|
|
713
|
+
* });
|
|
714
|
+
*
|
|
715
|
+
* // Later
|
|
716
|
+
* unsub();
|
|
717
|
+
* ws.close();
|
|
718
|
+
* ```
|
|
719
|
+
*/
|
|
720
|
+
declare class AlphaWebSocket {
|
|
721
|
+
private url;
|
|
722
|
+
private reconnectEnabled;
|
|
723
|
+
private maxReconnectAttempts;
|
|
724
|
+
private heartbeatIntervalMs;
|
|
725
|
+
private WebSocketImpl;
|
|
726
|
+
private ws;
|
|
727
|
+
private subscriptions;
|
|
728
|
+
private pendingRequests;
|
|
729
|
+
private lastOrderbookVersionBySubscription;
|
|
730
|
+
private heartbeatTimer;
|
|
731
|
+
private reconnectTimer;
|
|
732
|
+
private reconnectAttempts;
|
|
733
|
+
private intentionallyClosed;
|
|
734
|
+
private connectPromise;
|
|
735
|
+
constructor(config?: AlphaWebSocketConfig);
|
|
736
|
+
/** Whether the WebSocket is currently open and connected */
|
|
737
|
+
get connected(): boolean;
|
|
738
|
+
/**
|
|
739
|
+
* Subscribe to live market probability updates (incremental diffs).
|
|
740
|
+
* @returns An unsubscribe function
|
|
741
|
+
*/
|
|
742
|
+
subscribeLiveMarkets(callback: (event: MarketsChangedEvent) => void): () => void;
|
|
743
|
+
/**
|
|
744
|
+
* Subscribe to change events for a single market.
|
|
745
|
+
* @param slug - The market slug
|
|
746
|
+
* @returns An unsubscribe function
|
|
747
|
+
*/
|
|
748
|
+
subscribeMarket(slug: string, callback: (event: MarketChangedEvent) => void): () => void;
|
|
749
|
+
/**
|
|
750
|
+
* Subscribe to full orderbook snapshots (~5s interval on changes).
|
|
751
|
+
* @param slug - The market slug
|
|
752
|
+
* @returns An unsubscribe function
|
|
753
|
+
*/
|
|
754
|
+
subscribeOrderbook(slug: string, callback: (event: OrderbookChangedEvent) => void): () => void;
|
|
755
|
+
/**
|
|
756
|
+
* Subscribe to wallet order updates.
|
|
757
|
+
* @param wallet - The wallet address
|
|
758
|
+
* @returns An unsubscribe function
|
|
759
|
+
*/
|
|
760
|
+
subscribeWalletOrders(wallet: string, callback: (event: WalletOrdersChangedEvent) => void): () => void;
|
|
761
|
+
/** Query the server for the list of active subscriptions on this connection */
|
|
762
|
+
listSubscriptions(): Promise<unknown>;
|
|
763
|
+
/** Query a server property (e.g. "heartbeat", "limits") */
|
|
764
|
+
getProperty(property: string): Promise<unknown>;
|
|
765
|
+
/** Open the WebSocket connection. Called automatically on first subscribe. */
|
|
766
|
+
connect(): Promise<void>;
|
|
767
|
+
/** Close the connection and clean up all resources */
|
|
768
|
+
close(): void;
|
|
769
|
+
private buildStreamKey;
|
|
770
|
+
private buildQueryString;
|
|
771
|
+
private subscribe;
|
|
772
|
+
private doConnect;
|
|
773
|
+
private handleMessage;
|
|
774
|
+
private matchesSubscriptionMessage;
|
|
775
|
+
private shouldDispatchSubscriptionMessage;
|
|
776
|
+
private sendSubscribe;
|
|
777
|
+
private sendUnsubscribe;
|
|
778
|
+
private sendRequest;
|
|
779
|
+
private send;
|
|
780
|
+
private startHeartbeat;
|
|
781
|
+
private stopHeartbeat;
|
|
782
|
+
private scheduleReconnect;
|
|
783
|
+
private clearTimers;
|
|
784
|
+
}
|
|
785
|
+
|
|
600
786
|
/**
|
|
601
787
|
* Fetches all live, tradeable markets directly from the Algorand blockchain.
|
|
602
788
|
*
|
|
@@ -639,6 +825,7 @@ declare const getLiveMarketsFromApi: (config: AlphaClientConfig) => Promise<Mark
|
|
|
639
825
|
declare const getMarketFromApi: (config: AlphaClientConfig, marketId: string) => Promise<Market | null>;
|
|
640
826
|
|
|
641
827
|
declare const DEFAULT_API_BASE_URL = "https://platform.alphaarcade.com/api";
|
|
828
|
+
declare const DEFAULT_WSS_BASE_URL = "wss://wss.platform.alphaarcade.com";
|
|
642
829
|
declare const DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
|
|
643
830
|
|
|
644
831
|
/**
|
|
@@ -720,4 +907,4 @@ declare const getEscrowGlobalState: (indexerClient: algosdk.Indexer, escrowAppId
|
|
|
720
907
|
*/
|
|
721
908
|
declare const checkAssetOptIn: (algodClient: algosdk.Algodv2, address: string, assetId: number) => Promise<boolean>;
|
|
722
909
|
|
|
723
|
-
export { type AggregatedOrderbook, type AggregatedOrderbookEntry, type AggregatedOrderbookSide, AlphaClient, type AlphaClientConfig, type AmendOrderParams, type AmendOrderResult, type CancelOrderParams, type CancelOrderResult, type ClaimParams, type ClaimResult, type CounterpartyMatch, type CreateLimitOrderParams, type CreateMarketOrderParams, type CreateOrderResult, DEFAULT_API_BASE_URL, DEFAULT_MARKET_CREATOR_ADDRESS, type EscrowGlobalState, type Market, type MarketGlobalState, type MarketOption, type MergeSharesParams, type OpenOrder, type OrderSide, type Orderbook, type OrderbookEntry, type OrderbookSide, type Position, type ProcessMatchParams, type ProcessMatchResult, type ProposeMatchParams, type ProposeMatchResult, type SplitMergeResult, type SplitSharesParams, type WalletPosition, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getLiveMarketsFromApi, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsOnChain };
|
|
910
|
+
export { type AggregatedOrderbook, type AggregatedOrderbookEntry, type AggregatedOrderbookSide, AlphaClient, type AlphaClientConfig, AlphaWebSocket, type AlphaWebSocketConfig, type AmendOrderParams, type AmendOrderResult, type CancelOrderParams, type CancelOrderResult, type ClaimParams, type ClaimResult, type CounterpartyMatch, type CreateLimitOrderParams, type CreateMarketOrderParams, type CreateOrderResult, DEFAULT_API_BASE_URL, DEFAULT_MARKET_CREATOR_ADDRESS, DEFAULT_WSS_BASE_URL, type EscrowGlobalState, type FullOrderbookSnapshot, type Market, type MarketChangedEvent, type MarketGlobalState, type MarketOption, type MarketsChangedEvent, type MergeSharesParams, type OpenOrder, type OrderSide, type Orderbook, type OrderbookChangedEvent, type OrderbookEntry, type OrderbookSide, type Position, type ProcessMatchParams, type ProcessMatchResult, type ProposeMatchParams, type ProposeMatchResult, type SplitMergeResult, type SplitSharesParams, type WalletOrdersChangedEvent, type WalletPosition, type WebSocketStreamEvent, type WsOrderbookAggregatedEntry, type WsOrderbookApp, type WsOrderbookDetailEntry, type WsOrderbookDetailSide, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getLiveMarketsFromApi, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsOnChain };
|