@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/dist/index.d.cts CHANGED
@@ -340,7 +340,7 @@ type EscrowGlobalState = {
340
340
  * });
341
341
  *
342
342
  * // Fetch markets
343
- * const markets = await client.getMarkets();
343
+ * const markets = await client.getLiveMarkets();
344
344
  *
345
345
  * // Place a limit order
346
346
  * const result = await client.createLimitOrder({
@@ -463,7 +463,7 @@ declare class AlphaClient {
463
463
  *
464
464
  * @returns Array of live markets
465
465
  */
466
- getMarkets(): Promise<Market[]>;
466
+ getLiveMarkets(): Promise<Market[]>;
467
467
  /**
468
468
  * Fetches a single market by its ID.
469
469
  *
@@ -498,7 +498,7 @@ declare class AlphaClient {
498
498
  *
499
499
  * @returns Array of live markets from the API
500
500
  */
501
- getMarketsFromApi(): Promise<Market[]>;
501
+ getLiveMarketsFromApi(): Promise<Market[]>;
502
502
  /**
503
503
  * Fetches a single market by ID from the Alpha REST API (requires API key).
504
504
  *
@@ -540,7 +540,7 @@ declare const getMarketOnChain: (config: AlphaClientConfig, marketAppId: number
540
540
  * @param config - Alpha client config
541
541
  * @returns Array of live markets
542
542
  */
543
- declare const getMarketsFromApi: (config: AlphaClientConfig) => Promise<Market[]>;
543
+ declare const getLiveMarketsFromApi: (config: AlphaClientConfig) => Promise<Market[]>;
544
544
  /**
545
545
  * Fetches a single market by its ID from the Alpha REST API.
546
546
  * Requires an API key.
@@ -629,4 +629,4 @@ declare const getEscrowGlobalState: (indexerClient: algosdk.Indexer, escrowAppId
629
629
  */
630
630
  declare const checkAssetOptIn: (algodClient: algosdk.Algodv2, address: string, assetId: number) => Promise<boolean>;
631
631
 
632
- 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 CreateMarketOrderResult, 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, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsFromApi, getMarketsOnChain };
632
+ 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 CreateMarketOrderResult, 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 };
package/dist/index.d.ts CHANGED
@@ -340,7 +340,7 @@ type EscrowGlobalState = {
340
340
  * });
341
341
  *
342
342
  * // Fetch markets
343
- * const markets = await client.getMarkets();
343
+ * const markets = await client.getLiveMarkets();
344
344
  *
345
345
  * // Place a limit order
346
346
  * const result = await client.createLimitOrder({
@@ -463,7 +463,7 @@ declare class AlphaClient {
463
463
  *
464
464
  * @returns Array of live markets
465
465
  */
466
- getMarkets(): Promise<Market[]>;
466
+ getLiveMarkets(): Promise<Market[]>;
467
467
  /**
468
468
  * Fetches a single market by its ID.
469
469
  *
@@ -498,7 +498,7 @@ declare class AlphaClient {
498
498
  *
499
499
  * @returns Array of live markets from the API
500
500
  */
501
- getMarketsFromApi(): Promise<Market[]>;
501
+ getLiveMarketsFromApi(): Promise<Market[]>;
502
502
  /**
503
503
  * Fetches a single market by ID from the Alpha REST API (requires API key).
504
504
  *
@@ -540,7 +540,7 @@ declare const getMarketOnChain: (config: AlphaClientConfig, marketAppId: number
540
540
  * @param config - Alpha client config
541
541
  * @returns Array of live markets
542
542
  */
543
- declare const getMarketsFromApi: (config: AlphaClientConfig) => Promise<Market[]>;
543
+ declare const getLiveMarketsFromApi: (config: AlphaClientConfig) => Promise<Market[]>;
544
544
  /**
545
545
  * Fetches a single market by its ID from the Alpha REST API.
546
546
  * Requires an API key.
@@ -629,4 +629,4 @@ declare const getEscrowGlobalState: (indexerClient: algosdk.Indexer, escrowAppId
629
629
  */
630
630
  declare const checkAssetOptIn: (algodClient: algosdk.Algodv2, address: string, assetId: number) => Promise<boolean>;
631
631
 
632
- 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 CreateMarketOrderResult, 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, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsFromApi, getMarketsOnChain };
632
+ 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 CreateMarketOrderResult, 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 };
package/dist/index.js CHANGED
@@ -1944,6 +1944,7 @@ var getPositions = async (config, walletAddress) => {
1944
1944
  // src/modules/markets.ts
1945
1945
  var DEFAULT_API_BASE_URL = "https://partners.alphaarcade.com/api";
1946
1946
  var DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
1947
+ var toSeconds = (ts) => ts > 1e10 ? Math.floor(ts / 1e3) : ts;
1947
1948
  var groupMultiChoiceMarkets = (flatMarkets) => {
1948
1949
  const parentMap = /* @__PURE__ */ new Map();
1949
1950
  const result = [];
@@ -2054,7 +2055,7 @@ var getMarketOnChain = async (config, marketAppId) => {
2054
2055
  return null;
2055
2056
  }
2056
2057
  };
2057
- var getMarketsFromApi = async (config) => {
2058
+ var getLiveMarketsFromApi = async (config) => {
2058
2059
  if (!config.apiKey) {
2059
2060
  throw new Error("apiKey is required for API-based market fetching. Use getMarketsOnChain() instead, or pass an apiKey.");
2060
2061
  }
@@ -2067,17 +2068,22 @@ var getMarketsFromApi = async (config) => {
2067
2068
  if (lastEvaluatedKey) {
2068
2069
  params.set("lastEvaluatedKey", lastEvaluatedKey);
2069
2070
  }
2070
- const url = `${baseUrl}/get-live-markets?${params.toString()}`;
2071
+ const url = `${baseUrl}/get-live-markets-cached?${params.toString()}`;
2071
2072
  const response = await fetch(url, { headers: { "x-api-key": config.apiKey } });
2072
2073
  if (!response.ok) {
2073
2074
  throw new Error(`Alpha API error: ${response.status} ${response.statusText}`);
2074
2075
  }
2075
2076
  const data = await response.json();
2077
+ const normalizeApiMarket = (m) => ({
2078
+ ...m,
2079
+ endTs: m.endTs ? toSeconds(m.endTs) : 0,
2080
+ source: "api"
2081
+ });
2076
2082
  if (Array.isArray(data)) {
2077
- allMarkets.push(...data.map((m) => ({ ...m, source: "api" })));
2083
+ allMarkets.push(...data.map(normalizeApiMarket));
2078
2084
  hasMore = false;
2079
2085
  } else if (data.markets) {
2080
- allMarkets.push(...data.markets.map((m) => ({ ...m, source: "api" })));
2086
+ allMarkets.push(...data.markets.map(normalizeApiMarket));
2081
2087
  lastEvaluatedKey = data.lastEvaluatedKey;
2082
2088
  hasMore = !!lastEvaluatedKey;
2083
2089
  } else {
@@ -2099,12 +2105,15 @@ var getMarketFromApi = async (config, marketId) => {
2099
2105
  }
2100
2106
  const data = await response.json();
2101
2107
  const market = data.market ?? data ?? null;
2102
- if (market) market.source = "api";
2108
+ if (market) {
2109
+ market.source = "api";
2110
+ if (market.endTs) market.endTs = toSeconds(market.endTs);
2111
+ }
2103
2112
  return market;
2104
2113
  };
2105
- var getMarkets = async (config) => {
2114
+ var getLiveMarkets = async (config) => {
2106
2115
  if (config.apiKey) {
2107
- return getMarketsFromApi(config);
2116
+ return getLiveMarketsFromApi(config);
2108
2117
  }
2109
2118
  return getMarketsOnChain(config);
2110
2119
  };
@@ -2270,8 +2279,8 @@ var AlphaClient = class {
2270
2279
  *
2271
2280
  * @returns Array of live markets
2272
2281
  */
2273
- async getMarkets() {
2274
- return getMarkets(this.config);
2282
+ async getLiveMarkets() {
2283
+ return getLiveMarkets(this.config);
2275
2284
  }
2276
2285
  /**
2277
2286
  * Fetches a single market by its ID.
@@ -2313,8 +2322,8 @@ var AlphaClient = class {
2313
2322
  *
2314
2323
  * @returns Array of live markets from the API
2315
2324
  */
2316
- async getMarketsFromApi() {
2317
- return getMarketsFromApi(this.config);
2325
+ async getLiveMarketsFromApi() {
2326
+ return getLiveMarketsFromApi(this.config);
2318
2327
  }
2319
2328
  /**
2320
2329
  * Fetches a single market by ID from the Alpha REST API (requires API key).
@@ -2327,6 +2336,6 @@ var AlphaClient = class {
2327
2336
  }
2328
2337
  };
2329
2338
 
2330
- export { AlphaClient, DEFAULT_MARKET_CREATOR_ADDRESS, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsFromApi, getMarketsOnChain };
2339
+ export { AlphaClient, DEFAULT_MARKET_CREATOR_ADDRESS, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getLiveMarketsFromApi, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsOnChain };
2331
2340
  //# sourceMappingURL=index.js.map
2332
2341
  //# sourceMappingURL=index.js.map