@alva-ai/toolkit 0.26.0 → 0.27.0
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 +4 -1
- package/dist/browser.global.js +14 -14
- package/dist/browser.global.js.map +1 -1
- package/dist/cli.d.ts +41 -2
- package/dist/cli.js +390 -12
- package/dist/cli.js.map +1 -1
- package/dist/dispatch.d.ts +41 -2
- package/dist/dispatch.js +253 -6
- package/dist/dispatch.js.map +1 -1
- package/dist/index.cjs +198 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -3
- package/dist/index.d.ts +42 -3
- package/dist/index.js +197 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.d.ts
CHANGED
|
@@ -1681,8 +1681,8 @@ declare class NotificationsResource {
|
|
|
1681
1681
|
constructor(client: AlvaClient);
|
|
1682
1682
|
/**
|
|
1683
1683
|
* List the caller's notification history for one feed
|
|
1684
|
-
* `(username, name)`. Authorization
|
|
1685
|
-
*
|
|
1684
|
+
* `(username, name)`. Authorization uses the backend's canonical Feed read
|
|
1685
|
+
* decision (owner, public, bundled paid access, Plan, or Access Group).
|
|
1686
1686
|
*/
|
|
1687
1687
|
listFeed(params: NotificationListParams): Promise<FeedNotificationListResponse>;
|
|
1688
1688
|
}
|
|
@@ -2106,6 +2106,43 @@ declare class SchedulesResource {
|
|
|
2106
2106
|
private graphql;
|
|
2107
2107
|
}
|
|
2108
2108
|
|
|
2109
|
+
interface TradingPairCandidate {
|
|
2110
|
+
/** Underlying ticker returned by the market catalog. */
|
|
2111
|
+
symbol: string;
|
|
2112
|
+
/** Complete canonical identity used by OHLCV, Altra, and orders. */
|
|
2113
|
+
tradingPair: string;
|
|
2114
|
+
market: string;
|
|
2115
|
+
instrumentType: string;
|
|
2116
|
+
underlyingType?: string;
|
|
2117
|
+
quote: string;
|
|
2118
|
+
type?: string;
|
|
2119
|
+
description?: string;
|
|
2120
|
+
feeRate?: number;
|
|
2121
|
+
symbolIconUrl?: string;
|
|
2122
|
+
}
|
|
2123
|
+
interface TradingPairSearchParams {
|
|
2124
|
+
symbol: string;
|
|
2125
|
+
market?: string;
|
|
2126
|
+
instrumentType?: string;
|
|
2127
|
+
underlyingType?: string;
|
|
2128
|
+
quote?: string;
|
|
2129
|
+
limit?: number;
|
|
2130
|
+
}
|
|
2131
|
+
interface TradingPairSearchResponse {
|
|
2132
|
+
query: string;
|
|
2133
|
+
candidates: TradingPairCandidate[];
|
|
2134
|
+
truncated?: boolean;
|
|
2135
|
+
}
|
|
2136
|
+
type TradingPairResolveFilters = Omit<TradingPairSearchParams, 'symbol' | 'limit'>;
|
|
2137
|
+
declare class TradingPairsResource {
|
|
2138
|
+
private client;
|
|
2139
|
+
constructor(client: AlvaClient);
|
|
2140
|
+
search(params: TradingPairSearchParams): Promise<TradingPairSearchResponse>;
|
|
2141
|
+
resolve(params: ({
|
|
2142
|
+
pair: string;
|
|
2143
|
+
} & TradingPairResolveFilters) | Omit<TradingPairSearchParams, 'limit'>): Promise<TradingPairCandidate>;
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2109
2146
|
interface RequestOptions {
|
|
2110
2147
|
query?: Record<string, unknown>;
|
|
2111
2148
|
body?: unknown;
|
|
@@ -2172,6 +2209,7 @@ declare class AlvaClient {
|
|
|
2172
2209
|
private _credits?;
|
|
2173
2210
|
private _markets?;
|
|
2174
2211
|
private _schedules?;
|
|
2212
|
+
private _tradingPairs?;
|
|
2175
2213
|
constructor(config: AlvaClientConfig);
|
|
2176
2214
|
get fs(): FsResource;
|
|
2177
2215
|
get run(): RunResource;
|
|
@@ -2201,6 +2239,7 @@ declare class AlvaClient {
|
|
|
2201
2239
|
get functions(): FunctionsResource;
|
|
2202
2240
|
get credits(): CreditsResource;
|
|
2203
2241
|
get markets(): MarketsResource;
|
|
2242
|
+
get tradingPairs(): TradingPairsResource;
|
|
2204
2243
|
get schedules(): SchedulesResource;
|
|
2205
2244
|
_requireAuth(): void;
|
|
2206
2245
|
_request(method: string, path: string, options?: RequestOptions): Promise<unknown>;
|
package/dist/cli.js
CHANGED
|
@@ -8179,8 +8179,8 @@ var NotificationsResource = class {
|
|
|
8179
8179
|
client;
|
|
8180
8180
|
/**
|
|
8181
8181
|
* List the caller's notification history for one feed
|
|
8182
|
-
* `(username, name)`. Authorization
|
|
8183
|
-
*
|
|
8182
|
+
* `(username, name)`. Authorization uses the backend's canonical Feed read
|
|
8183
|
+
* decision (owner, public, bundled paid access, Plan, or Access Group).
|
|
8184
8184
|
*/
|
|
8185
8185
|
async listFeed(params) {
|
|
8186
8186
|
this.client._requireAuth();
|
|
@@ -9442,14 +9442,199 @@ function scheduleEmptyResponse() {
|
|
|
9442
9442
|
);
|
|
9443
9443
|
}
|
|
9444
9444
|
|
|
9445
|
+
// src/resources/tradingPairs.ts
|
|
9446
|
+
function isRecord(value) {
|
|
9447
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9448
|
+
}
|
|
9449
|
+
function stringValue(value) {
|
|
9450
|
+
return typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
9451
|
+
}
|
|
9452
|
+
function numberValue(value) {
|
|
9453
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
9454
|
+
}
|
|
9455
|
+
function upper(value) {
|
|
9456
|
+
return value === void 0 ? void 0 : value.trim().toUpperCase();
|
|
9457
|
+
}
|
|
9458
|
+
function pairParts(pair) {
|
|
9459
|
+
return pair.split("_");
|
|
9460
|
+
}
|
|
9461
|
+
function inferInstrumentType(rawType, tradingPair) {
|
|
9462
|
+
const type = rawType?.toLowerCase();
|
|
9463
|
+
if (type?.includes("spot")) return "spot";
|
|
9464
|
+
if (type?.includes("perp")) return "perp";
|
|
9465
|
+
if (type?.includes("option")) return "option";
|
|
9466
|
+
return pairParts(tradingPair)[1]?.toLowerCase() ?? "";
|
|
9467
|
+
}
|
|
9468
|
+
function inferUnderlyingType(rawType) {
|
|
9469
|
+
if (rawType === void 0) return void 0;
|
|
9470
|
+
const prefix = rawType.split("-")[0]?.trim().toLowerCase();
|
|
9471
|
+
return prefix && prefix !== rawType.toLowerCase() ? prefix : void 0;
|
|
9472
|
+
}
|
|
9473
|
+
function normalizeCandidate(raw, outerSymbol) {
|
|
9474
|
+
const tradingPair = stringValue(raw.trading_pair) ?? stringValue(raw.tradingPair) ?? stringValue(raw.symbol);
|
|
9475
|
+
if (tradingPair === void 0) return void 0;
|
|
9476
|
+
const type = stringValue(raw.type);
|
|
9477
|
+
const parts = pairParts(tradingPair);
|
|
9478
|
+
const symbol = stringValue(raw.base) ?? outerSymbol ?? (parts.length >= 4 ? parts.slice(2, -1).join("_") : parts.length === 3 ? parts[2] : tradingPair);
|
|
9479
|
+
const market = stringValue(raw.market) ?? stringValue(raw.exchange) ?? parts[0] ?? "";
|
|
9480
|
+
const quote = stringValue(raw.quote) ?? parts[parts.length - 1] ?? "";
|
|
9481
|
+
const instrumentType = stringValue(raw.instrument_type) ?? stringValue(raw.instrumentType) ?? inferInstrumentType(type, tradingPair);
|
|
9482
|
+
const underlyingType = stringValue(raw.underlying_type) ?? stringValue(raw.underlyingType) ?? inferUnderlyingType(type);
|
|
9483
|
+
return {
|
|
9484
|
+
symbol,
|
|
9485
|
+
tradingPair,
|
|
9486
|
+
market,
|
|
9487
|
+
instrumentType,
|
|
9488
|
+
...underlyingType === void 0 ? {} : { underlyingType },
|
|
9489
|
+
quote,
|
|
9490
|
+
...type === void 0 ? {} : { type },
|
|
9491
|
+
...stringValue(raw.description) === void 0 ? {} : { description: stringValue(raw.description) },
|
|
9492
|
+
...numberValue(raw.fee_rate) === void 0 ? numberValue(raw.feeRate) === void 0 ? {} : { feeRate: numberValue(raw.feeRate) } : { feeRate: numberValue(raw.fee_rate) },
|
|
9493
|
+
...stringValue(raw.symbol_icon_url) === void 0 ? stringValue(raw.symbolIconUrl) === void 0 ? {} : { symbolIconUrl: stringValue(raw.symbolIconUrl) } : { symbolIconUrl: stringValue(raw.symbol_icon_url) }
|
|
9494
|
+
};
|
|
9495
|
+
}
|
|
9496
|
+
function flattenResponse(value) {
|
|
9497
|
+
if (!isRecord(value)) return [];
|
|
9498
|
+
const flat = value.trading_pairs;
|
|
9499
|
+
if (Array.isArray(flat)) {
|
|
9500
|
+
return flat.flatMap(
|
|
9501
|
+
(item) => isRecord(item) ? [normalizeCandidate(item)].filter(
|
|
9502
|
+
(candidate) => candidate !== void 0
|
|
9503
|
+
) : []
|
|
9504
|
+
);
|
|
9505
|
+
}
|
|
9506
|
+
const data = value.data;
|
|
9507
|
+
if (!Array.isArray(data)) return [];
|
|
9508
|
+
const candidates = [];
|
|
9509
|
+
for (const symbolGroup of data) {
|
|
9510
|
+
if (!isRecord(symbolGroup)) continue;
|
|
9511
|
+
const symbol = stringValue(symbolGroup.symbol);
|
|
9512
|
+
const groups = symbolGroup.trading_pairs;
|
|
9513
|
+
if (!Array.isArray(groups)) continue;
|
|
9514
|
+
for (const group of groups) {
|
|
9515
|
+
if (!isRecord(group) || !Array.isArray(group.pairs)) continue;
|
|
9516
|
+
for (const pair of group.pairs) {
|
|
9517
|
+
if (!isRecord(pair)) continue;
|
|
9518
|
+
const candidate = normalizeCandidate(
|
|
9519
|
+
{
|
|
9520
|
+
...pair,
|
|
9521
|
+
instrument_type: pair.instrument_type ?? group.instrument_type
|
|
9522
|
+
},
|
|
9523
|
+
symbol
|
|
9524
|
+
);
|
|
9525
|
+
if (candidate !== void 0) candidates.push(candidate);
|
|
9526
|
+
}
|
|
9527
|
+
}
|
|
9528
|
+
}
|
|
9529
|
+
return candidates;
|
|
9530
|
+
}
|
|
9531
|
+
function matchesQuery(candidate, query) {
|
|
9532
|
+
const expected = query.trim();
|
|
9533
|
+
if (candidate.tradingPair === expected) return true;
|
|
9534
|
+
return upper(candidate.symbol) === upper(expected);
|
|
9535
|
+
}
|
|
9536
|
+
function matchesFilter(value, expected) {
|
|
9537
|
+
return expected === void 0 || upper(value) === upper(expected);
|
|
9538
|
+
}
|
|
9539
|
+
function dedupe(candidates) {
|
|
9540
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9541
|
+
return candidates.filter((candidate) => {
|
|
9542
|
+
if (seen.has(candidate.tradingPair)) return false;
|
|
9543
|
+
seen.add(candidate.tradingPair);
|
|
9544
|
+
return true;
|
|
9545
|
+
});
|
|
9546
|
+
}
|
|
9547
|
+
function resolveFilters(params) {
|
|
9548
|
+
const record = isRecord(params) ? params : {};
|
|
9549
|
+
return {
|
|
9550
|
+
market: typeof record.market === "string" ? record.market : void 0,
|
|
9551
|
+
instrumentType: typeof record.instrumentType === "string" ? record.instrumentType : void 0,
|
|
9552
|
+
underlyingType: typeof record.underlyingType === "string" ? record.underlyingType : void 0,
|
|
9553
|
+
quote: typeof record.quote === "string" ? record.quote : void 0
|
|
9554
|
+
};
|
|
9555
|
+
}
|
|
9556
|
+
function pairSearchParams(pair, params) {
|
|
9557
|
+
const parts = pair.split("_");
|
|
9558
|
+
const market = parts[0];
|
|
9559
|
+
const instrumentType = parts[1];
|
|
9560
|
+
const symbol = parts.length >= 4 ? parts.slice(2, -1).join("_") : parts.length === 3 ? parts[2] : void 0;
|
|
9561
|
+
const quote = parts.at(-1);
|
|
9562
|
+
if (!market || !instrumentType || !symbol || !quote) {
|
|
9563
|
+
return { symbol: pair, ...params };
|
|
9564
|
+
}
|
|
9565
|
+
return {
|
|
9566
|
+
symbol,
|
|
9567
|
+
market: params.market ?? market,
|
|
9568
|
+
instrumentType: params.instrumentType ?? instrumentType,
|
|
9569
|
+
underlyingType: params.underlyingType,
|
|
9570
|
+
quote: params.quote ?? quote
|
|
9571
|
+
};
|
|
9572
|
+
}
|
|
9573
|
+
var TradingPairsResource = class {
|
|
9574
|
+
constructor(client) {
|
|
9575
|
+
this.client = client;
|
|
9576
|
+
}
|
|
9577
|
+
client;
|
|
9578
|
+
async search(params) {
|
|
9579
|
+
this.client._requireAuth();
|
|
9580
|
+
const rawSymbol = isRecord(params) ? params.symbol : void 0;
|
|
9581
|
+
const query = typeof rawSymbol === "string" ? rawSymbol.trim() : "";
|
|
9582
|
+
if (!query)
|
|
9583
|
+
throw new AlvaError("INVALID_ARGUMENT", "symbol is required", 400);
|
|
9584
|
+
const response = await this.client._request(
|
|
9585
|
+
"GET",
|
|
9586
|
+
"/api/v1/trading-pairs/search",
|
|
9587
|
+
{ query: { q: query, strict: true } }
|
|
9588
|
+
);
|
|
9589
|
+
const candidates = dedupe(flattenResponse(response)).filter((candidate) => matchesQuery(candidate, query)).filter((candidate) => matchesFilter(candidate.market, params.market)).filter(
|
|
9590
|
+
(candidate) => matchesFilter(candidate.instrumentType, params.instrumentType)
|
|
9591
|
+
).filter(
|
|
9592
|
+
(candidate) => matchesFilter(candidate.underlyingType, params.underlyingType)
|
|
9593
|
+
).filter((candidate) => matchesFilter(candidate.quote, params.quote));
|
|
9594
|
+
const limit = params.limit;
|
|
9595
|
+
if (limit !== void 0 && candidates.length > limit) {
|
|
9596
|
+
return { query, candidates: candidates.slice(0, limit), truncated: true };
|
|
9597
|
+
}
|
|
9598
|
+
return { query, candidates };
|
|
9599
|
+
}
|
|
9600
|
+
async resolve(params) {
|
|
9601
|
+
const record = isRecord(params) ? params : {};
|
|
9602
|
+
const pair = typeof record.pair === "string" ? record.pair.trim() : void 0;
|
|
9603
|
+
const filters = resolveFilters(params);
|
|
9604
|
+
const searchParams = pair === void 0 ? {
|
|
9605
|
+
symbol: typeof record.symbol === "string" ? record.symbol : "",
|
|
9606
|
+
...filters
|
|
9607
|
+
} : pairSearchParams(pair, filters);
|
|
9608
|
+
const result = await this.search(searchParams);
|
|
9609
|
+
const candidates = pair === void 0 ? result.candidates : result.candidates.filter(
|
|
9610
|
+
(candidate) => candidate.tradingPair === pair
|
|
9611
|
+
);
|
|
9612
|
+
if (candidates.length !== 1) {
|
|
9613
|
+
const detailLimit = 50;
|
|
9614
|
+
throw new AlvaError(
|
|
9615
|
+
candidates.length === 0 ? "TRADING_PAIR_NOT_FOUND" : "TRADING_PAIR_NOT_UNIQUE",
|
|
9616
|
+
candidates.length === 0 ? `no canonical trading pair matched "${pair ?? searchParams.symbol}"` : `multiple canonical trading pairs matched "${searchParams.symbol}"`,
|
|
9617
|
+
candidates.length === 0 ? 404 : 409,
|
|
9618
|
+
{
|
|
9619
|
+
query: pair ?? searchParams.symbol,
|
|
9620
|
+
candidateCount: candidates.length,
|
|
9621
|
+
candidates: candidates.slice(0, detailLimit),
|
|
9622
|
+
...candidates.length > detailLimit ? { truncated: true } : {}
|
|
9623
|
+
}
|
|
9624
|
+
);
|
|
9625
|
+
}
|
|
9626
|
+
return candidates[0];
|
|
9627
|
+
}
|
|
9628
|
+
};
|
|
9629
|
+
|
|
9445
9630
|
// src/client.ts
|
|
9446
9631
|
var DEFAULT_BASE_URL = "https://api-llm.prd.alva.ai";
|
|
9447
9632
|
var DEFAULT_ARRAYS_BASE_URL = "https://data-tools.prd.space.id";
|
|
9448
|
-
function
|
|
9633
|
+
function isRecord2(value) {
|
|
9449
9634
|
return typeof value === "object" && value !== null;
|
|
9450
9635
|
}
|
|
9451
9636
|
function stringField(value, field) {
|
|
9452
|
-
if (!
|
|
9637
|
+
if (!isRecord2(value)) return void 0;
|
|
9453
9638
|
const fieldValue = value[field];
|
|
9454
9639
|
return typeof fieldValue === "string" && fieldValue ? fieldValue : void 0;
|
|
9455
9640
|
}
|
|
@@ -9463,7 +9648,7 @@ function describeCause(cause) {
|
|
|
9463
9648
|
if (cause.message) details.message = cause.message;
|
|
9464
9649
|
const code = stringField(cause, "code");
|
|
9465
9650
|
if (code) details.code = code;
|
|
9466
|
-
} else if (
|
|
9651
|
+
} else if (isRecord2(cause)) {
|
|
9467
9652
|
const code = stringField(cause, "code");
|
|
9468
9653
|
const name = stringField(cause, "name");
|
|
9469
9654
|
const message = stringField(cause, "message");
|
|
@@ -9491,7 +9676,7 @@ function describeFetchFailure(err) {
|
|
|
9491
9676
|
details.message = String(err);
|
|
9492
9677
|
}
|
|
9493
9678
|
const { message: causeMessage, details: causeDetails } = describeCause(
|
|
9494
|
-
|
|
9679
|
+
isRecord2(err) ? err.cause : void 0
|
|
9495
9680
|
);
|
|
9496
9681
|
if (causeDetails) {
|
|
9497
9682
|
details.cause = causeDetails;
|
|
@@ -9551,6 +9736,7 @@ var AlvaClient = class {
|
|
|
9551
9736
|
_credits;
|
|
9552
9737
|
_markets;
|
|
9553
9738
|
_schedules;
|
|
9739
|
+
_tradingPairs;
|
|
9554
9740
|
constructor(config) {
|
|
9555
9741
|
this.baseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
|
|
9556
9742
|
this.arraysBaseUrl = config.arraysBaseUrl ?? DEFAULT_ARRAYS_BASE_URL;
|
|
@@ -9648,6 +9834,9 @@ var AlvaClient = class {
|
|
|
9648
9834
|
get markets() {
|
|
9649
9835
|
return this._markets ??= new MarketsResource(this);
|
|
9650
9836
|
}
|
|
9837
|
+
get tradingPairs() {
|
|
9838
|
+
return this._tradingPairs ??= new TradingPairsResource(this);
|
|
9839
|
+
}
|
|
9651
9840
|
get schedules() {
|
|
9652
9841
|
return this._schedules ??= new SchedulesResource(this);
|
|
9653
9842
|
}
|
|
@@ -10030,7 +10219,8 @@ var COMMAND_DEFINITIONS = [
|
|
|
10030
10219
|
"args",
|
|
10031
10220
|
"max-heap-size-mb",
|
|
10032
10221
|
"timeout-ms"
|
|
10033
|
-
]
|
|
10222
|
+
],
|
|
10223
|
+
booleans: ["args-stdin"]
|
|
10034
10224
|
}),
|
|
10035
10225
|
command("deploy create", {
|
|
10036
10226
|
values: [
|
|
@@ -10376,6 +10566,28 @@ var COMMAND_DEFINITIONS = [
|
|
|
10376
10566
|
command("markets earnings", {
|
|
10377
10567
|
values: ["ticker", "event", "fiscal-year", "fiscal-quarter"]
|
|
10378
10568
|
}),
|
|
10569
|
+
command("trading-pairs search", {
|
|
10570
|
+
values: [
|
|
10571
|
+
"symbol",
|
|
10572
|
+
"market",
|
|
10573
|
+
"instrument-type",
|
|
10574
|
+
"underlying-type",
|
|
10575
|
+
"quote",
|
|
10576
|
+
"limit"
|
|
10577
|
+
],
|
|
10578
|
+
booleans: ["json"]
|
|
10579
|
+
}),
|
|
10580
|
+
command("trading-pairs resolve", {
|
|
10581
|
+
values: [
|
|
10582
|
+
"pair",
|
|
10583
|
+
"symbol",
|
|
10584
|
+
"market",
|
|
10585
|
+
"instrument-type",
|
|
10586
|
+
"underlying-type",
|
|
10587
|
+
"quote"
|
|
10588
|
+
],
|
|
10589
|
+
booleans: ["json"]
|
|
10590
|
+
}),
|
|
10379
10591
|
command("trading accounts"),
|
|
10380
10592
|
command("trading portfolio", { values: ["account-id"] }),
|
|
10381
10593
|
command("trading orders", {
|
|
@@ -10472,6 +10684,28 @@ function closestFlag(input, available) {
|
|
|
10472
10684
|
const threshold = input.length <= 4 ? 1 : 2;
|
|
10473
10685
|
return distance <= threshold ? closest : void 0;
|
|
10474
10686
|
}
|
|
10687
|
+
var TOP_LEVEL_COMMAND_SUGGESTIONS = {
|
|
10688
|
+
market: "markets",
|
|
10689
|
+
data: "data-skills",
|
|
10690
|
+
feeds: "automation"
|
|
10691
|
+
};
|
|
10692
|
+
function closestCommand(input, available) {
|
|
10693
|
+
const terminology = TOP_LEVEL_COMMAND_SUGGESTIONS[input];
|
|
10694
|
+
if (terminology !== void 0 && available.has(terminology)) {
|
|
10695
|
+
return terminology;
|
|
10696
|
+
}
|
|
10697
|
+
let closest;
|
|
10698
|
+
let distance = Number.POSITIVE_INFINITY;
|
|
10699
|
+
for (const candidate of available.keys()) {
|
|
10700
|
+
const candidateDistance = editDistance(input, candidate);
|
|
10701
|
+
if (candidateDistance < distance) {
|
|
10702
|
+
closest = candidate;
|
|
10703
|
+
distance = candidateDistance;
|
|
10704
|
+
}
|
|
10705
|
+
}
|
|
10706
|
+
const threshold = input.length <= 4 ? 1 : 2;
|
|
10707
|
+
return distance <= threshold ? closest : void 0;
|
|
10708
|
+
}
|
|
10475
10709
|
function mergeFlags(definition, globalFlags) {
|
|
10476
10710
|
return { ...globalFlags, ...definition.flags };
|
|
10477
10711
|
}
|
|
@@ -10489,7 +10723,9 @@ function resolveCommand(args, tree) {
|
|
|
10489
10723
|
}
|
|
10490
10724
|
if (node.definition !== void 0 && node.children.size === 0) break;
|
|
10491
10725
|
if (consumed === 0) {
|
|
10492
|
-
|
|
10726
|
+
const suggestion = closestCommand(input, node.children);
|
|
10727
|
+
const recovery = suggestion === void 0 ? " Run 'alva --help' to list command families." : ` Did you mean '${suggestion}'?`;
|
|
10728
|
+
throw new CliUsageError(`Unknown command: '${input}'.${recovery}`);
|
|
10493
10729
|
}
|
|
10494
10730
|
const group2 = args[0];
|
|
10495
10731
|
const command2 = args.slice(0, consumed).join(" ");
|
|
@@ -14670,8 +14906,41 @@ ${formatReport(report, "human")}
|
|
|
14670
14906
|
return report;
|
|
14671
14907
|
}
|
|
14672
14908
|
|
|
14909
|
+
// src/cli/tradingPairsFormat.ts
|
|
14910
|
+
function candidateLine(candidate) {
|
|
14911
|
+
const metadata = [
|
|
14912
|
+
`market=${candidate.market}`,
|
|
14913
|
+
`instrument=${candidate.instrumentType}`,
|
|
14914
|
+
candidate.underlyingType === void 0 ? void 0 : `underlying=${candidate.underlyingType}`,
|
|
14915
|
+
`quote=${candidate.quote}`
|
|
14916
|
+
].filter((value) => value !== void 0);
|
|
14917
|
+
return `${candidate.tradingPair} (${metadata.join(" ")})`;
|
|
14918
|
+
}
|
|
14919
|
+
function formatTradingPairSearch(result) {
|
|
14920
|
+
if (result.candidates.length === 0) {
|
|
14921
|
+
return `No trading pairs found for "${result.query}".`;
|
|
14922
|
+
}
|
|
14923
|
+
const lines = result.candidates.map(candidateLine);
|
|
14924
|
+
if (result.truncated === true) {
|
|
14925
|
+
lines.push(
|
|
14926
|
+
`... results truncated at ${result.candidates.length} candidates`
|
|
14927
|
+
);
|
|
14928
|
+
}
|
|
14929
|
+
return lines.join("\n");
|
|
14930
|
+
}
|
|
14931
|
+
function formatTradingPairResolved(result) {
|
|
14932
|
+
return [
|
|
14933
|
+
result.tradingPair,
|
|
14934
|
+
`symbol=${result.symbol}`,
|
|
14935
|
+
`market=${result.market}`,
|
|
14936
|
+
`instrument=${result.instrumentType}`,
|
|
14937
|
+
...result.underlyingType === void 0 ? [] : [`underlying=${result.underlyingType}`],
|
|
14938
|
+
`quote=${result.quote}`
|
|
14939
|
+
].join("\n");
|
|
14940
|
+
}
|
|
14941
|
+
|
|
14673
14942
|
// src/cli/dispatch.ts
|
|
14674
|
-
var CLI_VERSION = true ? "0.
|
|
14943
|
+
var CLI_VERSION = true ? "0.27.0" : "dev";
|
|
14675
14944
|
var DEFAULT_RUN_TIMEOUT_MS = 6e5;
|
|
14676
14945
|
var RUN_TIMEOUT_ENV = "ALVA_RUN_TIMEOUT_MS";
|
|
14677
14946
|
var GLOBAL_VALUE_FLAGS = Object.entries(GLOBAL_FLAG_DEFINITIONS).filter(([, kind]) => kind === "value").map(([name]) => `--${name}`);
|
|
@@ -14735,6 +15004,7 @@ Commands:
|
|
|
14735
15004
|
remix Save playbook remix lineage
|
|
14736
15005
|
portfolio Connected-account portfolio (accounts, summary, activities)
|
|
14737
15006
|
markets Company narrative and earnings context (narrative, earnings)
|
|
15007
|
+
trading-pairs Discover and strictly verify canonical trading pairs (search, resolve)
|
|
14738
15008
|
trading Trading operations (accounts, portfolio, orders, subscriptions, equity-history, risk-rules, subscribe, unsubscribe, execute, update-risk-rules)
|
|
14739
15009
|
broker Agentic order execution \u2014 venue-native passthrough to trex (accounts, quote, order, balance, positions, ...; run 'alva broker describe')
|
|
14740
15010
|
auth Authentication (login)
|
|
@@ -14953,6 +15223,7 @@ Options:
|
|
|
14953
15223
|
--entry-path <path> Path to a script file on ALFS (home-relative)
|
|
14954
15224
|
--working-dir <dir> Working directory for require() (inline code only)
|
|
14955
15225
|
--args <json> JSON object passed to require("env").args
|
|
15226
|
+
--args-stdin Read the JSON object from stdin (mutually exclusive with --args)
|
|
14956
15227
|
--max-heap-size-mb <mb> Override the V8 heap limit in MB (1-2048, default 256)
|
|
14957
15228
|
--timeout-ms <ms> Client HTTP timeout for /api/v1/run (default: ${DEFAULT_RUN_TIMEOUT_MS}; env: ${RUN_TIMEOUT_ENV})
|
|
14958
15229
|
|
|
@@ -14986,6 +15257,7 @@ Examples:
|
|
|
14986
15257
|
alva run --entry-path "~/feeds/my-feed/v1/src/index.js"
|
|
14987
15258
|
alva run --entry-path "~/tasks/analyze/src/index.js" --args '{"symbol":"NVDA","limit":50}'
|
|
14988
15259
|
alva run --local-file ./my-script.js --args '{"symbol":"BTC"}'
|
|
15260
|
+
printf '%s' '{"symbol":"BTC"}' | alva run --local-file ./my-script.js --args-stdin
|
|
14989
15261
|
alva run --entry-path "~/tasks/heavy/src/index.js" --max-heap-size-mb 1024
|
|
14990
15262
|
alva run --entry-path "~/feeds/slow/v1/src/index.js" --timeout-ms 900000`,
|
|
14991
15263
|
deploy: `Usage: alva deploy <subcommand> [options]
|
|
@@ -15874,6 +16146,34 @@ Examples:
|
|
|
15874
16146
|
alva markets earnings --ticker AAPL
|
|
15875
16147
|
alva markets earnings --ticker AAPL --event next-confirmed
|
|
15876
16148
|
alva markets earnings --ticker AAPL --fiscal-year 2026 --fiscal-quarter Q3`,
|
|
16149
|
+
"trading-pairs": `Usage: alva trading-pairs <subcommand> [options]
|
|
16150
|
+
|
|
16151
|
+
Discover canonical trading-pair identities before backtesting or trading.
|
|
16152
|
+
The returned tradingPair is the exact value to use in OHLCV, Altra targets,
|
|
16153
|
+
positions, and orders. This command never constructs aliases or picks the
|
|
16154
|
+
first result.
|
|
16155
|
+
|
|
16156
|
+
Subcommands:
|
|
16157
|
+
search Return all matching candidates; multiple results are normal
|
|
16158
|
+
resolve Require exactly one matching canonical tradingPair
|
|
16159
|
+
|
|
16160
|
+
Search and resolve flags:
|
|
16161
|
+
--symbol <ticker> Underlying ticker/query (for example RKLB)
|
|
16162
|
+
--market <market> Venue/market filter (for example US, BINANCE)
|
|
16163
|
+
--instrument-type <type> spot, perp, option, ...
|
|
16164
|
+
--underlying-type <type> stock, crypto, ...
|
|
16165
|
+
--quote <currency> USD, USDT, USDC, ...
|
|
16166
|
+
--json Return the machine-readable result
|
|
16167
|
+
|
|
16168
|
+
Search-only flags:
|
|
16169
|
+
--limit <n> Limit returned candidates; truncation is reported
|
|
16170
|
+
|
|
16171
|
+
Resolve forms:
|
|
16172
|
+
alva trading-pairs resolve --pair US_SPOT_RKLB_USD --json
|
|
16173
|
+
alva trading-pairs resolve --symbol RKLB --market US --instrument-type spot --quote USD --json
|
|
16174
|
+
|
|
16175
|
+
Resolve fails when zero or multiple distinct pairs remain. Existing holdings
|
|
16176
|
+
must keep their stored full tradingPair instead of being resolved again.`,
|
|
15877
16177
|
trading: `Usage: alva trading <subcommand> [options]
|
|
15878
16178
|
|
|
15879
16179
|
Manage trading accounts, portfolios, orders, subscriptions, and risk rules.
|
|
@@ -15987,13 +16287,13 @@ function boolFlag(val) {
|
|
|
15987
16287
|
if (val === "false") return false;
|
|
15988
16288
|
return void 0;
|
|
15989
16289
|
}
|
|
15990
|
-
function serializedJSONFlag(value, command2) {
|
|
16290
|
+
function serializedJSONFlag(value, command2, flag = "--args") {
|
|
15991
16291
|
if (value === void 0) return void 0;
|
|
15992
16292
|
try {
|
|
15993
16293
|
validateSerializedArgs(value);
|
|
15994
16294
|
} catch (error) {
|
|
15995
16295
|
throw new CliUsageError(
|
|
15996
|
-
|
|
16296
|
+
`${flag} must contain valid JSON for '${command2}': ${error instanceof Error ? error.message : String(error)}`,
|
|
15997
16297
|
command2.split(" ")[0]
|
|
15998
16298
|
);
|
|
15999
16299
|
}
|
|
@@ -16860,7 +17160,30 @@ async function executeParsedCommand(client, parsedCommand, meta, deps) {
|
|
|
16860
17160
|
),
|
|
16861
17161
|
timeout_ms
|
|
16862
17162
|
};
|
|
16863
|
-
const
|
|
17163
|
+
const argsFromStdin = boolFlag(flags["args-stdin"]) === true;
|
|
17164
|
+
if (argsFromStdin && flags["args"] !== void 0) {
|
|
17165
|
+
throw new CliUsageError(
|
|
17166
|
+
"--args and --args-stdin are mutually exclusive",
|
|
17167
|
+
"run"
|
|
17168
|
+
);
|
|
17169
|
+
}
|
|
17170
|
+
let serializedArgs = serializedJSONFlag(flags["args"], "run");
|
|
17171
|
+
if (argsFromStdin) {
|
|
17172
|
+
if (!deps?.readStdin) {
|
|
17173
|
+
throw new CliUsageError(
|
|
17174
|
+
"--args-stdin requires a Node.js runtime adapter",
|
|
17175
|
+
"run"
|
|
17176
|
+
);
|
|
17177
|
+
}
|
|
17178
|
+
const stdin = await deps.readStdin();
|
|
17179
|
+
serializedArgs = serializedJSONFlag(stdin, "run", "--args-stdin");
|
|
17180
|
+
if (serializedArgs === void 0) {
|
|
17181
|
+
throw new CliUsageError(
|
|
17182
|
+
"--args-stdin requires JSON input from stdin",
|
|
17183
|
+
"run"
|
|
17184
|
+
);
|
|
17185
|
+
}
|
|
17186
|
+
}
|
|
16864
17187
|
return serializedArgs === void 0 ? client.run.execute(params) : client.run._executeSerializedArgs(params, serializedArgs);
|
|
16865
17188
|
}
|
|
16866
17189
|
case "deploy": {
|
|
@@ -18186,6 +18509,61 @@ async function executeParsedCommand(client, parsedCommand, meta, deps) {
|
|
|
18186
18509
|
);
|
|
18187
18510
|
}
|
|
18188
18511
|
}
|
|
18512
|
+
case "trading-pairs": {
|
|
18513
|
+
if (!subcommand) {
|
|
18514
|
+
throw new CliUsageError(
|
|
18515
|
+
"Missing subcommand for trading-pairs",
|
|
18516
|
+
"trading-pairs"
|
|
18517
|
+
);
|
|
18518
|
+
}
|
|
18519
|
+
const asJson = boolFlag(flags["json"]) ?? false;
|
|
18520
|
+
const filters = {
|
|
18521
|
+
market: flags["market"],
|
|
18522
|
+
instrumentType: flags["instrument-type"],
|
|
18523
|
+
underlyingType: flags["underlying-type"],
|
|
18524
|
+
quote: flags["quote"]
|
|
18525
|
+
};
|
|
18526
|
+
switch (subcommand) {
|
|
18527
|
+
case "search": {
|
|
18528
|
+
const limit = flags["limit"] === void 0 ? void 0 : requirePositiveIntegerFlag(
|
|
18529
|
+
flags,
|
|
18530
|
+
"limit",
|
|
18531
|
+
"trading-pairs search"
|
|
18532
|
+
);
|
|
18533
|
+
const result = await client.tradingPairs.search({
|
|
18534
|
+
symbol: requireFlag(flags, "symbol", "trading-pairs search"),
|
|
18535
|
+
...filters,
|
|
18536
|
+
limit
|
|
18537
|
+
});
|
|
18538
|
+
return asJson ? result : formatTradingPairSearch(result);
|
|
18539
|
+
}
|
|
18540
|
+
case "resolve": {
|
|
18541
|
+
const pair = flags["pair"];
|
|
18542
|
+
const symbol = flags["symbol"];
|
|
18543
|
+
if (pair !== void 0 && symbol !== void 0) {
|
|
18544
|
+
throw new CliUsageError(
|
|
18545
|
+
"'trading-pairs resolve' accepts either --pair or --symbol, not both",
|
|
18546
|
+
"trading-pairs"
|
|
18547
|
+
);
|
|
18548
|
+
}
|
|
18549
|
+
if (pair === void 0 && symbol === void 0) {
|
|
18550
|
+
throw new CliUsageError(
|
|
18551
|
+
"'trading-pairs resolve' requires --pair or --symbol",
|
|
18552
|
+
"trading-pairs"
|
|
18553
|
+
);
|
|
18554
|
+
}
|
|
18555
|
+
const result = await client.tradingPairs.resolve(
|
|
18556
|
+
pair !== void 0 ? { pair, ...filters } : { symbol, ...filters }
|
|
18557
|
+
);
|
|
18558
|
+
return asJson ? result : formatTradingPairResolved(result);
|
|
18559
|
+
}
|
|
18560
|
+
default:
|
|
18561
|
+
throw new CliUsageError(
|
|
18562
|
+
`Unknown subcommand: trading-pairs ${subcommand}`,
|
|
18563
|
+
"trading-pairs"
|
|
18564
|
+
);
|
|
18565
|
+
}
|
|
18566
|
+
}
|
|
18189
18567
|
case "trading": {
|
|
18190
18568
|
if (!subcommand)
|
|
18191
18569
|
throw new CliUsageError("Missing subcommand for trading", "trading");
|