@alpha-arcade/sdk 0.2.3 → 0.2.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 +7 -7
- package/dist/index.cjs +21 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +21 -12
- 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
|
|
|
@@ -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
|
@@ -1969,6 +1969,7 @@ var getPositions = async (config, walletAddress) => {
|
|
|
1969
1969
|
// src/modules/markets.ts
|
|
1970
1970
|
var DEFAULT_API_BASE_URL = "https://partners.alphaarcade.com/api";
|
|
1971
1971
|
var DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
|
|
1972
|
+
var toSeconds = (ts) => ts > 1e10 ? Math.floor(ts / 1e3) : ts;
|
|
1972
1973
|
var groupMultiChoiceMarkets = (flatMarkets) => {
|
|
1973
1974
|
const parentMap = /* @__PURE__ */ new Map();
|
|
1974
1975
|
const result = [];
|
|
@@ -2079,7 +2080,7 @@ var getMarketOnChain = async (config, marketAppId) => {
|
|
|
2079
2080
|
return null;
|
|
2080
2081
|
}
|
|
2081
2082
|
};
|
|
2082
|
-
var
|
|
2083
|
+
var getLiveMarketsFromApi = async (config) => {
|
|
2083
2084
|
if (!config.apiKey) {
|
|
2084
2085
|
throw new Error("apiKey is required for API-based market fetching. Use getMarketsOnChain() instead, or pass an apiKey.");
|
|
2085
2086
|
}
|
|
@@ -2092,17 +2093,22 @@ var getMarketsFromApi = async (config) => {
|
|
|
2092
2093
|
if (lastEvaluatedKey) {
|
|
2093
2094
|
params.set("lastEvaluatedKey", lastEvaluatedKey);
|
|
2094
2095
|
}
|
|
2095
|
-
const url = `${baseUrl}/get-live-markets?${params.toString()}`;
|
|
2096
|
+
const url = `${baseUrl}/get-live-markets-cached?${params.toString()}`;
|
|
2096
2097
|
const response = await fetch(url, { headers: { "x-api-key": config.apiKey } });
|
|
2097
2098
|
if (!response.ok) {
|
|
2098
2099
|
throw new Error(`Alpha API error: ${response.status} ${response.statusText}`);
|
|
2099
2100
|
}
|
|
2100
2101
|
const data = await response.json();
|
|
2102
|
+
const normalizeApiMarket = (m) => ({
|
|
2103
|
+
...m,
|
|
2104
|
+
endTs: m.endTs ? toSeconds(m.endTs) : 0,
|
|
2105
|
+
source: "api"
|
|
2106
|
+
});
|
|
2101
2107
|
if (Array.isArray(data)) {
|
|
2102
|
-
allMarkets.push(...data.map(
|
|
2108
|
+
allMarkets.push(...data.map(normalizeApiMarket));
|
|
2103
2109
|
hasMore = false;
|
|
2104
2110
|
} else if (data.markets) {
|
|
2105
|
-
allMarkets.push(...data.markets.map(
|
|
2111
|
+
allMarkets.push(...data.markets.map(normalizeApiMarket));
|
|
2106
2112
|
lastEvaluatedKey = data.lastEvaluatedKey;
|
|
2107
2113
|
hasMore = !!lastEvaluatedKey;
|
|
2108
2114
|
} else {
|
|
@@ -2124,12 +2130,15 @@ var getMarketFromApi = async (config, marketId) => {
|
|
|
2124
2130
|
}
|
|
2125
2131
|
const data = await response.json();
|
|
2126
2132
|
const market = data.market ?? data ?? null;
|
|
2127
|
-
if (market)
|
|
2133
|
+
if (market) {
|
|
2134
|
+
market.source = "api";
|
|
2135
|
+
if (market.endTs) market.endTs = toSeconds(market.endTs);
|
|
2136
|
+
}
|
|
2128
2137
|
return market;
|
|
2129
2138
|
};
|
|
2130
|
-
var
|
|
2139
|
+
var getLiveMarkets = async (config) => {
|
|
2131
2140
|
if (config.apiKey) {
|
|
2132
|
-
return
|
|
2141
|
+
return getLiveMarketsFromApi(config);
|
|
2133
2142
|
}
|
|
2134
2143
|
return getMarketsOnChain(config);
|
|
2135
2144
|
};
|
|
@@ -2295,8 +2304,8 @@ var AlphaClient = class {
|
|
|
2295
2304
|
*
|
|
2296
2305
|
* @returns Array of live markets
|
|
2297
2306
|
*/
|
|
2298
|
-
async
|
|
2299
|
-
return
|
|
2307
|
+
async getLiveMarkets() {
|
|
2308
|
+
return getLiveMarkets(this.config);
|
|
2300
2309
|
}
|
|
2301
2310
|
/**
|
|
2302
2311
|
* Fetches a single market by its ID.
|
|
@@ -2338,8 +2347,8 @@ var AlphaClient = class {
|
|
|
2338
2347
|
*
|
|
2339
2348
|
* @returns Array of live markets from the API
|
|
2340
2349
|
*/
|
|
2341
|
-
async
|
|
2342
|
-
return
|
|
2350
|
+
async getLiveMarketsFromApi() {
|
|
2351
|
+
return getLiveMarketsFromApi(this.config);
|
|
2343
2352
|
}
|
|
2344
2353
|
/**
|
|
2345
2354
|
* Fetches a single market by ID from the Alpha REST API (requires API key).
|
|
@@ -2360,10 +2369,10 @@ exports.calculateMatchingOrders = calculateMatchingOrders;
|
|
|
2360
2369
|
exports.checkAssetOptIn = checkAssetOptIn;
|
|
2361
2370
|
exports.decodeGlobalState = decodeGlobalState;
|
|
2362
2371
|
exports.getEscrowGlobalState = getEscrowGlobalState;
|
|
2372
|
+
exports.getLiveMarketsFromApi = getLiveMarketsFromApi;
|
|
2363
2373
|
exports.getMarketFromApi = getMarketFromApi;
|
|
2364
2374
|
exports.getMarketGlobalState = getMarketGlobalState;
|
|
2365
2375
|
exports.getMarketOnChain = getMarketOnChain;
|
|
2366
|
-
exports.getMarketsFromApi = getMarketsFromApi;
|
|
2367
2376
|
exports.getMarketsOnChain = getMarketsOnChain;
|
|
2368
2377
|
//# sourceMappingURL=index.cjs.map
|
|
2369
2378
|
//# sourceMappingURL=index.cjs.map
|