@alpha-arcade/sdk 0.2.5 → 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/README.md +2 -2
- package/dist/index.cjs +75 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -9
- package/dist/index.d.ts +14 -9
- package/dist/index.js +75 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -158,13 +158,10 @@ type CreateOrderResult = {
|
|
|
158
158
|
txIds: string[];
|
|
159
159
|
/** Confirmed round number */
|
|
160
160
|
confirmedRound: number;
|
|
161
|
-
};
|
|
162
|
-
/** Result of creating a market order (includes match info) */
|
|
163
|
-
type CreateMarketOrderResult = CreateOrderResult & {
|
|
164
161
|
/** Total quantity that was matched */
|
|
165
|
-
matchedQuantity
|
|
162
|
+
matchedQuantity?: number;
|
|
166
163
|
/** Weighted average fill price in microunits (accounts for complementary matching) */
|
|
167
|
-
matchedPrice
|
|
164
|
+
matchedPrice?: number;
|
|
168
165
|
};
|
|
169
166
|
/** Result of cancelling an order */
|
|
170
167
|
type CancelOrderResult = {
|
|
@@ -375,7 +372,7 @@ declare class AlphaClient {
|
|
|
375
372
|
* @param params - Order parameters (marketAppId, position, price, quantity, isBuying, slippage)
|
|
376
373
|
* @returns The created escrow app ID, matched quantity, and transaction info
|
|
377
374
|
*/
|
|
378
|
-
createMarketOrder(params: CreateMarketOrderParams): Promise<
|
|
375
|
+
createMarketOrder(params: CreateMarketOrderParams): Promise<CreateOrderResult>;
|
|
379
376
|
/**
|
|
380
377
|
* Cancels an open order by deleting its escrow app.
|
|
381
378
|
*
|
|
@@ -455,6 +452,13 @@ declare class AlphaClient {
|
|
|
455
452
|
* @returns Array of open orders
|
|
456
453
|
*/
|
|
457
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[]>;
|
|
458
462
|
/**
|
|
459
463
|
* Fetches all live, tradeable markets.
|
|
460
464
|
*
|
|
@@ -508,8 +512,6 @@ declare class AlphaClient {
|
|
|
508
512
|
getMarketFromApi(marketId: string): Promise<Market | null>;
|
|
509
513
|
}
|
|
510
514
|
|
|
511
|
-
/** The default Alpha Arcade mainnet market creator address */
|
|
512
|
-
declare const DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
|
|
513
515
|
/**
|
|
514
516
|
* Fetches all live, tradeable markets directly from the Algorand blockchain.
|
|
515
517
|
*
|
|
@@ -551,6 +553,9 @@ declare const getLiveMarketsFromApi: (config: AlphaClientConfig) => Promise<Mark
|
|
|
551
553
|
*/
|
|
552
554
|
declare const getMarketFromApi: (config: AlphaClientConfig, marketId: string) => Promise<Market | null>;
|
|
553
555
|
|
|
556
|
+
declare const DEFAULT_API_BASE_URL = "https://partners.alphaarcade.com/api";
|
|
557
|
+
declare const DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
|
|
558
|
+
|
|
554
559
|
/**
|
|
555
560
|
* Calculates the required fee amount in microunits.
|
|
556
561
|
*
|
|
@@ -629,4 +634,4 @@ declare const getEscrowGlobalState: (indexerClient: algosdk.Indexer, escrowAppId
|
|
|
629
634
|
*/
|
|
630
635
|
declare const checkAssetOptIn: (algodClient: algosdk.Algodv2, address: string, assetId: number) => Promise<boolean>;
|
|
631
636
|
|
|
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
|
|
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
|
@@ -158,13 +158,10 @@ type CreateOrderResult = {
|
|
|
158
158
|
txIds: string[];
|
|
159
159
|
/** Confirmed round number */
|
|
160
160
|
confirmedRound: number;
|
|
161
|
-
};
|
|
162
|
-
/** Result of creating a market order (includes match info) */
|
|
163
|
-
type CreateMarketOrderResult = CreateOrderResult & {
|
|
164
161
|
/** Total quantity that was matched */
|
|
165
|
-
matchedQuantity
|
|
162
|
+
matchedQuantity?: number;
|
|
166
163
|
/** Weighted average fill price in microunits (accounts for complementary matching) */
|
|
167
|
-
matchedPrice
|
|
164
|
+
matchedPrice?: number;
|
|
168
165
|
};
|
|
169
166
|
/** Result of cancelling an order */
|
|
170
167
|
type CancelOrderResult = {
|
|
@@ -375,7 +372,7 @@ declare class AlphaClient {
|
|
|
375
372
|
* @param params - Order parameters (marketAppId, position, price, quantity, isBuying, slippage)
|
|
376
373
|
* @returns The created escrow app ID, matched quantity, and transaction info
|
|
377
374
|
*/
|
|
378
|
-
createMarketOrder(params: CreateMarketOrderParams): Promise<
|
|
375
|
+
createMarketOrder(params: CreateMarketOrderParams): Promise<CreateOrderResult>;
|
|
379
376
|
/**
|
|
380
377
|
* Cancels an open order by deleting its escrow app.
|
|
381
378
|
*
|
|
@@ -455,6 +452,13 @@ declare class AlphaClient {
|
|
|
455
452
|
* @returns Array of open orders
|
|
456
453
|
*/
|
|
457
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[]>;
|
|
458
462
|
/**
|
|
459
463
|
* Fetches all live, tradeable markets.
|
|
460
464
|
*
|
|
@@ -508,8 +512,6 @@ declare class AlphaClient {
|
|
|
508
512
|
getMarketFromApi(marketId: string): Promise<Market | null>;
|
|
509
513
|
}
|
|
510
514
|
|
|
511
|
-
/** The default Alpha Arcade mainnet market creator address */
|
|
512
|
-
declare const DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
|
|
513
515
|
/**
|
|
514
516
|
* Fetches all live, tradeable markets directly from the Algorand blockchain.
|
|
515
517
|
*
|
|
@@ -551,6 +553,9 @@ declare const getLiveMarketsFromApi: (config: AlphaClientConfig) => Promise<Mark
|
|
|
551
553
|
*/
|
|
552
554
|
declare const getMarketFromApi: (config: AlphaClientConfig, marketId: string) => Promise<Market | null>;
|
|
553
555
|
|
|
556
|
+
declare const DEFAULT_API_BASE_URL = "https://partners.alphaarcade.com/api";
|
|
557
|
+
declare const DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
|
|
558
|
+
|
|
554
559
|
/**
|
|
555
560
|
* Calculates the required fee amount in microunits.
|
|
556
561
|
*
|
|
@@ -629,4 +634,4 @@ declare const getEscrowGlobalState: (indexerClient: algosdk.Indexer, escrowAppId
|
|
|
629
634
|
*/
|
|
630
635
|
declare const checkAssetOptIn: (algodClient: algosdk.Algodv2, address: string, assetId: number) => Promise<boolean>;
|
|
631
636
|
|
|
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
|
|
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) => {
|
|
@@ -1519,7 +1568,21 @@ var extractEscrowAppId = async (algodClient, indexerClient, targetTxId) => {
|
|
|
1519
1568
|
return 0;
|
|
1520
1569
|
};
|
|
1521
1570
|
var createLimitOrder = async (config, params) => {
|
|
1522
|
-
|
|
1571
|
+
const orderbook = await getOrderbook(config, params.marketAppId);
|
|
1572
|
+
const matchingOrders = calculateMatchingOrders(
|
|
1573
|
+
orderbook,
|
|
1574
|
+
params.isBuying,
|
|
1575
|
+
params.position === 1,
|
|
1576
|
+
params.quantity,
|
|
1577
|
+
params.price,
|
|
1578
|
+
0
|
|
1579
|
+
);
|
|
1580
|
+
const totalMatchedQuantity = matchingOrders.reduce((sum, o) => sum + o.quantity, 0);
|
|
1581
|
+
const matchedPrice = totalMatchedQuantity > 0 ? Math.round(
|
|
1582
|
+
matchingOrders.reduce((sum, o) => sum + (o.price ?? params.price) * o.quantity, 0) / totalMatchedQuantity
|
|
1583
|
+
) : params.price;
|
|
1584
|
+
const result = await createOrder(config, { ...params, slippage: 0, matchingOrders });
|
|
1585
|
+
return { ...result, matchedQuantity: totalMatchedQuantity, matchedPrice };
|
|
1523
1586
|
};
|
|
1524
1587
|
var createMarketOrder = async (config, params) => {
|
|
1525
1588
|
let matchingOrders = params.matchingOrders;
|
|
@@ -1942,8 +2005,6 @@ var getPositions = async (config, walletAddress) => {
|
|
|
1942
2005
|
};
|
|
1943
2006
|
|
|
1944
2007
|
// src/modules/markets.ts
|
|
1945
|
-
var DEFAULT_API_BASE_URL = "https://partners.alphaarcade.com/api";
|
|
1946
|
-
var DEFAULT_MARKET_CREATOR_ADDRESS = "5P5Y6HTWUNG2E3VXBQDZN3ENZD3JPAIR5PKT3LOYJAPAUKOLFD6KANYTRY";
|
|
1947
2008
|
var toSeconds = (ts) => ts > 1e10 ? Math.floor(ts / 1e3) : ts;
|
|
1948
2009
|
var groupMultiChoiceMarkets = (flatMarkets) => {
|
|
1949
2010
|
const parentMap = /* @__PURE__ */ new Map();
|
|
@@ -2136,7 +2197,7 @@ var AlphaClient = class {
|
|
|
2136
2197
|
if (!config.usdcAssetId) throw new Error("usdcAssetId is required");
|
|
2137
2198
|
this.config = {
|
|
2138
2199
|
...config,
|
|
2139
|
-
apiBaseUrl: config.apiBaseUrl ??
|
|
2200
|
+
apiBaseUrl: config.apiBaseUrl ?? DEFAULT_API_BASE_URL
|
|
2140
2201
|
};
|
|
2141
2202
|
}
|
|
2142
2203
|
// ============================================
|
|
@@ -2268,6 +2329,15 @@ var AlphaClient = class {
|
|
|
2268
2329
|
async getOpenOrders(marketAppId, walletAddress) {
|
|
2269
2330
|
return getOpenOrders(this.config, marketAppId, walletAddress);
|
|
2270
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
|
+
}
|
|
2271
2341
|
// ============================================
|
|
2272
2342
|
// Markets
|
|
2273
2343
|
// ============================================
|
|
@@ -2336,6 +2406,6 @@ var AlphaClient = class {
|
|
|
2336
2406
|
}
|
|
2337
2407
|
};
|
|
2338
2408
|
|
|
2339
|
-
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 };
|
|
2340
2410
|
//# sourceMappingURL=index.js.map
|
|
2341
2411
|
//# sourceMappingURL=index.js.map
|