@alpha-arcade/sdk 0.2.4 → 0.2.6
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 +9 -9
- package/dist/index.cjs +24 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -11
- package/dist/index.d.ts +8 -11
- package/dist/index.js +24 -10
- 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 = {
|
|
@@ -340,7 +337,7 @@ type EscrowGlobalState = {
|
|
|
340
337
|
* });
|
|
341
338
|
*
|
|
342
339
|
* // Fetch markets
|
|
343
|
-
* const markets = await client.
|
|
340
|
+
* const markets = await client.getLiveMarkets();
|
|
344
341
|
*
|
|
345
342
|
* // Place a limit order
|
|
346
343
|
* const result = await client.createLimitOrder({
|
|
@@ -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
|
*
|
|
@@ -463,7 +460,7 @@ declare class AlphaClient {
|
|
|
463
460
|
*
|
|
464
461
|
* @returns Array of live markets
|
|
465
462
|
*/
|
|
466
|
-
|
|
463
|
+
getLiveMarkets(): Promise<Market[]>;
|
|
467
464
|
/**
|
|
468
465
|
* Fetches a single market by its ID.
|
|
469
466
|
*
|
|
@@ -498,7 +495,7 @@ declare class AlphaClient {
|
|
|
498
495
|
*
|
|
499
496
|
* @returns Array of live markets from the API
|
|
500
497
|
*/
|
|
501
|
-
|
|
498
|
+
getLiveMarketsFromApi(): Promise<Market[]>;
|
|
502
499
|
/**
|
|
503
500
|
* Fetches a single market by ID from the Alpha REST API (requires API key).
|
|
504
501
|
*
|
|
@@ -540,7 +537,7 @@ declare const getMarketOnChain: (config: AlphaClientConfig, marketAppId: number
|
|
|
540
537
|
* @param config - Alpha client config
|
|
541
538
|
* @returns Array of live markets
|
|
542
539
|
*/
|
|
543
|
-
declare const
|
|
540
|
+
declare const getLiveMarketsFromApi: (config: AlphaClientConfig) => Promise<Market[]>;
|
|
544
541
|
/**
|
|
545
542
|
* Fetches a single market by its ID from the Alpha REST API.
|
|
546
543
|
* Requires an API key.
|
|
@@ -629,4 +626,4 @@ declare const getEscrowGlobalState: (indexerClient: algosdk.Indexer, escrowAppId
|
|
|
629
626
|
*/
|
|
630
627
|
declare const checkAssetOptIn: (algodClient: algosdk.Algodv2, address: string, assetId: number) => Promise<boolean>;
|
|
631
628
|
|
|
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
|
|
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 };
|
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 = {
|
|
@@ -340,7 +337,7 @@ type EscrowGlobalState = {
|
|
|
340
337
|
* });
|
|
341
338
|
*
|
|
342
339
|
* // Fetch markets
|
|
343
|
-
* const markets = await client.
|
|
340
|
+
* const markets = await client.getLiveMarkets();
|
|
344
341
|
*
|
|
345
342
|
* // Place a limit order
|
|
346
343
|
* const result = await client.createLimitOrder({
|
|
@@ -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
|
*
|
|
@@ -463,7 +460,7 @@ declare class AlphaClient {
|
|
|
463
460
|
*
|
|
464
461
|
* @returns Array of live markets
|
|
465
462
|
*/
|
|
466
|
-
|
|
463
|
+
getLiveMarkets(): Promise<Market[]>;
|
|
467
464
|
/**
|
|
468
465
|
* Fetches a single market by its ID.
|
|
469
466
|
*
|
|
@@ -498,7 +495,7 @@ declare class AlphaClient {
|
|
|
498
495
|
*
|
|
499
496
|
* @returns Array of live markets from the API
|
|
500
497
|
*/
|
|
501
|
-
|
|
498
|
+
getLiveMarketsFromApi(): Promise<Market[]>;
|
|
502
499
|
/**
|
|
503
500
|
* Fetches a single market by ID from the Alpha REST API (requires API key).
|
|
504
501
|
*
|
|
@@ -540,7 +537,7 @@ declare const getMarketOnChain: (config: AlphaClientConfig, marketAppId: number
|
|
|
540
537
|
* @param config - Alpha client config
|
|
541
538
|
* @returns Array of live markets
|
|
542
539
|
*/
|
|
543
|
-
declare const
|
|
540
|
+
declare const getLiveMarketsFromApi: (config: AlphaClientConfig) => Promise<Market[]>;
|
|
544
541
|
/**
|
|
545
542
|
* Fetches a single market by its ID from the Alpha REST API.
|
|
546
543
|
* Requires an API key.
|
|
@@ -629,4 +626,4 @@ declare const getEscrowGlobalState: (indexerClient: algosdk.Indexer, escrowAppId
|
|
|
629
626
|
*/
|
|
630
627
|
declare const checkAssetOptIn: (algodClient: algosdk.Algodv2, address: string, assetId: number) => Promise<boolean>;
|
|
631
628
|
|
|
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
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1519,7 +1519,21 @@ var extractEscrowAppId = async (algodClient, indexerClient, targetTxId) => {
|
|
|
1519
1519
|
return 0;
|
|
1520
1520
|
};
|
|
1521
1521
|
var createLimitOrder = async (config, params) => {
|
|
1522
|
-
|
|
1522
|
+
const orderbook = await getOrderbook(config, params.marketAppId);
|
|
1523
|
+
const matchingOrders = calculateMatchingOrders(
|
|
1524
|
+
orderbook,
|
|
1525
|
+
params.isBuying,
|
|
1526
|
+
params.position === 1,
|
|
1527
|
+
params.quantity,
|
|
1528
|
+
params.price,
|
|
1529
|
+
0
|
|
1530
|
+
);
|
|
1531
|
+
const totalMatchedQuantity = matchingOrders.reduce((sum, o) => sum + o.quantity, 0);
|
|
1532
|
+
const matchedPrice = totalMatchedQuantity > 0 ? Math.round(
|
|
1533
|
+
matchingOrders.reduce((sum, o) => sum + (o.price ?? params.price) * o.quantity, 0) / totalMatchedQuantity
|
|
1534
|
+
) : params.price;
|
|
1535
|
+
const result = await createOrder(config, { ...params, slippage: 0, matchingOrders });
|
|
1536
|
+
return { ...result, matchedQuantity: totalMatchedQuantity, matchedPrice };
|
|
1523
1537
|
};
|
|
1524
1538
|
var createMarketOrder = async (config, params) => {
|
|
1525
1539
|
let matchingOrders = params.matchingOrders;
|
|
@@ -2055,7 +2069,7 @@ var getMarketOnChain = async (config, marketAppId) => {
|
|
|
2055
2069
|
return null;
|
|
2056
2070
|
}
|
|
2057
2071
|
};
|
|
2058
|
-
var
|
|
2072
|
+
var getLiveMarketsFromApi = async (config) => {
|
|
2059
2073
|
if (!config.apiKey) {
|
|
2060
2074
|
throw new Error("apiKey is required for API-based market fetching. Use getMarketsOnChain() instead, or pass an apiKey.");
|
|
2061
2075
|
}
|
|
@@ -2068,7 +2082,7 @@ var getMarketsFromApi = async (config) => {
|
|
|
2068
2082
|
if (lastEvaluatedKey) {
|
|
2069
2083
|
params.set("lastEvaluatedKey", lastEvaluatedKey);
|
|
2070
2084
|
}
|
|
2071
|
-
const url = `${baseUrl}/get-live-markets?${params.toString()}`;
|
|
2085
|
+
const url = `${baseUrl}/get-live-markets-cached?${params.toString()}`;
|
|
2072
2086
|
const response = await fetch(url, { headers: { "x-api-key": config.apiKey } });
|
|
2073
2087
|
if (!response.ok) {
|
|
2074
2088
|
throw new Error(`Alpha API error: ${response.status} ${response.statusText}`);
|
|
@@ -2111,9 +2125,9 @@ var getMarketFromApi = async (config, marketId) => {
|
|
|
2111
2125
|
}
|
|
2112
2126
|
return market;
|
|
2113
2127
|
};
|
|
2114
|
-
var
|
|
2128
|
+
var getLiveMarkets = async (config) => {
|
|
2115
2129
|
if (config.apiKey) {
|
|
2116
|
-
return
|
|
2130
|
+
return getLiveMarketsFromApi(config);
|
|
2117
2131
|
}
|
|
2118
2132
|
return getMarketsOnChain(config);
|
|
2119
2133
|
};
|
|
@@ -2279,8 +2293,8 @@ var AlphaClient = class {
|
|
|
2279
2293
|
*
|
|
2280
2294
|
* @returns Array of live markets
|
|
2281
2295
|
*/
|
|
2282
|
-
async
|
|
2283
|
-
return
|
|
2296
|
+
async getLiveMarkets() {
|
|
2297
|
+
return getLiveMarkets(this.config);
|
|
2284
2298
|
}
|
|
2285
2299
|
/**
|
|
2286
2300
|
* Fetches a single market by its ID.
|
|
@@ -2322,8 +2336,8 @@ var AlphaClient = class {
|
|
|
2322
2336
|
*
|
|
2323
2337
|
* @returns Array of live markets from the API
|
|
2324
2338
|
*/
|
|
2325
|
-
async
|
|
2326
|
-
return
|
|
2339
|
+
async getLiveMarketsFromApi() {
|
|
2340
|
+
return getLiveMarketsFromApi(this.config);
|
|
2327
2341
|
}
|
|
2328
2342
|
/**
|
|
2329
2343
|
* Fetches a single market by ID from the Alpha REST API (requires API key).
|
|
@@ -2336,6 +2350,6 @@ var AlphaClient = class {
|
|
|
2336
2350
|
}
|
|
2337
2351
|
};
|
|
2338
2352
|
|
|
2339
|
-
export { AlphaClient, DEFAULT_MARKET_CREATOR_ADDRESS, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getMarketFromApi, getMarketGlobalState, getMarketOnChain,
|
|
2353
|
+
export { AlphaClient, DEFAULT_MARKET_CREATOR_ADDRESS, calculateFee, calculateFeeFromTotal, calculateMatchingOrders, checkAssetOptIn, decodeGlobalState, getEscrowGlobalState, getLiveMarketsFromApi, getMarketFromApi, getMarketGlobalState, getMarketOnChain, getMarketsOnChain };
|
|
2340
2354
|
//# sourceMappingURL=index.js.map
|
|
2341
2355
|
//# sourceMappingURL=index.js.map
|