@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.d.cts CHANGED
@@ -452,6 +452,13 @@ declare class AlphaClient {
452
452
  * @returns Array of open orders
453
453
  */
454
454
  getOpenOrders(marketAppId: number, walletAddress?: string): Promise<OpenOrder[]>;
455
+ /**
456
+ * Gets all open orders for a wallet across every live market using the Alpha REST API.
457
+ *
458
+ * @param walletAddress - The wallet address
459
+ * @returns Array of open orders for the wallet
460
+ */
461
+ getWalletOrdersFromApi(walletAddress: string): Promise<OpenOrder[]>;
455
462
  /**
456
463
  * Fetches all live, tradeable markets.
457
464
  *
@@ -505,8 +512,6 @@ declare class AlphaClient {
505
512
  getMarketFromApi(marketId: string): Promise<Market | null>;
506
513
  }
507
514
 
508
- /** The default Alpha Arcade mainnet market creator address */
509
- declare const DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
510
515
  /**
511
516
  * Fetches all live, tradeable markets directly from the Algorand blockchain.
512
517
  *
@@ -548,6 +553,9 @@ declare const getLiveMarketsFromApi: (config: AlphaClientConfig) => Promise<Mark
548
553
  */
549
554
  declare const getMarketFromApi: (config: AlphaClientConfig, marketId: string) => Promise<Market | null>;
550
555
 
556
+ declare const DEFAULT_API_BASE_URL = "https://partners.alphaarcade.com/api";
557
+ declare const DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
558
+
551
559
  /**
552
560
  * Calculates the required fee amount in microunits.
553
561
  *
@@ -626,4 +634,4 @@ declare const getEscrowGlobalState: (indexerClient: algosdk.Indexer, escrowAppId
626
634
  */
627
635
  declare const checkAssetOptIn: (algodClient: algosdk.Algodv2, address: string, assetId: number) => Promise<boolean>;
628
636
 
629
- export { type AggregatedOrderbook, type AggregatedOrderbookEntry, type AggregatedOrderbookSide, AlphaClient, type AlphaClientConfig, type CancelOrderParams, type CancelOrderResult, type ClaimParams, type ClaimResult, type CounterpartyMatch, type CreateLimitOrderParams, type CreateMarketOrderParams, type CreateOrderResult, DEFAULT_MARKET_CREATOR_ADDRESS, type EscrowGlobalState, type Market, type MarketGlobalState, type MarketOption, type MergeSharesParams, type OpenOrder, type OrderSide, type Orderbook, type OrderbookEntry, type OrderbookSide, type Position, type ProposeMatchParams, type ProposeMatchResult, type SplitMergeResult, type SplitSharesParams, type WalletPosition, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getLiveMarketsFromApi, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsOnChain };
637
+ export { type AggregatedOrderbook, type AggregatedOrderbookEntry, type AggregatedOrderbookSide, AlphaClient, type AlphaClientConfig, type CancelOrderParams, type CancelOrderResult, type ClaimParams, type ClaimResult, type CounterpartyMatch, type CreateLimitOrderParams, type CreateMarketOrderParams, type CreateOrderResult, DEFAULT_API_BASE_URL, DEFAULT_MARKET_CREATOR_ADDRESS, type EscrowGlobalState, type Market, type MarketGlobalState, type MarketOption, type MergeSharesParams, type OpenOrder, type OrderSide, type Orderbook, type OrderbookEntry, type OrderbookSide, type Position, type ProposeMatchParams, type ProposeMatchResult, type SplitMergeResult, type SplitSharesParams, type WalletPosition, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getLiveMarketsFromApi, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsOnChain };
package/dist/index.d.ts CHANGED
@@ -452,6 +452,13 @@ declare class AlphaClient {
452
452
  * @returns Array of open orders
453
453
  */
454
454
  getOpenOrders(marketAppId: number, walletAddress?: string): Promise<OpenOrder[]>;
455
+ /**
456
+ * Gets all open orders for a wallet across every live market using the Alpha REST API.
457
+ *
458
+ * @param walletAddress - The wallet address
459
+ * @returns Array of open orders for the wallet
460
+ */
461
+ getWalletOrdersFromApi(walletAddress: string): Promise<OpenOrder[]>;
455
462
  /**
456
463
  * Fetches all live, tradeable markets.
457
464
  *
@@ -505,8 +512,6 @@ declare class AlphaClient {
505
512
  getMarketFromApi(marketId: string): Promise<Market | null>;
506
513
  }
507
514
 
508
- /** The default Alpha Arcade mainnet market creator address */
509
- declare const DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
510
515
  /**
511
516
  * Fetches all live, tradeable markets directly from the Algorand blockchain.
512
517
  *
@@ -548,6 +553,9 @@ declare const getLiveMarketsFromApi: (config: AlphaClientConfig) => Promise<Mark
548
553
  */
549
554
  declare const getMarketFromApi: (config: AlphaClientConfig, marketId: string) => Promise<Market | null>;
550
555
 
556
+ declare const DEFAULT_API_BASE_URL = "https://partners.alphaarcade.com/api";
557
+ declare const DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
558
+
551
559
  /**
552
560
  * Calculates the required fee amount in microunits.
553
561
  *
@@ -626,4 +634,4 @@ declare const getEscrowGlobalState: (indexerClient: algosdk.Indexer, escrowAppId
626
634
  */
627
635
  declare const checkAssetOptIn: (algodClient: algosdk.Algodv2, address: string, assetId: number) => Promise<boolean>;
628
636
 
629
- export { type AggregatedOrderbook, type AggregatedOrderbookEntry, type AggregatedOrderbookSide, AlphaClient, type AlphaClientConfig, type CancelOrderParams, type CancelOrderResult, type ClaimParams, type ClaimResult, type CounterpartyMatch, type CreateLimitOrderParams, type CreateMarketOrderParams, type CreateOrderResult, DEFAULT_MARKET_CREATOR_ADDRESS, type EscrowGlobalState, type Market, type MarketGlobalState, type MarketOption, type MergeSharesParams, type OpenOrder, type OrderSide, type Orderbook, type OrderbookEntry, type OrderbookSide, type Position, type ProposeMatchParams, type ProposeMatchResult, type SplitMergeResult, type SplitSharesParams, type WalletPosition, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getLiveMarketsFromApi, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsOnChain };
637
+ export { type AggregatedOrderbook, type AggregatedOrderbookEntry, type AggregatedOrderbookSide, AlphaClient, type AlphaClientConfig, type CancelOrderParams, type CancelOrderResult, type ClaimParams, type ClaimResult, type CounterpartyMatch, type CreateLimitOrderParams, type CreateMarketOrderParams, type CreateOrderResult, DEFAULT_API_BASE_URL, DEFAULT_MARKET_CREATOR_ADDRESS, type EscrowGlobalState, type Market, type MarketGlobalState, type MarketOption, type MergeSharesParams, type OpenOrder, type OrderSide, type Orderbook, type OrderbookEntry, type OrderbookSide, type Position, type ProposeMatchParams, type ProposeMatchResult, type SplitMergeResult, type SplitSharesParams, type WalletPosition, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getLiveMarketsFromApi, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsOnChain };
package/dist/index.js CHANGED
@@ -1402,6 +1402,12 @@ var calculateMatchingOrders = (orderbook, isBuying, isYes, quantity, price, slip
1402
1402
  }
1403
1403
  return matches;
1404
1404
  };
1405
+
1406
+ // src/constants.ts
1407
+ var DEFAULT_API_BASE_URL = "https://partners.alphaarcade.com/api";
1408
+ var DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
1409
+
1410
+ // src/modules/orderbook.ts
1405
1411
  var getAllCreatedApplications = async (indexerClient, address, limit = 100) => {
1406
1412
  let applications = [];
1407
1413
  let nextToken;
@@ -1495,6 +1501,49 @@ var getOpenOrders = async (config, marketAppId, walletAddress) => {
1495
1501
  owner: o.globalState.owner ?? ""
1496
1502
  }));
1497
1503
  };
1504
+ var normalizeApiOrder = (raw) => ({
1505
+ escrowAppId: Number(raw.escrowAppId ?? raw.orderId),
1506
+ marketAppId: Number(raw.marketAppId),
1507
+ position: raw.orderPosition ?? 0,
1508
+ side: raw.orderSide === "BUY" ? 1 : 0,
1509
+ price: raw.orderPrice ?? 0,
1510
+ quantity: raw.orderQuantity ?? 0,
1511
+ quantityFilled: raw.orderQuantityFilled ?? 0,
1512
+ slippage: raw.slippage ?? 0,
1513
+ owner: raw.senderWallet ?? ""
1514
+ });
1515
+ var getWalletOrdersFromApi = async (config, walletAddress) => {
1516
+ if (!config.apiKey) {
1517
+ throw new Error("apiKey is required for API-based market fetching.");
1518
+ }
1519
+ const baseUrl = config.apiBaseUrl ?? DEFAULT_API_BASE_URL;
1520
+ const allOrders = [];
1521
+ let cursor;
1522
+ let hasMore = true;
1523
+ while (hasMore) {
1524
+ const params = new URLSearchParams({ wallet: walletAddress, limit: "300" });
1525
+ if (cursor) {
1526
+ params.set("cursor", cursor);
1527
+ }
1528
+ const url = `${baseUrl}/get-wallet-orders?${params.toString()}`;
1529
+ const response = await fetch(url, { headers: { "x-api-key": config.apiKey } });
1530
+ if (!response.ok) {
1531
+ throw new Error(`Alpha API error: ${response.status} ${response.statusText}`);
1532
+ }
1533
+ const data = await response.json();
1534
+ if (Array.isArray(data)) {
1535
+ allOrders.push(...data.map(normalizeApiOrder));
1536
+ hasMore = false;
1537
+ } else if (data.orders) {
1538
+ allOrders.push(...data.orders.map(normalizeApiOrder));
1539
+ cursor = data.nextCursor ?? void 0;
1540
+ hasMore = data.hasMore === true && !!cursor;
1541
+ } else {
1542
+ hasMore = false;
1543
+ }
1544
+ }
1545
+ return allOrders;
1546
+ };
1498
1547
 
1499
1548
  // src/modules/trading.ts
1500
1549
  var extractEscrowAppId = async (algodClient, indexerClient, targetTxId) => {
@@ -1956,8 +2005,6 @@ var getPositions = async (config, walletAddress) => {
1956
2005
  };
1957
2006
 
1958
2007
  // src/modules/markets.ts
1959
- var DEFAULT_API_BASE_URL = "https://partners.alphaarcade.com/api";
1960
- var DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
1961
2008
  var toSeconds = (ts) => ts > 1e10 ? Math.floor(ts / 1e3) : ts;
1962
2009
  var groupMultiChoiceMarkets = (flatMarkets) => {
1963
2010
  const parentMap = /* @__PURE__ */ new Map();
@@ -2150,7 +2197,7 @@ var AlphaClient = class {
2150
2197
  if (!config.usdcAssetId) throw new Error("usdcAssetId is required");
2151
2198
  this.config = {
2152
2199
  ...config,
2153
- apiBaseUrl: config.apiBaseUrl ?? "https://partners.alphaarcade.com/api"
2200
+ apiBaseUrl: config.apiBaseUrl ?? DEFAULT_API_BASE_URL
2154
2201
  };
2155
2202
  }
2156
2203
  // ============================================
@@ -2282,6 +2329,15 @@ var AlphaClient = class {
2282
2329
  async getOpenOrders(marketAppId, walletAddress) {
2283
2330
  return getOpenOrders(this.config, marketAppId, walletAddress);
2284
2331
  }
2332
+ /**
2333
+ * Gets all open orders for a wallet across every live market using the Alpha REST API.
2334
+ *
2335
+ * @param walletAddress - The wallet address
2336
+ * @returns Array of open orders for the wallet
2337
+ */
2338
+ async getWalletOrdersFromApi(walletAddress) {
2339
+ return getWalletOrdersFromApi(this.config, walletAddress);
2340
+ }
2285
2341
  // ============================================
2286
2342
  // Markets
2287
2343
  // ============================================
@@ -2350,6 +2406,6 @@ var AlphaClient = class {
2350
2406
  }
2351
2407
  };
2352
2408
 
2353
- export { AlphaClient, DEFAULT_MARKET_CREATOR_ADDRESS, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getLiveMarketsFromApi, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsOnChain };
2409
+ export { AlphaClient, DEFAULT_API_BASE_URL, DEFAULT_MARKET_CREATOR_ADDRESS, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getLiveMarketsFromApi, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsOnChain };
2354
2410
  //# sourceMappingURL=index.js.map
2355
2411
  //# sourceMappingURL=index.js.map