@alpha-arcade/sdk 0.2.7 → 0.2.9

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 CHANGED
@@ -12,6 +12,24 @@ npm install @alpha-arcade/sdk algosdk @algorandfoundation/algokit-utils
12
12
 
13
13
  `algosdk` and `@algorandfoundation/algokit-utils` are peer dependencies.
14
14
 
15
+ ## Getting an API key
16
+
17
+ An API key is **optional**. Without it, you can still fetch markets on-chain, place orders, and use most SDK features. With an API key, you get richer market data, liquidity rewards information, and wallet order lookups, and more.
18
+
19
+ To get an API key:
20
+
21
+ 1. Go to [alphaarcade.com](https://alphaarcade.com) and **sign up** with your email or Google account.
22
+ 2. Open the **Account** page
23
+ 3. Open the **Partners** tab.
24
+ 4. Click **Create API key** and copy the key.
25
+ 5. Add it to your environment (e.g. a `.env` file in the project root):
26
+
27
+ ```bash
28
+ ALPHA_API_KEY=your_api_key_here
29
+ ```
30
+
31
+ Then pass it when creating the client: `apiKey: process.env.ALPHA_API_KEY`.
32
+
15
33
  ## Quick Start
16
34
 
17
35
  ```typescript
@@ -53,6 +71,21 @@ const result = await client.createLimitOrder({
53
71
  console.log(`Order created! Escrow app ID: ${result.escrowAppId}`);
54
72
  ```
55
73
 
74
+ ## Examples
75
+
76
+ The repo includes runnable examples (use `npx tsx examples/<script>.ts`). Scripts that call the API (e.g. `get-orders.ts`, `get-reward-markets.ts`) need `ALPHA_API_KEY` in your `.env` — see [Getting an API key](#getting-an-api-key). Trading examples also need `TEST_MNEMONIC`.
77
+
78
+ | Script | Description |
79
+ |--------|-------------|
80
+ | `get-orders.ts` | Fetch all open orders for a wallet via the API (`getWalletOrdersFromApi`) |
81
+ | `get-reward-markets.ts` | Fetch reward markets and show liquidity reward info (`getRewardMarkets`) |
82
+ | `get-positions.ts` | List token positions across markets (`getPositions`) |
83
+ | `place-limit-order.ts` | Place a limit order |
84
+ | `place-market-order.ts` | Place a market order |
85
+ | `cancel-order.ts` | Cancel an open order |
86
+ | `split-merge.ts` | Split USDC into YES/NO and merge back |
87
+ | `simple-trading-bot.ts` | Example bot that scans markets and places market orders |
88
+
56
89
  ## API Reference
57
90
 
58
91
  ### AlphaClient
@@ -71,8 +104,8 @@ new AlphaClient(config: AlphaClientConfig)
71
104
  | `activeAddress` | `string` | Yes | Your Algorand address |
72
105
  | `matcherAppId` | `number` | Yes | Matcher contract app ID (mainnet: `3078581851`) |
73
106
  | `usdcAssetId` | `number` | Yes | USDC ASA ID (mainnet: `31566704`) |
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
- | `apiBaseUrl` | `string` | No | API base URL (default: `https://partners.alphaarcade.com/api`) |
107
+ | `apiKey` | `string` | No | Alpha API key. If provided, `getLiveMarkets()` and related API methods use the platform for richer data (images, categories, volume, reward markets, wallet orders). If omitted, markets are discovered on-chain. |
108
+ | `apiBaseUrl` | `string` | No | API base URL (default: `https://platform.alphaarcade.com/api`) |
76
109
  | `marketCreatorAddress` | `string` | No | Market creator address for on-chain discovery (defaults to Alpha Arcade mainnet) |
77
110
 
78
111
  ---
@@ -211,7 +244,7 @@ if (book.yes.bids.length > 0) {
211
244
 
212
245
  #### `getOpenOrders(marketAppId, walletAddress?)`
213
246
 
214
- Gets open orders for a wallet on a specific market.
247
+ Gets open orders for a wallet on a specific market (from on-chain data).
215
248
 
216
249
  ```typescript
217
250
  const orders = await client.getOpenOrders(123456789);
@@ -222,6 +255,17 @@ for (const order of orders) {
222
255
  }
223
256
  ```
224
257
 
258
+ #### `getWalletOrdersFromApi(walletAddress)`
259
+
260
+ Gets all open orders for a wallet across every live market via the Alpha REST API. Requires `apiKey`. Paginates automatically.
261
+
262
+ ```typescript
263
+ const orders = await client.getWalletOrdersFromApi('ALGO_ADDRESS...');
264
+ for (const order of orders) {
265
+ console.log(`Market ${order.marketAppId} | Escrow ${order.escrowAppId} | ${order.quantityFilled / 1e6} filled`);
266
+ }
267
+ ```
268
+
225
269
  ---
226
270
 
227
271
  ### Markets
@@ -259,6 +303,17 @@ const markets = await client.getLiveMarketsFromApi();
259
303
  const market = await client.getMarketFromApi('uuid-here');
260
304
  ```
261
305
 
306
+ #### `getRewardMarkets()`
307
+
308
+ Fetches markets that have liquidity rewards from the Alpha REST API. Requires `apiKey`. Returns the same `Market[]` shape with reward fields populated: `totalRewards`, `rewardsPaidOut`, `rewardsSpreadDistance`, `rewardsMinContracts`, `lastRewardAmount`, `lastRewardTs`.
309
+
310
+ ```typescript
311
+ const rewardMarkets = await client.getRewardMarkets();
312
+ for (const m of rewardMarkets) {
313
+ console.log(`${m.title}: $${(m.totalRewards ?? 0) / 1e6} total rewards`);
314
+ }
315
+ ```
316
+
262
317
  ---
263
318
 
264
319
  ### Utility Functions
package/dist/index.cjs CHANGED
@@ -1429,7 +1429,7 @@ var calculateMatchingOrders = (orderbook, isBuying, isYes, quantity, price, slip
1429
1429
  };
1430
1430
 
1431
1431
  // src/constants.ts
1432
- var DEFAULT_API_BASE_URL = "https://partners.alphaarcade.com/api";
1432
+ var DEFAULT_API_BASE_URL = "https://platform.alphaarcade.com/api";
1433
1433
  var DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
1434
1434
 
1435
1435
  // src/modules/orderbook.ts
@@ -1539,7 +1539,7 @@ var normalizeApiOrder = (raw) => ({
1539
1539
  });
1540
1540
  var getWalletOrdersFromApi = async (config, walletAddress) => {
1541
1541
  if (!config.apiKey) {
1542
- throw new Error("apiKey is required for API-based market fetching.");
1542
+ throw new Error("apiKey is required for API-based market fetching. Retrieve an API key from the Alpha Arcade platform via the Account page and pass it to the client.");
1543
1543
  }
1544
1544
  const baseUrl = config.apiBaseUrl ?? DEFAULT_API_BASE_URL;
1545
1545
  const allOrders = [];
@@ -2143,7 +2143,7 @@ var getMarketOnChain = async (config, marketAppId) => {
2143
2143
  };
2144
2144
  var getLiveMarketsFromApi = async (config) => {
2145
2145
  if (!config.apiKey) {
2146
- throw new Error("apiKey is required for API-based market fetching. Use getMarketsOnChain() instead, or pass an apiKey.");
2146
+ throw new Error("apiKey is required for API-based market fetching. Use getMarketsOnChain() instead, or retrieve an API key from the Alpha Arcade platform via the Account page and pass it to the client.");
2147
2147
  }
2148
2148
  const baseUrl = config.apiBaseUrl ?? DEFAULT_API_BASE_URL;
2149
2149
  const allMarkets = [];
@@ -2180,7 +2180,7 @@ var getLiveMarketsFromApi = async (config) => {
2180
2180
  };
2181
2181
  var getMarketFromApi = async (config, marketId) => {
2182
2182
  if (!config.apiKey) {
2183
- throw new Error("apiKey is required for API-based market fetching. Use getMarketOnChain() instead, or pass an apiKey.");
2183
+ throw new Error("apiKey is required for API-based market fetching. Use getMarketOnChain() instead, or retrieve an API key from the Alpha Arcade platform via the Account page and pass it to the client.");
2184
2184
  }
2185
2185
  const baseUrl = config.apiBaseUrl ?? DEFAULT_API_BASE_URL;
2186
2186
  const url = `${baseUrl}/get-market?marketId=${encodeURIComponent(marketId)}`;
@@ -2197,6 +2197,13 @@ var getMarketFromApi = async (config, marketId) => {
2197
2197
  }
2198
2198
  return market;
2199
2199
  };
2200
+ var getRewardMarkets = async (config) => {
2201
+ if (!config.apiKey) {
2202
+ throw new Error("apiKey is required for API-based market fetching. Retrieve an API key from the Alpha Arcade platform via the Account page and pass it to the client.");
2203
+ }
2204
+ const markets = await getLiveMarketsFromApi(config);
2205
+ return markets.filter((m) => m.totalRewards && m.totalRewards > 0);
2206
+ };
2200
2207
  var getLiveMarkets = async (config) => {
2201
2208
  if (config.apiKey) {
2202
2209
  return getLiveMarketsFromApi(config);
@@ -2420,6 +2427,14 @@ var AlphaClient = class {
2420
2427
  async getLiveMarketsFromApi() {
2421
2428
  return getLiveMarketsFromApi(this.config);
2422
2429
  }
2430
+ /**
2431
+ * Fetches the reward markets from the Alpha REST API (requires API key).
2432
+ *
2433
+ * @returns Array of reward markets
2434
+ */
2435
+ async getRewardMarkets() {
2436
+ return getRewardMarkets(this.config);
2437
+ }
2423
2438
  /**
2424
2439
  * Fetches a single market by ID from the Alpha REST API (requires API key).
2425
2440
  *