@livefolio/sdk 0.4.1 → 0.4.2

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.ts CHANGED
@@ -577,6 +577,11 @@ type PriceMap = ReadonlyMap<AssetId, number>;
577
577
  * value and existing share counts.
578
578
  * @param prices - Current prices for all assets that appear in `targets` or are
579
579
  * currently held. Throws `Error` if a target asset is missing from this map.
580
+ * @param assets - Optional canonical {@link Asset} metadata keyed by id. When
581
+ * `reconcile` needs to emit an order for an asset that is not yet held in the
582
+ * portfolio, it consults this map for the proper `symbol`/`kind`. If the
583
+ * asset is missing here too, the order falls back to a synthesized
584
+ * `{ kind: 'equity', id, symbol: id }` — lossless but display-unfriendly.
580
585
  * @returns A readonly array of `RebalanceOrder` objects. The array may be empty
581
586
  * if the portfolio is already at the target allocation. Order IDs are
582
587
  * deterministic within a single call (`rebal_<assetId>_<counter>`).
@@ -603,7 +608,7 @@ type PriceMap = ReadonlyMap<AssetId, number>;
603
608
  * // ]
604
609
  * ```
605
610
  */
606
- declare function reconcile(targets: TargetWeights, portfolio: Portfolio, prices: PriceMap): ReadonlyArray<RebalanceOrder>;
611
+ declare function reconcile(targets: TargetWeights, portfolio: Portfolio, prices: PriceMap, assets?: ReadonlyMap<AssetId, Asset>): ReadonlyArray<RebalanceOrder>;
607
612
 
608
613
  /**
609
614
  * A flat record of fundamental data points for an asset at a point in time.
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // src/strategy/reconcile.ts
8
- function reconcile(targets, portfolio, prices) {
8
+ function reconcile(targets, portfolio, prices, assets) {
9
9
  const longByAsset = /* @__PURE__ */ new Map();
10
10
  for (const p of portfolio.positions) {
11
11
  if (p.side !== "long") continue;
@@ -33,10 +33,10 @@ function reconcile(targets, portfolio, prices) {
33
33
  const delta = targetShares - currentShares;
34
34
  seen.add(assetId);
35
35
  if (delta !== 0) {
36
- const asset = held?.asset ?? {
36
+ const asset = held?.asset ?? assets?.get(assetId) ?? {
37
37
  kind: "equity",
38
38
  id: assetId,
39
- symbol: assetId.split(":").pop() ?? assetId
39
+ symbol: assetId
40
40
  };
41
41
  orders.push({ id: nextId(assetId), kind: "rebalance", asset, delta });
42
42
  }
@@ -2890,6 +2890,13 @@ function fromSpec(spec, opts) {
2890
2890
  }
2891
2891
  validateSynthetics(spec);
2892
2892
  const universe = spec.universe.map(resolveAssetRef);
2893
+ const assetsById = /* @__PURE__ */ new Map();
2894
+ for (const a of universe) assetsById.set(a.id, a);
2895
+ for (const s of spec.synthetics ?? []) {
2896
+ if (!assetsById.has(s.id)) {
2897
+ assetsById.set(s.id, { kind: "equity", id: s.id, symbol: s.symbol });
2898
+ }
2899
+ }
2893
2900
  const { runtime, calendar } = opts;
2894
2901
  const cadence = spec.rebalance?.frequency ?? "Daily";
2895
2902
  return {
@@ -2934,7 +2941,7 @@ function fromSpec(spec, opts) {
2934
2941
  }
2935
2942
  }
2936
2943
  return {
2937
- orders: reconcile(evaluated.weights, portfolio, features.prices),
2944
+ orders: reconcile(evaluated.weights, portfolio, features.prices, assetsById),
2938
2945
  state: evaluated.state
2939
2946
  };
2940
2947
  }