@alpha-arcade/sdk 0.3.1 → 0.3.5
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 +164 -2
- package/dist/index.cjs +332 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +181 -2
- package/dist/index.d.ts +181 -2
- package/dist/index.js +331 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -276,6 +276,11 @@ type AggregatedOrderbook = {
|
|
|
276
276
|
yes: AggregatedOrderbookSide;
|
|
277
277
|
no: AggregatedOrderbookSide;
|
|
278
278
|
};
|
|
279
|
+
/**
|
|
280
|
+
* Full processed market orderbook keyed by marketAppId.
|
|
281
|
+
* Matches the REST `/get-full-orderbook` response and `orderbook_changed.orderbook`.
|
|
282
|
+
*/
|
|
283
|
+
type FullOrderbookSnapshot = Record<string, WsOrderbookApp>;
|
|
279
284
|
/** Parameters for split shares */
|
|
280
285
|
type SplitSharesParams = {
|
|
281
286
|
/** Market app ID */
|
|
@@ -362,6 +367,78 @@ type EscrowGlobalState = {
|
|
|
362
367
|
asset_listed?: number;
|
|
363
368
|
fee_timer_start?: number;
|
|
364
369
|
};
|
|
370
|
+
/** Configuration for AlphaWebSocket */
|
|
371
|
+
type AlphaWebSocketConfig = {
|
|
372
|
+
/** WebSocket URL override (default: wss://wss.platform.alphaarcade.com) */
|
|
373
|
+
url?: string;
|
|
374
|
+
/** Enable auto-reconnect on unexpected disconnect (default: true) */
|
|
375
|
+
reconnect?: boolean;
|
|
376
|
+
/** Maximum reconnect attempts before giving up (default: Infinity) */
|
|
377
|
+
maxReconnectAttempts?: number;
|
|
378
|
+
/** Heartbeat interval in ms (default: 60000) */
|
|
379
|
+
heartbeatIntervalMs?: number;
|
|
380
|
+
/**
|
|
381
|
+
* WebSocket constructor to use. Defaults to the global `WebSocket`.
|
|
382
|
+
* On Node.js < 22, pass the `ws` package: `import WebSocket from 'ws'; new AlphaWebSocket({ WebSocket })`
|
|
383
|
+
*/
|
|
384
|
+
WebSocket?: unknown;
|
|
385
|
+
};
|
|
386
|
+
/** Orderbook bid/ask entry at the top level (decimal cents) */
|
|
387
|
+
type WsOrderbookAggregatedEntry = {
|
|
388
|
+
price: number;
|
|
389
|
+
quantity: number;
|
|
390
|
+
total: number;
|
|
391
|
+
};
|
|
392
|
+
/** Orderbook bid/ask entry with escrow details (raw microunit prices) */
|
|
393
|
+
type WsOrderbookDetailEntry = {
|
|
394
|
+
price: number;
|
|
395
|
+
quantity: number;
|
|
396
|
+
total: number;
|
|
397
|
+
escrowAppId: number;
|
|
398
|
+
owner: string;
|
|
399
|
+
};
|
|
400
|
+
/** Per-side orderbook detail (yes or no) */
|
|
401
|
+
type WsOrderbookDetailSide = {
|
|
402
|
+
bids: WsOrderbookDetailEntry[];
|
|
403
|
+
asks: WsOrderbookDetailEntry[];
|
|
404
|
+
};
|
|
405
|
+
/** Orderbook data for a single app within the orderbook payload */
|
|
406
|
+
type WsOrderbookApp = {
|
|
407
|
+
bids: WsOrderbookAggregatedEntry[];
|
|
408
|
+
asks: WsOrderbookAggregatedEntry[];
|
|
409
|
+
spread: number;
|
|
410
|
+
yes: WsOrderbookDetailSide;
|
|
411
|
+
no: WsOrderbookDetailSide;
|
|
412
|
+
};
|
|
413
|
+
/** Payload for orderbook_changed events */
|
|
414
|
+
type OrderbookChangedEvent = {
|
|
415
|
+
type: 'orderbook_changed';
|
|
416
|
+
ts: number;
|
|
417
|
+
marketId: string;
|
|
418
|
+
slug?: string;
|
|
419
|
+
version: number;
|
|
420
|
+
orderbook: FullOrderbookSnapshot;
|
|
421
|
+
};
|
|
422
|
+
/** Payload for markets_changed events (incremental diffs) */
|
|
423
|
+
type MarketsChangedEvent = {
|
|
424
|
+
type: 'markets_changed';
|
|
425
|
+
ts: number;
|
|
426
|
+
[key: string]: unknown;
|
|
427
|
+
};
|
|
428
|
+
/** Payload for market_changed events (single market) */
|
|
429
|
+
type MarketChangedEvent = {
|
|
430
|
+
type: 'market_changed';
|
|
431
|
+
ts: number;
|
|
432
|
+
[key: string]: unknown;
|
|
433
|
+
};
|
|
434
|
+
/** Payload for wallet_orders_changed events */
|
|
435
|
+
type WalletOrdersChangedEvent = {
|
|
436
|
+
type: 'wallet_orders_changed';
|
|
437
|
+
ts: number;
|
|
438
|
+
[key: string]: unknown;
|
|
439
|
+
};
|
|
440
|
+
/** Discriminated union of all WebSocket stream events */
|
|
441
|
+
type WebSocketStreamEvent = MarketsChangedEvent | MarketChangedEvent | OrderbookChangedEvent | WalletOrdersChangedEvent;
|
|
365
442
|
|
|
366
443
|
/**
|
|
367
444
|
* The main client for interacting with Alpha Market prediction markets on Algorand.
|
|
@@ -369,7 +446,7 @@ type EscrowGlobalState = {
|
|
|
369
446
|
* Provides methods for:
|
|
370
447
|
* - **Trading**: Create limit/market orders, cancel orders, propose matches
|
|
371
448
|
* - **Positions**: Split/merge shares, claim resolved tokens, view positions
|
|
372
|
-
* - **Orderbook**: Read on-chain
|
|
449
|
+
* - **Orderbook**: Read on-chain orderbooks or fetch full API-backed market snapshots
|
|
373
450
|
* - **Markets**: Fetch live markets from the Alpha API
|
|
374
451
|
*
|
|
375
452
|
* @example
|
|
@@ -523,6 +600,17 @@ declare class AlphaClient {
|
|
|
523
600
|
* @returns Orderbook with yes and no sides, each having bids and asks
|
|
524
601
|
*/
|
|
525
602
|
getOrderbook(marketAppId: number): Promise<Orderbook>;
|
|
603
|
+
/**
|
|
604
|
+
* Fetches the full processed orderbook snapshot for a market from the Alpha REST API.
|
|
605
|
+
*
|
|
606
|
+
* Returns the same shape as websocket `orderbook_changed.orderbook`: a record keyed by
|
|
607
|
+
* `marketAppId`, where each value includes aggregated bids/asks plus detailed yes/no orders.
|
|
608
|
+
* Requires `apiKey`.
|
|
609
|
+
*
|
|
610
|
+
* @param marketId - The Alpha market UUID
|
|
611
|
+
* @returns Full processed market orderbook keyed by marketAppId
|
|
612
|
+
*/
|
|
613
|
+
getFullOrderbookFromApi(marketId: string): Promise<FullOrderbookSnapshot>;
|
|
526
614
|
/**
|
|
527
615
|
* Gets open orders for a specific wallet on a market.
|
|
528
616
|
*
|
|
@@ -597,6 +685,96 @@ declare class AlphaClient {
|
|
|
597
685
|
getMarketFromApi(marketId: string): Promise<Market | null>;
|
|
598
686
|
}
|
|
599
687
|
|
|
688
|
+
/**
|
|
689
|
+
* Real-time WebSocket client for Alpha Market platform streams.
|
|
690
|
+
*
|
|
691
|
+
* Connects to `wss://wss.platform.alphaarcade.com` and provides typed,
|
|
692
|
+
* callback-based subscriptions for live market data. No auth required.
|
|
693
|
+
*
|
|
694
|
+
* @example
|
|
695
|
+
* ```typescript
|
|
696
|
+
* // Node.js 22+ or browser (native WebSocket)
|
|
697
|
+
* const ws = new AlphaWebSocket();
|
|
698
|
+
*
|
|
699
|
+
* // Node.js < 22 — pass the `ws` package
|
|
700
|
+
* import WebSocket from 'ws';
|
|
701
|
+
* const ws = new AlphaWebSocket({ WebSocket });
|
|
702
|
+
*
|
|
703
|
+
* const unsub = ws.subscribeOrderbook('will-btc-hit-100k', (event) => {
|
|
704
|
+
* console.log('Orderbook:', event.orderbook);
|
|
705
|
+
* });
|
|
706
|
+
*
|
|
707
|
+
* // Later
|
|
708
|
+
* unsub();
|
|
709
|
+
* ws.close();
|
|
710
|
+
* ```
|
|
711
|
+
*/
|
|
712
|
+
declare class AlphaWebSocket {
|
|
713
|
+
private url;
|
|
714
|
+
private reconnectEnabled;
|
|
715
|
+
private maxReconnectAttempts;
|
|
716
|
+
private heartbeatIntervalMs;
|
|
717
|
+
private WebSocketImpl;
|
|
718
|
+
private ws;
|
|
719
|
+
private subscriptions;
|
|
720
|
+
private pendingRequests;
|
|
721
|
+
private lastOrderbookVersionBySubscription;
|
|
722
|
+
private heartbeatTimer;
|
|
723
|
+
private reconnectTimer;
|
|
724
|
+
private reconnectAttempts;
|
|
725
|
+
private intentionallyClosed;
|
|
726
|
+
private connectPromise;
|
|
727
|
+
constructor(config?: AlphaWebSocketConfig);
|
|
728
|
+
/** Whether the WebSocket is currently open and connected */
|
|
729
|
+
get connected(): boolean;
|
|
730
|
+
/**
|
|
731
|
+
* Subscribe to live market probability updates (incremental diffs).
|
|
732
|
+
* @returns An unsubscribe function
|
|
733
|
+
*/
|
|
734
|
+
subscribeLiveMarkets(callback: (event: MarketsChangedEvent) => void): () => void;
|
|
735
|
+
/**
|
|
736
|
+
* Subscribe to change events for a single market.
|
|
737
|
+
* @param slug - The market slug
|
|
738
|
+
* @returns An unsubscribe function
|
|
739
|
+
*/
|
|
740
|
+
subscribeMarket(slug: string, callback: (event: MarketChangedEvent) => void): () => void;
|
|
741
|
+
/**
|
|
742
|
+
* Subscribe to full orderbook snapshots (~5s interval on changes).
|
|
743
|
+
* @param slug - The market slug
|
|
744
|
+
* @returns An unsubscribe function
|
|
745
|
+
*/
|
|
746
|
+
subscribeOrderbook(slug: string, callback: (event: OrderbookChangedEvent) => void): () => void;
|
|
747
|
+
/**
|
|
748
|
+
* Subscribe to wallet order updates.
|
|
749
|
+
* @param wallet - The wallet address
|
|
750
|
+
* @returns An unsubscribe function
|
|
751
|
+
*/
|
|
752
|
+
subscribeWalletOrders(wallet: string, callback: (event: WalletOrdersChangedEvent) => void): () => void;
|
|
753
|
+
/** Query the server for the list of active subscriptions on this connection */
|
|
754
|
+
listSubscriptions(): Promise<unknown>;
|
|
755
|
+
/** Query a server property (e.g. "heartbeat", "limits") */
|
|
756
|
+
getProperty(property: string): Promise<unknown>;
|
|
757
|
+
/** Open the WebSocket connection. Called automatically on first subscribe. */
|
|
758
|
+
connect(): Promise<void>;
|
|
759
|
+
/** Close the connection and clean up all resources */
|
|
760
|
+
close(): void;
|
|
761
|
+
private buildStreamKey;
|
|
762
|
+
private buildQueryString;
|
|
763
|
+
private subscribe;
|
|
764
|
+
private doConnect;
|
|
765
|
+
private handleMessage;
|
|
766
|
+
private matchesSubscriptionMessage;
|
|
767
|
+
private shouldDispatchSubscriptionMessage;
|
|
768
|
+
private sendSubscribe;
|
|
769
|
+
private sendUnsubscribe;
|
|
770
|
+
private sendRequest;
|
|
771
|
+
private send;
|
|
772
|
+
private startHeartbeat;
|
|
773
|
+
private stopHeartbeat;
|
|
774
|
+
private scheduleReconnect;
|
|
775
|
+
private clearTimers;
|
|
776
|
+
}
|
|
777
|
+
|
|
600
778
|
/**
|
|
601
779
|
* Fetches all live, tradeable markets directly from the Algorand blockchain.
|
|
602
780
|
*
|
|
@@ -639,6 +817,7 @@ declare const getLiveMarketsFromApi: (config: AlphaClientConfig) => Promise<Mark
|
|
|
639
817
|
declare const getMarketFromApi: (config: AlphaClientConfig, marketId: string) => Promise<Market | null>;
|
|
640
818
|
|
|
641
819
|
declare const DEFAULT_API_BASE_URL = "https://platform.alphaarcade.com/api";
|
|
820
|
+
declare const DEFAULT_WSS_BASE_URL = "wss://wss.platform.alphaarcade.com";
|
|
642
821
|
declare const DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
|
|
643
822
|
|
|
644
823
|
/**
|
|
@@ -720,4 +899,4 @@ declare const getEscrowGlobalState: (indexerClient: algosdk.Indexer, escrowAppId
|
|
|
720
899
|
*/
|
|
721
900
|
declare const checkAssetOptIn: (algodClient: algosdk.Algodv2, address: string, assetId: number) => Promise<boolean>;
|
|
722
901
|
|
|
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 };
|
|
902
|
+
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
|
@@ -276,6 +276,11 @@ type AggregatedOrderbook = {
|
|
|
276
276
|
yes: AggregatedOrderbookSide;
|
|
277
277
|
no: AggregatedOrderbookSide;
|
|
278
278
|
};
|
|
279
|
+
/**
|
|
280
|
+
* Full processed market orderbook keyed by marketAppId.
|
|
281
|
+
* Matches the REST `/get-full-orderbook` response and `orderbook_changed.orderbook`.
|
|
282
|
+
*/
|
|
283
|
+
type FullOrderbookSnapshot = Record<string, WsOrderbookApp>;
|
|
279
284
|
/** Parameters for split shares */
|
|
280
285
|
type SplitSharesParams = {
|
|
281
286
|
/** Market app ID */
|
|
@@ -362,6 +367,78 @@ type EscrowGlobalState = {
|
|
|
362
367
|
asset_listed?: number;
|
|
363
368
|
fee_timer_start?: number;
|
|
364
369
|
};
|
|
370
|
+
/** Configuration for AlphaWebSocket */
|
|
371
|
+
type AlphaWebSocketConfig = {
|
|
372
|
+
/** WebSocket URL override (default: wss://wss.platform.alphaarcade.com) */
|
|
373
|
+
url?: string;
|
|
374
|
+
/** Enable auto-reconnect on unexpected disconnect (default: true) */
|
|
375
|
+
reconnect?: boolean;
|
|
376
|
+
/** Maximum reconnect attempts before giving up (default: Infinity) */
|
|
377
|
+
maxReconnectAttempts?: number;
|
|
378
|
+
/** Heartbeat interval in ms (default: 60000) */
|
|
379
|
+
heartbeatIntervalMs?: number;
|
|
380
|
+
/**
|
|
381
|
+
* WebSocket constructor to use. Defaults to the global `WebSocket`.
|
|
382
|
+
* On Node.js < 22, pass the `ws` package: `import WebSocket from 'ws'; new AlphaWebSocket({ WebSocket })`
|
|
383
|
+
*/
|
|
384
|
+
WebSocket?: unknown;
|
|
385
|
+
};
|
|
386
|
+
/** Orderbook bid/ask entry at the top level (decimal cents) */
|
|
387
|
+
type WsOrderbookAggregatedEntry = {
|
|
388
|
+
price: number;
|
|
389
|
+
quantity: number;
|
|
390
|
+
total: number;
|
|
391
|
+
};
|
|
392
|
+
/** Orderbook bid/ask entry with escrow details (raw microunit prices) */
|
|
393
|
+
type WsOrderbookDetailEntry = {
|
|
394
|
+
price: number;
|
|
395
|
+
quantity: number;
|
|
396
|
+
total: number;
|
|
397
|
+
escrowAppId: number;
|
|
398
|
+
owner: string;
|
|
399
|
+
};
|
|
400
|
+
/** Per-side orderbook detail (yes or no) */
|
|
401
|
+
type WsOrderbookDetailSide = {
|
|
402
|
+
bids: WsOrderbookDetailEntry[];
|
|
403
|
+
asks: WsOrderbookDetailEntry[];
|
|
404
|
+
};
|
|
405
|
+
/** Orderbook data for a single app within the orderbook payload */
|
|
406
|
+
type WsOrderbookApp = {
|
|
407
|
+
bids: WsOrderbookAggregatedEntry[];
|
|
408
|
+
asks: WsOrderbookAggregatedEntry[];
|
|
409
|
+
spread: number;
|
|
410
|
+
yes: WsOrderbookDetailSide;
|
|
411
|
+
no: WsOrderbookDetailSide;
|
|
412
|
+
};
|
|
413
|
+
/** Payload for orderbook_changed events */
|
|
414
|
+
type OrderbookChangedEvent = {
|
|
415
|
+
type: 'orderbook_changed';
|
|
416
|
+
ts: number;
|
|
417
|
+
marketId: string;
|
|
418
|
+
slug?: string;
|
|
419
|
+
version: number;
|
|
420
|
+
orderbook: FullOrderbookSnapshot;
|
|
421
|
+
};
|
|
422
|
+
/** Payload for markets_changed events (incremental diffs) */
|
|
423
|
+
type MarketsChangedEvent = {
|
|
424
|
+
type: 'markets_changed';
|
|
425
|
+
ts: number;
|
|
426
|
+
[key: string]: unknown;
|
|
427
|
+
};
|
|
428
|
+
/** Payload for market_changed events (single market) */
|
|
429
|
+
type MarketChangedEvent = {
|
|
430
|
+
type: 'market_changed';
|
|
431
|
+
ts: number;
|
|
432
|
+
[key: string]: unknown;
|
|
433
|
+
};
|
|
434
|
+
/** Payload for wallet_orders_changed events */
|
|
435
|
+
type WalletOrdersChangedEvent = {
|
|
436
|
+
type: 'wallet_orders_changed';
|
|
437
|
+
ts: number;
|
|
438
|
+
[key: string]: unknown;
|
|
439
|
+
};
|
|
440
|
+
/** Discriminated union of all WebSocket stream events */
|
|
441
|
+
type WebSocketStreamEvent = MarketsChangedEvent | MarketChangedEvent | OrderbookChangedEvent | WalletOrdersChangedEvent;
|
|
365
442
|
|
|
366
443
|
/**
|
|
367
444
|
* The main client for interacting with Alpha Market prediction markets on Algorand.
|
|
@@ -369,7 +446,7 @@ type EscrowGlobalState = {
|
|
|
369
446
|
* Provides methods for:
|
|
370
447
|
* - **Trading**: Create limit/market orders, cancel orders, propose matches
|
|
371
448
|
* - **Positions**: Split/merge shares, claim resolved tokens, view positions
|
|
372
|
-
* - **Orderbook**: Read on-chain
|
|
449
|
+
* - **Orderbook**: Read on-chain orderbooks or fetch full API-backed market snapshots
|
|
373
450
|
* - **Markets**: Fetch live markets from the Alpha API
|
|
374
451
|
*
|
|
375
452
|
* @example
|
|
@@ -523,6 +600,17 @@ declare class AlphaClient {
|
|
|
523
600
|
* @returns Orderbook with yes and no sides, each having bids and asks
|
|
524
601
|
*/
|
|
525
602
|
getOrderbook(marketAppId: number): Promise<Orderbook>;
|
|
603
|
+
/**
|
|
604
|
+
* Fetches the full processed orderbook snapshot for a market from the Alpha REST API.
|
|
605
|
+
*
|
|
606
|
+
* Returns the same shape as websocket `orderbook_changed.orderbook`: a record keyed by
|
|
607
|
+
* `marketAppId`, where each value includes aggregated bids/asks plus detailed yes/no orders.
|
|
608
|
+
* Requires `apiKey`.
|
|
609
|
+
*
|
|
610
|
+
* @param marketId - The Alpha market UUID
|
|
611
|
+
* @returns Full processed market orderbook keyed by marketAppId
|
|
612
|
+
*/
|
|
613
|
+
getFullOrderbookFromApi(marketId: string): Promise<FullOrderbookSnapshot>;
|
|
526
614
|
/**
|
|
527
615
|
* Gets open orders for a specific wallet on a market.
|
|
528
616
|
*
|
|
@@ -597,6 +685,96 @@ declare class AlphaClient {
|
|
|
597
685
|
getMarketFromApi(marketId: string): Promise<Market | null>;
|
|
598
686
|
}
|
|
599
687
|
|
|
688
|
+
/**
|
|
689
|
+
* Real-time WebSocket client for Alpha Market platform streams.
|
|
690
|
+
*
|
|
691
|
+
* Connects to `wss://wss.platform.alphaarcade.com` and provides typed,
|
|
692
|
+
* callback-based subscriptions for live market data. No auth required.
|
|
693
|
+
*
|
|
694
|
+
* @example
|
|
695
|
+
* ```typescript
|
|
696
|
+
* // Node.js 22+ or browser (native WebSocket)
|
|
697
|
+
* const ws = new AlphaWebSocket();
|
|
698
|
+
*
|
|
699
|
+
* // Node.js < 22 — pass the `ws` package
|
|
700
|
+
* import WebSocket from 'ws';
|
|
701
|
+
* const ws = new AlphaWebSocket({ WebSocket });
|
|
702
|
+
*
|
|
703
|
+
* const unsub = ws.subscribeOrderbook('will-btc-hit-100k', (event) => {
|
|
704
|
+
* console.log('Orderbook:', event.orderbook);
|
|
705
|
+
* });
|
|
706
|
+
*
|
|
707
|
+
* // Later
|
|
708
|
+
* unsub();
|
|
709
|
+
* ws.close();
|
|
710
|
+
* ```
|
|
711
|
+
*/
|
|
712
|
+
declare class AlphaWebSocket {
|
|
713
|
+
private url;
|
|
714
|
+
private reconnectEnabled;
|
|
715
|
+
private maxReconnectAttempts;
|
|
716
|
+
private heartbeatIntervalMs;
|
|
717
|
+
private WebSocketImpl;
|
|
718
|
+
private ws;
|
|
719
|
+
private subscriptions;
|
|
720
|
+
private pendingRequests;
|
|
721
|
+
private lastOrderbookVersionBySubscription;
|
|
722
|
+
private heartbeatTimer;
|
|
723
|
+
private reconnectTimer;
|
|
724
|
+
private reconnectAttempts;
|
|
725
|
+
private intentionallyClosed;
|
|
726
|
+
private connectPromise;
|
|
727
|
+
constructor(config?: AlphaWebSocketConfig);
|
|
728
|
+
/** Whether the WebSocket is currently open and connected */
|
|
729
|
+
get connected(): boolean;
|
|
730
|
+
/**
|
|
731
|
+
* Subscribe to live market probability updates (incremental diffs).
|
|
732
|
+
* @returns An unsubscribe function
|
|
733
|
+
*/
|
|
734
|
+
subscribeLiveMarkets(callback: (event: MarketsChangedEvent) => void): () => void;
|
|
735
|
+
/**
|
|
736
|
+
* Subscribe to change events for a single market.
|
|
737
|
+
* @param slug - The market slug
|
|
738
|
+
* @returns An unsubscribe function
|
|
739
|
+
*/
|
|
740
|
+
subscribeMarket(slug: string, callback: (event: MarketChangedEvent) => void): () => void;
|
|
741
|
+
/**
|
|
742
|
+
* Subscribe to full orderbook snapshots (~5s interval on changes).
|
|
743
|
+
* @param slug - The market slug
|
|
744
|
+
* @returns An unsubscribe function
|
|
745
|
+
*/
|
|
746
|
+
subscribeOrderbook(slug: string, callback: (event: OrderbookChangedEvent) => void): () => void;
|
|
747
|
+
/**
|
|
748
|
+
* Subscribe to wallet order updates.
|
|
749
|
+
* @param wallet - The wallet address
|
|
750
|
+
* @returns An unsubscribe function
|
|
751
|
+
*/
|
|
752
|
+
subscribeWalletOrders(wallet: string, callback: (event: WalletOrdersChangedEvent) => void): () => void;
|
|
753
|
+
/** Query the server for the list of active subscriptions on this connection */
|
|
754
|
+
listSubscriptions(): Promise<unknown>;
|
|
755
|
+
/** Query a server property (e.g. "heartbeat", "limits") */
|
|
756
|
+
getProperty(property: string): Promise<unknown>;
|
|
757
|
+
/** Open the WebSocket connection. Called automatically on first subscribe. */
|
|
758
|
+
connect(): Promise<void>;
|
|
759
|
+
/** Close the connection and clean up all resources */
|
|
760
|
+
close(): void;
|
|
761
|
+
private buildStreamKey;
|
|
762
|
+
private buildQueryString;
|
|
763
|
+
private subscribe;
|
|
764
|
+
private doConnect;
|
|
765
|
+
private handleMessage;
|
|
766
|
+
private matchesSubscriptionMessage;
|
|
767
|
+
private shouldDispatchSubscriptionMessage;
|
|
768
|
+
private sendSubscribe;
|
|
769
|
+
private sendUnsubscribe;
|
|
770
|
+
private sendRequest;
|
|
771
|
+
private send;
|
|
772
|
+
private startHeartbeat;
|
|
773
|
+
private stopHeartbeat;
|
|
774
|
+
private scheduleReconnect;
|
|
775
|
+
private clearTimers;
|
|
776
|
+
}
|
|
777
|
+
|
|
600
778
|
/**
|
|
601
779
|
* Fetches all live, tradeable markets directly from the Algorand blockchain.
|
|
602
780
|
*
|
|
@@ -639,6 +817,7 @@ declare const getLiveMarketsFromApi: (config: AlphaClientConfig) => Promise<Mark
|
|
|
639
817
|
declare const getMarketFromApi: (config: AlphaClientConfig, marketId: string) => Promise<Market | null>;
|
|
640
818
|
|
|
641
819
|
declare const DEFAULT_API_BASE_URL = "https://platform.alphaarcade.com/api";
|
|
820
|
+
declare const DEFAULT_WSS_BASE_URL = "wss://wss.platform.alphaarcade.com";
|
|
642
821
|
declare const DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
|
|
643
822
|
|
|
644
823
|
/**
|
|
@@ -720,4 +899,4 @@ declare const getEscrowGlobalState: (indexerClient: algosdk.Indexer, escrowAppId
|
|
|
720
899
|
*/
|
|
721
900
|
declare const checkAssetOptIn: (algodClient: algosdk.Algodv2, address: string, assetId: number) => Promise<boolean>;
|
|
722
901
|
|
|
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 };
|
|
902
|
+
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 };
|