@alpha-arcade/sdk 0.4.1 → 0.4.2
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 +21 -3
- package/dist/index.cjs +25 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -3
- package/dist/index.d.ts +19 -3
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
TypeScript SDK for trading on **Alpha Market** — Algorand prediction markets.
|
|
4
4
|
|
|
5
|
-
Place orders, manage positions, read orderbooks, and build automated trading bots
|
|
5
|
+
Place orders, manage positions, read orderbooks from the API or chain, and build automated trading bots.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -246,7 +246,7 @@ for (const pos of positions) {
|
|
|
246
246
|
|
|
247
247
|
#### `getOrderbook(marketAppId)`
|
|
248
248
|
|
|
249
|
-
Fetches the full on-chain orderbook.
|
|
249
|
+
Fetches the full on-chain orderbook for a single market app.
|
|
250
250
|
|
|
251
251
|
```typescript
|
|
252
252
|
const book = await client.getOrderbook(123456789);
|
|
@@ -263,6 +263,24 @@ if (book.yes.bids.length > 0) {
|
|
|
263
263
|
}
|
|
264
264
|
```
|
|
265
265
|
|
|
266
|
+
#### `getFullOrderbookFromApi(marketId)`
|
|
267
|
+
|
|
268
|
+
Fetches the full processed orderbook snapshot for a market from the Alpha REST API. Requires `apiKey`.
|
|
269
|
+
|
|
270
|
+
This returns the same shape as websocket `orderbook_changed.orderbook`: a record keyed by `marketAppId`, where each value includes:
|
|
271
|
+
- top-level aggregated `bids`, `asks`, and `spread`
|
|
272
|
+
- detailed `yes` and `no` bid/ask orders with `escrowAppId` and `owner`
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
const snapshot = await client.getFullOrderbookFromApi('market-uuid-here');
|
|
276
|
+
|
|
277
|
+
for (const [appId, book] of Object.entries(snapshot)) {
|
|
278
|
+
console.log(`App ${appId}: spread=${book.spread}`);
|
|
279
|
+
console.log('Top-level bids:', book.bids);
|
|
280
|
+
console.log('Detailed YES bids:', book.yes.bids);
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
266
284
|
#### `getOpenOrders(marketAppId, walletAddress?)`
|
|
267
285
|
|
|
268
286
|
Gets open orders for a wallet on a specific market (from on-chain data).
|
|
@@ -407,7 +425,7 @@ ws.subscribeMarket('will-btc-hit-100k', (event) => {
|
|
|
407
425
|
|
|
408
426
|
#### `subscribeOrderbook(slug, callback)`
|
|
409
427
|
|
|
410
|
-
Receive full orderbook snapshots on every change (~5s interval).
|
|
428
|
+
Receive full orderbook snapshots on every change (~5s interval). The payload matches `getFullOrderbookFromApi(marketId)`.
|
|
411
429
|
|
|
412
430
|
**Note:** The WebSocket API uses market **slugs** (URL-friendly names like `"will-btc-hit-100k"`), not `marketAppId` numbers. You can get a market's slug from the `slug` field on `Market` objects returned by `getLiveMarkets()` or `getMarket()`.
|
|
413
431
|
|
package/dist/index.cjs
CHANGED
|
@@ -2266,6 +2266,18 @@ var getWalletOrdersFromApi = async (config, walletAddress) => {
|
|
|
2266
2266
|
}
|
|
2267
2267
|
return allOrders;
|
|
2268
2268
|
};
|
|
2269
|
+
var getFullOrderbookFromApi = async (config, marketId) => {
|
|
2270
|
+
if (!config.apiKey) {
|
|
2271
|
+
throw new Error("apiKey is required for API-based orderbook fetching. Retrieve an API key from the Alpha Arcade platform via the Account page and pass it to the client.");
|
|
2272
|
+
}
|
|
2273
|
+
const baseUrl = config.apiBaseUrl ?? DEFAULT_API_BASE_URL;
|
|
2274
|
+
const url = `${baseUrl}/get-full-orderbook?marketId=${encodeURIComponent(marketId)}`;
|
|
2275
|
+
const response = await fetch(url, { headers: { "x-api-key": config.apiKey } });
|
|
2276
|
+
if (!response.ok) {
|
|
2277
|
+
throw new Error(`Alpha API error: ${response.status} ${response.statusText}`);
|
|
2278
|
+
}
|
|
2279
|
+
return response.json();
|
|
2280
|
+
};
|
|
2269
2281
|
|
|
2270
2282
|
// src/modules/trading.ts
|
|
2271
2283
|
var extractEscrowAppId = async (algodClient, indexerClient, targetTxId) => {
|
|
@@ -3272,6 +3284,19 @@ var AlphaClient = class {
|
|
|
3272
3284
|
async getOrderbook(marketAppId) {
|
|
3273
3285
|
return getOrderbook(this.config, marketAppId);
|
|
3274
3286
|
}
|
|
3287
|
+
/**
|
|
3288
|
+
* Fetches the full processed orderbook snapshot for a market from the Alpha REST API.
|
|
3289
|
+
*
|
|
3290
|
+
* Returns the same shape as websocket `orderbook_changed.orderbook`: a record keyed by
|
|
3291
|
+
* `marketAppId`, where each value includes aggregated bids/asks plus detailed yes/no orders.
|
|
3292
|
+
* Requires `apiKey`.
|
|
3293
|
+
*
|
|
3294
|
+
* @param marketId - The Alpha market UUID
|
|
3295
|
+
* @returns Full processed market orderbook keyed by marketAppId
|
|
3296
|
+
*/
|
|
3297
|
+
async getFullOrderbookFromApi(marketId) {
|
|
3298
|
+
return getFullOrderbookFromApi(this.config, marketId);
|
|
3299
|
+
}
|
|
3275
3300
|
/**
|
|
3276
3301
|
* Gets open orders for a specific wallet on a market.
|
|
3277
3302
|
*
|