@alpha-arcade/sdk 0.2.4 → 0.2.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 +9 -9
- package/dist/index.cjs +24 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -11
- package/dist/index.d.ts +8 -11
- package/dist/index.js +24 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ const client = new AlphaClient({
|
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
// 4. Fetch live markets (reads directly from chain)
|
|
40
|
-
const markets = await client.
|
|
40
|
+
const markets = await client.getLiveMarkets();
|
|
41
41
|
console.log(`Found ${markets.length} live markets`);
|
|
42
42
|
|
|
43
43
|
// 5. Place a limit buy order on the first market
|
|
@@ -71,7 +71,7 @@ new AlphaClient(config: AlphaClientConfig)
|
|
|
71
71
|
| `activeAddress` | `string` | Yes | Your Algorand address |
|
|
72
72
|
| `matcherAppId` | `number` | Yes | Matcher contract app ID (mainnet: `3078581851`) |
|
|
73
73
|
| `usdcAssetId` | `number` | Yes | USDC ASA ID (mainnet: `31566704`) |
|
|
74
|
-
| `apiKey` | `string` | No | Alpha partners API key. If provided, `
|
|
74
|
+
| `apiKey` | `string` | No | Alpha partners API key. If provided, `getLiveMarkets()` uses the API for richer data (images, categories, volume). If omitted, markets are discovered on-chain. |
|
|
75
75
|
| `apiBaseUrl` | `string` | No | API base URL (default: `https://partners.alphaarcade.com/api`) |
|
|
76
76
|
| `marketCreatorAddress` | `string` | No | Market creator address for on-chain discovery (defaults to Alpha Arcade mainnet) |
|
|
77
77
|
|
|
@@ -91,7 +91,7 @@ const result = await client.createLimitOrder({
|
|
|
91
91
|
quantity: 2_000_000, // 2 shares in microunits
|
|
92
92
|
isBuying: true,
|
|
93
93
|
});
|
|
94
|
-
// result: { escrowAppId, txIds, confirmedRound }
|
|
94
|
+
// result: { escrowAppId, txIds, confirmedRound, matchedQuantity?, matchedPrice? }
|
|
95
95
|
```
|
|
96
96
|
|
|
97
97
|
#### `createMarketOrder(params)`
|
|
@@ -107,7 +107,7 @@ const result = await client.createMarketOrder({
|
|
|
107
107
|
isBuying: true,
|
|
108
108
|
slippage: 50_000, // $0.05 slippage tolerance
|
|
109
109
|
});
|
|
110
|
-
// result: { escrowAppId,
|
|
110
|
+
// result: { escrowAppId, txIds, confirmedRound, matchedQuantity, matchedPrice }
|
|
111
111
|
```
|
|
112
112
|
|
|
113
113
|
#### `cancelOrder(params)`
|
|
@@ -228,12 +228,12 @@ for (const order of orders) {
|
|
|
228
228
|
|
|
229
229
|
Markets can be loaded **on-chain** (default, no API key) or via the **REST API** (richer data, requires API key).
|
|
230
230
|
|
|
231
|
-
#### `
|
|
231
|
+
#### `getLiveMarkets()` / `getMarket(marketId)`
|
|
232
232
|
|
|
233
233
|
Smart defaults — uses the API if `apiKey` is set, otherwise reads from chain.
|
|
234
234
|
|
|
235
235
|
```typescript
|
|
236
|
-
const markets = await client.
|
|
236
|
+
const markets = await client.getLiveMarkets();
|
|
237
237
|
for (const m of markets) {
|
|
238
238
|
console.log(`${m.title} — App ID: ${m.marketAppId}, source: ${m.source}`);
|
|
239
239
|
}
|
|
@@ -250,12 +250,12 @@ const markets = await client.getMarketsOnChain();
|
|
|
250
250
|
const market = await client.getMarketOnChain(3012345678);
|
|
251
251
|
```
|
|
252
252
|
|
|
253
|
-
#### `
|
|
253
|
+
#### `getLiveMarketsFromApi()` / `getMarketFromApi(marketId)`
|
|
254
254
|
|
|
255
255
|
Always uses the REST API. Requires `apiKey`. Returns richer data: images, categories, volume, probabilities.
|
|
256
256
|
|
|
257
257
|
```typescript
|
|
258
|
-
const markets = await client.
|
|
258
|
+
const markets = await client.getLiveMarketsFromApi();
|
|
259
259
|
const market = await client.getMarketFromApi('uuid-here');
|
|
260
260
|
```
|
|
261
261
|
|
|
@@ -312,7 +312,7 @@ const setup = () => {
|
|
|
312
312
|
|
|
313
313
|
const run = async () => {
|
|
314
314
|
const client = setup();
|
|
315
|
-
const markets = await client.
|
|
315
|
+
const markets = await client.getLiveMarkets(); // Loads from chain, no API key needed
|
|
316
316
|
|
|
317
317
|
for (const market of markets) {
|
|
318
318
|
const book = await client.getOrderbook(market.marketAppId);
|
package/dist/index.cjs
CHANGED
|
@@ -1544,7 +1544,21 @@ var extractEscrowAppId = async (algodClient, indexerClient, targetTxId) => {
|
|
|
1544
1544
|
return 0;
|
|
1545
1545
|
};
|
|
1546
1546
|
var createLimitOrder = async (config, params) => {
|
|
1547
|
-
|
|
1547
|
+
const orderbook = await getOrderbook(config, params.marketAppId);
|
|
1548
|
+
const matchingOrders = calculateMatchingOrders(
|
|
1549
|
+
orderbook,
|
|
1550
|
+
params.isBuying,
|
|
1551
|
+
params.position === 1,
|
|
1552
|
+
params.quantity,
|
|
1553
|
+
params.price,
|
|
1554
|
+
0
|
|
1555
|
+
);
|
|
1556
|
+
const totalMatchedQuantity = matchingOrders.reduce((sum, o) => sum + o.quantity, 0);
|
|
1557
|
+
const matchedPrice = totalMatchedQuantity > 0 ? Math.round(
|
|
1558
|
+
matchingOrders.reduce((sum, o) => sum + (o.price ?? params.price) * o.quantity, 0) / totalMatchedQuantity
|
|
1559
|
+
) : params.price;
|
|
1560
|
+
const result = await createOrder(config, { ...params, slippage: 0, matchingOrders });
|
|
1561
|
+
return { ...result, matchedQuantity: totalMatchedQuantity, matchedPrice };
|
|
1548
1562
|
};
|
|
1549
1563
|
var createMarketOrder = async (config, params) => {
|
|
1550
1564
|
let matchingOrders = params.matchingOrders;
|
|
@@ -2080,7 +2094,7 @@ var getMarketOnChain = async (config, marketAppId) => {
|
|
|
2080
2094
|
return null;
|
|
2081
2095
|
}
|
|
2082
2096
|
};
|
|
2083
|
-
var
|
|
2097
|
+
var getLiveMarketsFromApi = async (config) => {
|
|
2084
2098
|
if (!config.apiKey) {
|
|
2085
2099
|
throw new Error("apiKey is required for API-based market fetching. Use getMarketsOnChain() instead, or pass an apiKey.");
|
|
2086
2100
|
}
|
|
@@ -2093,7 +2107,7 @@ var getMarketsFromApi = async (config) => {
|
|
|
2093
2107
|
if (lastEvaluatedKey) {
|
|
2094
2108
|
params.set("lastEvaluatedKey", lastEvaluatedKey);
|
|
2095
2109
|
}
|
|
2096
|
-
const url = `${baseUrl}/get-live-markets?${params.toString()}`;
|
|
2110
|
+
const url = `${baseUrl}/get-live-markets-cached?${params.toString()}`;
|
|
2097
2111
|
const response = await fetch(url, { headers: { "x-api-key": config.apiKey } });
|
|
2098
2112
|
if (!response.ok) {
|
|
2099
2113
|
throw new Error(`Alpha API error: ${response.status} ${response.statusText}`);
|
|
@@ -2136,9 +2150,9 @@ var getMarketFromApi = async (config, marketId) => {
|
|
|
2136
2150
|
}
|
|
2137
2151
|
return market;
|
|
2138
2152
|
};
|
|
2139
|
-
var
|
|
2153
|
+
var getLiveMarkets = async (config) => {
|
|
2140
2154
|
if (config.apiKey) {
|
|
2141
|
-
return
|
|
2155
|
+
return getLiveMarketsFromApi(config);
|
|
2142
2156
|
}
|
|
2143
2157
|
return getMarketsOnChain(config);
|
|
2144
2158
|
};
|
|
@@ -2304,8 +2318,8 @@ var AlphaClient = class {
|
|
|
2304
2318
|
*
|
|
2305
2319
|
* @returns Array of live markets
|
|
2306
2320
|
*/
|
|
2307
|
-
async
|
|
2308
|
-
return
|
|
2321
|
+
async getLiveMarkets() {
|
|
2322
|
+
return getLiveMarkets(this.config);
|
|
2309
2323
|
}
|
|
2310
2324
|
/**
|
|
2311
2325
|
* Fetches a single market by its ID.
|
|
@@ -2347,8 +2361,8 @@ var AlphaClient = class {
|
|
|
2347
2361
|
*
|
|
2348
2362
|
* @returns Array of live markets from the API
|
|
2349
2363
|
*/
|
|
2350
|
-
async
|
|
2351
|
-
return
|
|
2364
|
+
async getLiveMarketsFromApi() {
|
|
2365
|
+
return getLiveMarketsFromApi(this.config);
|
|
2352
2366
|
}
|
|
2353
2367
|
/**
|
|
2354
2368
|
* Fetches a single market by ID from the Alpha REST API (requires API key).
|
|
@@ -2369,10 +2383,10 @@ exports.calculateMatchingOrders = calculateMatchingOrders;
|
|
|
2369
2383
|
exports.checkAssetOptIn = checkAssetOptIn;
|
|
2370
2384
|
exports.decodeGlobalState = decodeGlobalState;
|
|
2371
2385
|
exports.getEscrowGlobalState = getEscrowGlobalState;
|
|
2386
|
+
exports.getLiveMarketsFromApi = getLiveMarketsFromApi;
|
|
2372
2387
|
exports.getMarketFromApi = getMarketFromApi;
|
|
2373
2388
|
exports.getMarketGlobalState = getMarketGlobalState;
|
|
2374
2389
|
exports.getMarketOnChain = getMarketOnChain;
|
|
2375
|
-
exports.getMarketsFromApi = getMarketsFromApi;
|
|
2376
2390
|
exports.getMarketsOnChain = getMarketsOnChain;
|
|
2377
2391
|
//# sourceMappingURL=index.cjs.map
|
|
2378
2392
|
//# sourceMappingURL=index.cjs.map
|