tradeblocks-mcp 3.10.0 → 3.10.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.
Files changed (53) hide show
  1. package/dist/{chunk-SX2RJIMS.js → chunk-COSLRCST.js} +80 -4
  2. package/dist/chunk-COSLRCST.js.map +1 -0
  3. package/dist/{chunk-MOSBMO6W.js → chunk-TZRDK5VL.js} +165 -40
  4. package/dist/chunk-TZRDK5VL.js.map +1 -0
  5. package/dist/{chunk-B22R7HMR.js → chunk-XANRFYQT.js} +44 -32
  6. package/dist/chunk-XANRFYQT.js.map +1 -0
  7. package/dist/market/provenance/index.js +55 -36
  8. package/dist/market/provenance/index.js.map +1 -1
  9. package/dist/{market-provider-PZIUP462.js → market-provider-FWKON2ZG.js} +3 -3
  10. package/dist/{sync-PKN7FRBZ.js → sync-DVSXIIUZ.js} +3 -3
  11. package/dist/test-exports.js +345 -226
  12. package/dist/test-exports.js.map +1 -1
  13. package/package.json +5 -5
  14. package/server/{chunk-BFXJCMA2.js → chunk-GKB4EQFU.js} +158 -40
  15. package/server/chunk-GKB4EQFU.js.map +1 -0
  16. package/server/{chunk-LNAAA74R.js → chunk-I6FEESXT.js} +44 -32
  17. package/server/chunk-I6FEESXT.js.map +1 -0
  18. package/server/{chunk-WFWYMFY5.js → chunk-RY37QPQJ.js} +80 -4
  19. package/server/chunk-RY37QPQJ.js.map +1 -0
  20. package/server/index.js +341 -229
  21. package/server/index.js.map +1 -1
  22. package/server/{market-provider-AR7OVVUK.js → market-provider-I6JMSBIK.js} +3 -3
  23. package/server/{sync-FNVNZR6P.js → sync-MW333YEK.js} +3 -3
  24. package/src/db/connection.ts +374 -51
  25. package/src/db/index.ts +4 -0
  26. package/src/db/market-datasets.ts +1 -2
  27. package/src/db/parquet-writer.ts +11 -1
  28. package/src/index.ts +7 -2
  29. package/src/market/provenance/content-manifest.ts +2 -7
  30. package/src/market/provenance/dataset-registry.ts +1 -2
  31. package/src/market/provenance/partition-commit-attempt.ts +1 -2
  32. package/src/market/provenance/partition-commit-store.ts +22 -10
  33. package/src/test-exports.ts +6 -0
  34. package/src/tools/batch-exit-analysis.ts +10 -4
  35. package/src/tools/exit-analysis.ts +10 -4
  36. package/src/tools/middleware/connection-lease.ts +73 -0
  37. package/src/utils/exit-triggers.ts +71 -13
  38. package/src/utils/field-timing.ts +125 -29
  39. package/src/utils/greeks-decomposition.ts +1 -8
  40. package/src/utils/market-enricher.ts +86 -2
  41. package/src/utils/money.ts +94 -36
  42. package/src/utils/providers/thetadata/backfill.ts +1 -4
  43. package/src/utils/trade-replay.ts +8 -2
  44. package/dist/chunk-B22R7HMR.js.map +0 -1
  45. package/dist/chunk-MOSBMO6W.js.map +0 -1
  46. package/dist/chunk-SX2RJIMS.js.map +0 -1
  47. package/server/chunk-BFXJCMA2.js.map +0 -1
  48. package/server/chunk-LNAAA74R.js.map +0 -1
  49. package/server/chunk-WFWYMFY5.js.map +0 -1
  50. /package/dist/{market-provider-PZIUP462.js.map → market-provider-FWKON2ZG.js.map} +0 -0
  51. /package/dist/{sync-PKN7FRBZ.js.map → sync-DVSXIIUZ.js.map} +0 -0
  52. /package/server/{market-provider-AR7OVVUK.js.map → market-provider-I6JMSBIK.js.map} +0 -0
  53. /package/server/{sync-FNVNZR6P.js.map → sync-MW333YEK.js.map} +0 -0
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  ALL_GREEKS,
3
3
  getSofrRateByKey
4
- } from "./chunk-B22R7HMR.js";
4
+ } from "./chunk-XANRFYQT.js";
5
5
  import {
6
6
  loadMddsProtoRoot
7
7
  } from "./chunk-2E63THNI.js";
@@ -983,6 +983,70 @@ var MassiveProvider = class {
983
983
  }
984
984
  };
985
985
 
986
+ // src/utils/money.ts
987
+ var SCALE = 1e6;
988
+ var MONEY_MAX_DOLLARS = Math.floor(Number.MAX_SAFE_INTEGER / SCALE);
989
+ var MoneyDomainError = class extends Error {
990
+ };
991
+ function toMoneyField(amount, field) {
992
+ if (!Number.isFinite(amount)) {
993
+ throw new MoneyDomainError(`${field} must be a finite dollar amount`);
994
+ }
995
+ const scaled = Math.round(amount * SCALE);
996
+ if (!Number.isSafeInteger(scaled)) {
997
+ throw new MoneyDomainError(
998
+ `${field} is beyond the largest dollar amount this analysis can represent (about ${MONEY_MAX_DOLLARS.toLocaleString("en-US")})`
999
+ );
1000
+ }
1001
+ return scaled === 0 ? 0 : scaled;
1002
+ }
1003
+ function checkedMoney(value, field) {
1004
+ if (!Number.isSafeInteger(value)) {
1005
+ throw new MoneyDomainError(`${field} is beyond the exact monetary range`);
1006
+ }
1007
+ return value === 0 ? 0 : value;
1008
+ }
1009
+ function addMoney(left, right, field) {
1010
+ return checkedMoney(left + right, field);
1011
+ }
1012
+ function legPnlMoney(markPrice2, entryPrice, quantity, multiplier) {
1013
+ const priceDifference = addMoney(
1014
+ toMoneyField(markPrice2, "mark price"),
1015
+ -toMoneyField(entryPrice, "entry price"),
1016
+ "price difference"
1017
+ );
1018
+ const scaled = priceDifference * quantity * multiplier;
1019
+ if (!Number.isFinite(scaled)) {
1020
+ throw new MoneyDomainError("leg P&L must be a finite dollar amount");
1021
+ }
1022
+ return Number.isSafeInteger(scaled) ? scaled === 0 ? 0 : scaled : toMoneyField(fromMoney(priceDifference) * quantity * multiplier, "leg P&L");
1023
+ }
1024
+ function applyRatioField(amount, ratio, field) {
1025
+ if (!Number.isFinite(ratio)) {
1026
+ throw new MoneyDomainError(`${field} must be a finite number`);
1027
+ }
1028
+ const scaled = Math.round(amount * ratio);
1029
+ if (!Number.isSafeInteger(scaled)) {
1030
+ throw new MoneyDomainError(
1031
+ `${field} is beyond the largest dollar amount this analysis can represent (about ${MONEY_MAX_DOLLARS.toLocaleString("en-US")})`
1032
+ );
1033
+ }
1034
+ return scaled === 0 ? 0 : scaled;
1035
+ }
1036
+ function thresholdFromEntryCost(entryCost, ratio, field) {
1037
+ return applyRatioField(entryCost, ratio, field);
1038
+ }
1039
+ function fromMoney(value) {
1040
+ return value / SCALE;
1041
+ }
1042
+ function moneyAtLeast(amount, threshold) {
1043
+ return amount >= threshold;
1044
+ }
1045
+ function formatMoney(value) {
1046
+ if (value % 1e4 === 0) return (value / SCALE).toFixed(2);
1047
+ return (value / SCALE).toFixed(6).replace(/(\.\d\d[0-9]*?)0+$/, "$1");
1048
+ }
1049
+
986
1050
  // src/utils/trade-replay.ts
987
1051
  function markPrice(bar) {
988
1052
  const { bid, ask } = bar;
@@ -1143,7 +1207,7 @@ function computeStrategyPnlPath(legs, barsByLeg, greeksConfig) {
1143
1207
  for (const ts of sortedTimestamps) {
1144
1208
  let complete = true;
1145
1209
  const legPrices = [];
1146
- let strategyPnl = 0;
1210
+ let strategyPnlMoney = 0;
1147
1211
  for (let i = 0; i < legs.length; i++) {
1148
1212
  const bar = legMaps[i].get(ts);
1149
1213
  if (bar) {
@@ -1156,9 +1220,14 @@ function computeStrategyPnlPath(legs, barsByLeg, greeksConfig) {
1156
1220
  }
1157
1221
  const hl2 = markPrice(effective);
1158
1222
  legPrices.push(hl2);
1159
- strategyPnl += (hl2 - legs[i].entryPrice) * legs[i].quantity * legs[i].multiplier;
1223
+ strategyPnlMoney = addMoney(
1224
+ strategyPnlMoney,
1225
+ legPnlMoney(hl2, legs[i].entryPrice, legs[i].quantity, legs[i].multiplier),
1226
+ "strategy P&L"
1227
+ );
1160
1228
  }
1161
1229
  if (complete) {
1230
+ const strategyPnl = fromMoney(strategyPnlMoney);
1162
1231
  const point = { timestamp: ts, strategyPnl, legPrices };
1163
1232
  if (greeksConfig) {
1164
1233
  let underlyingPrice = greeksConfig.underlyingPrices.get(ts);
@@ -3251,6 +3320,13 @@ export {
3251
3320
  massiveTimestampToETTime,
3252
3321
  nanosToETMinuteKey,
3253
3322
  MassiveProvider,
3323
+ toMoneyField,
3324
+ addMoney,
3325
+ legPnlMoney,
3326
+ thresholdFromEntryCost,
3327
+ fromMoney,
3328
+ moneyAtLeast,
3329
+ formatMoney,
3254
3330
  markPrice,
3255
3331
  findNearestTimestamp,
3256
3332
  parseLegsString,
@@ -3295,4 +3371,4 @@ export {
3295
3371
  getProvider,
3296
3372
  _resetProvider
3297
3373
  };
3298
- //# sourceMappingURL=chunk-SX2RJIMS.js.map
3374
+ //# sourceMappingURL=chunk-COSLRCST.js.map