@alpha-arcade/sdk 0.2.6 → 0.2.7

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/dist/index.cjs CHANGED
@@ -1427,6 +1427,12 @@ var calculateMatchingOrders = (orderbook, isBuying, isYes, quantity, price, slip
1427
1427
  }
1428
1428
  return matches;
1429
1429
  };
1430
+
1431
+ // src/constants.ts
1432
+ var DEFAULT_API_BASE_URL = "https://partners.alphaarcade.com/api";
1433
+ var DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
1434
+
1435
+ // src/modules/orderbook.ts
1430
1436
  var getAllCreatedApplications = async (indexerClient, address, limit = 100) => {
1431
1437
  let applications = [];
1432
1438
  let nextToken;
@@ -1520,6 +1526,49 @@ var getOpenOrders = async (config, marketAppId, walletAddress) => {
1520
1526
  owner: o.globalState.owner ?? ""
1521
1527
  }));
1522
1528
  };
1529
+ var normalizeApiOrder = (raw) => ({
1530
+ escrowAppId: Number(raw.escrowAppId ?? raw.orderId),
1531
+ marketAppId: Number(raw.marketAppId),
1532
+ position: raw.orderPosition ?? 0,
1533
+ side: raw.orderSide === "BUY" ? 1 : 0,
1534
+ price: raw.orderPrice ?? 0,
1535
+ quantity: raw.orderQuantity ?? 0,
1536
+ quantityFilled: raw.orderQuantityFilled ?? 0,
1537
+ slippage: raw.slippage ?? 0,
1538
+ owner: raw.senderWallet ?? ""
1539
+ });
1540
+ var getWalletOrdersFromApi = async (config, walletAddress) => {
1541
+ if (!config.apiKey) {
1542
+ throw new Error("apiKey is required for API-based market fetching.");
1543
+ }
1544
+ const baseUrl = config.apiBaseUrl ?? DEFAULT_API_BASE_URL;
1545
+ const allOrders = [];
1546
+ let cursor;
1547
+ let hasMore = true;
1548
+ while (hasMore) {
1549
+ const params = new URLSearchParams({ wallet: walletAddress, limit: "300" });
1550
+ if (cursor) {
1551
+ params.set("cursor", cursor);
1552
+ }
1553
+ const url = `${baseUrl}/get-wallet-orders?${params.toString()}`;
1554
+ const response = await fetch(url, { headers: { "x-api-key": config.apiKey } });
1555
+ if (!response.ok) {
1556
+ throw new Error(`Alpha API error: ${response.status} ${response.statusText}`);
1557
+ }
1558
+ const data = await response.json();
1559
+ if (Array.isArray(data)) {
1560
+ allOrders.push(...data.map(normalizeApiOrder));
1561
+ hasMore = false;
1562
+ } else if (data.orders) {
1563
+ allOrders.push(...data.orders.map(normalizeApiOrder));
1564
+ cursor = data.nextCursor ?? void 0;
1565
+ hasMore = data.hasMore === true && !!cursor;
1566
+ } else {
1567
+ hasMore = false;
1568
+ }
1569
+ }
1570
+ return allOrders;
1571
+ };
1523
1572
 
1524
1573
  // src/modules/trading.ts
1525
1574
  var extractEscrowAppId = async (algodClient, indexerClient, targetTxId) => {
@@ -1981,8 +2030,6 @@ var getPositions = async (config, walletAddress) => {
1981
2030
  };
1982
2031
 
1983
2032
  // src/modules/markets.ts
1984
- var DEFAULT_API_BASE_URL = "https://partners.alphaarcade.com/api";
1985
- var DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
1986
2033
  var toSeconds = (ts) => ts > 1e10 ? Math.floor(ts / 1e3) : ts;
1987
2034
  var groupMultiChoiceMarkets = (flatMarkets) => {
1988
2035
  const parentMap = /* @__PURE__ */ new Map();
@@ -2175,7 +2222,7 @@ var AlphaClient = class {
2175
2222
  if (!config.usdcAssetId) throw new Error("usdcAssetId is required");
2176
2223
  this.config = {
2177
2224
  ...config,
2178
- apiBaseUrl: config.apiBaseUrl ?? "https://partners.alphaarcade.com/api"
2225
+ apiBaseUrl: config.apiBaseUrl ?? DEFAULT_API_BASE_URL
2179
2226
  };
2180
2227
  }
2181
2228
  // ============================================
@@ -2307,6 +2354,15 @@ var AlphaClient = class {
2307
2354
  async getOpenOrders(marketAppId, walletAddress) {
2308
2355
  return getOpenOrders(this.config, marketAppId, walletAddress);
2309
2356
  }
2357
+ /**
2358
+ * Gets all open orders for a wallet across every live market using the Alpha REST API.
2359
+ *
2360
+ * @param walletAddress - The wallet address
2361
+ * @returns Array of open orders for the wallet
2362
+ */
2363
+ async getWalletOrdersFromApi(walletAddress) {
2364
+ return getWalletOrdersFromApi(this.config, walletAddress);
2365
+ }
2310
2366
  // ============================================
2311
2367
  // Markets
2312
2368
  // ============================================
@@ -2376,6 +2432,7 @@ var AlphaClient = class {
2376
2432
  };
2377
2433
 
2378
2434
  exports.AlphaClient = AlphaClient;
2435
+ exports.DEFAULT_API_BASE_URL = DEFAULT_API_BASE_URL;
2379
2436
  exports.DEFAULT_MARKET_CREATOR_ADDRESS = DEFAULT_MARKET_CREATOR_ADDRESS;
2380
2437
  exports.calculateFee = calculateFee;
2381
2438
  exports.calculateFeeFromTotal = calculateFeeFromTotal;