tradeblocks-mcp 3.0.2 → 3.0.3

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 (214) hide show
  1. package/README.md +82 -68
  2. package/dist/{chunk-LDKTV7GW.js → chunk-27S67XW3.js} +24 -52
  3. package/dist/chunk-27S67XW3.js.map +1 -0
  4. package/dist/{chunk-FGZH632F.js → chunk-2E63THNI.js} +13 -11
  5. package/dist/chunk-2E63THNI.js.map +1 -0
  6. package/dist/{chunk-BKQ4PM4Y.js → chunk-6S37CXUA.js} +11 -13
  7. package/dist/chunk-6S37CXUA.js.map +1 -0
  8. package/dist/{chunk-PRAYH3RT.js → chunk-AP7IHUUR.js} +29 -12
  9. package/dist/chunk-AP7IHUUR.js.map +1 -0
  10. package/dist/{chunk-QTTR7AAW.js → chunk-C6LL746C.js} +67 -84
  11. package/dist/{chunk-QTTR7AAW.js.map → chunk-C6LL746C.js.map} +1 -1
  12. package/dist/{chunk-W2PP3LEH.js → chunk-SEUZYQGQ.js} +17 -8
  13. package/dist/chunk-SEUZYQGQ.js.map +1 -0
  14. package/dist/{chunk-4BLCXNQ6.js → chunk-UBUC5A66.js} +105 -114
  15. package/dist/chunk-UBUC5A66.js.map +1 -0
  16. package/dist/{chunk-XXYOUIZY.js → chunk-VDU25Z6X.js} +63 -80
  17. package/dist/chunk-VDU25Z6X.js.map +1 -0
  18. package/dist/daily-log-processor-BY3ISY6K.js +9 -0
  19. package/dist/{daily-logs-store-D3QC2XPV.js → daily-logs-store-3C3OTGPK.js} +2 -2
  20. package/dist/iv-solver-worker.js +9 -1
  21. package/dist/market-provider-H3ARIVZ4.js +16 -0
  22. package/dist/{proto-3HZTCWK4.js → proto-V23GIZG2.js} +2 -2
  23. package/dist/{sync-PO4IPCYV.js → sync-EVLKB3ZJ.js} +7 -7
  24. package/dist/test-exports.js +358 -254
  25. package/dist/test-exports.js.map +1 -1
  26. package/dist/trade-processor-EYA3I3XB.js +9 -0
  27. package/dist/{trades-store-LOL3FQSF.js → trades-store-R3NL25T2.js} +2 -2
  28. package/manifest.json +3 -11
  29. package/package.json +1 -1
  30. package/server/{chunk-NZO6PT64.js → chunk-4P7D7YZP.js} +102 -113
  31. package/server/chunk-4P7D7YZP.js.map +1 -0
  32. package/server/{chunk-72GKJE2U.js → chunk-BOPHW5M6.js} +521 -235
  33. package/server/chunk-BOPHW5M6.js.map +1 -0
  34. package/server/{chunk-WA5AAPCH.js → chunk-GH2552SE.js} +17 -8
  35. package/server/chunk-GH2552SE.js.map +1 -0
  36. package/server/{chunk-5EBXHT6C.js → chunk-OBYKFW2B.js} +11 -13
  37. package/server/chunk-OBYKFW2B.js.map +1 -0
  38. package/server/{chunk-FBNDMCT5.js → chunk-T66KH2XH.js} +13 -11
  39. package/server/chunk-T66KH2XH.js.map +1 -0
  40. package/server/{chunk-NRFXAJF7.js → chunk-W5E7FHC4.js} +24 -52
  41. package/server/chunk-W5E7FHC4.js.map +1 -0
  42. package/server/{chunk-CSDVJPBB.js → chunk-YUCOAJ4Z.js} +29 -12
  43. package/server/chunk-YUCOAJ4Z.js.map +1 -0
  44. package/server/{chunk-PNKG7RY7.js → chunk-ZBJCF4ZG.js} +63 -80
  45. package/server/chunk-ZBJCF4ZG.js.map +1 -0
  46. package/server/{config-6IZXEFEX.js → config-DK7KOMNL.js} +1 -1
  47. package/server/config-DK7KOMNL.js.map +1 -0
  48. package/server/daily-log-processor-ENEUT22A.js +10 -0
  49. package/server/{daily-logs-store-NU7M4L5C.js → daily-logs-store-YFNXTB7J.js} +2 -2
  50. package/server/http-server.js +2 -5
  51. package/server/index.js +1771 -1538
  52. package/server/index.js.map +1 -1
  53. package/server/iv-solver-worker.js +9 -1
  54. package/server/market-provider-B437HKLW.js +17 -0
  55. package/server/{proto-DWRZJO4E.js → proto-YZ4TLX2N.js} +2 -2
  56. package/server/{sync-QFI5L7S7.js → sync-V25UQJA3.js} +7 -7
  57. package/server/trade-processor-L3PIQ5TG.js +10 -0
  58. package/server/{trades-store-VY26MWER.js → trades-store-RTTEYMXH.js} +2 -2
  59. package/src/auth/clients-store.ts +4 -4
  60. package/src/auth/code-store.ts +1 -1
  61. package/src/auth/config.ts +11 -12
  62. package/src/auth/login-page.ts +8 -10
  63. package/src/auth/provider.ts +35 -30
  64. package/src/auth/token.ts +17 -15
  65. package/src/db/backtest-schemas.ts +12 -4
  66. package/src/db/connection.ts +107 -40
  67. package/src/db/index.ts +37 -5
  68. package/src/db/json-adapters.ts +22 -31
  69. package/src/db/json-migration.ts +11 -15
  70. package/src/db/json-store.ts +5 -3
  71. package/src/db/market-datasets.ts +48 -15
  72. package/src/db/market-schemas.ts +11 -5
  73. package/src/db/market-views.ts +119 -32
  74. package/src/db/parquet-writer.ts +7 -7
  75. package/src/db/profile-schemas.ts +39 -22
  76. package/src/db/schemas.ts +2 -2
  77. package/src/http-server.ts +7 -12
  78. package/src/index.ts +8 -9
  79. package/src/market/ingestor/index.ts +1 -4
  80. package/src/market/ingestor/market-ingestor.ts +140 -67
  81. package/src/market/ingestor/types.ts +1 -3
  82. package/src/market/stores/chain-sql.ts +2 -8
  83. package/src/market/stores/chain-store.ts +1 -4
  84. package/src/market/stores/duckdb-chain-store.ts +3 -14
  85. package/src/market/stores/duckdb-enriched-store.ts +3 -13
  86. package/src/market/stores/duckdb-quote-store.ts +10 -27
  87. package/src/market/stores/duckdb-spot-store.ts +4 -20
  88. package/src/market/stores/enriched-sql.ts +3 -9
  89. package/src/market/stores/enriched-store.ts +2 -2
  90. package/src/market/stores/parquet-chain-store.ts +5 -22
  91. package/src/market/stores/parquet-enriched-store.ts +4 -16
  92. package/src/market/stores/parquet-oi-daily-store.ts +3 -14
  93. package/src/market/stores/parquet-quote-store.ts +9 -29
  94. package/src/market/stores/parquet-spot-store.ts +14 -33
  95. package/src/market/stores/quote-store.ts +2 -10
  96. package/src/market/stores/spot-sql.ts +3 -15
  97. package/src/market/stores/spot-store.ts +1 -1
  98. package/src/market/tickers/defaults.json +6 -6
  99. package/src/market/tickers/loader.ts +2 -7
  100. package/src/market/tickers/registry.ts +5 -15
  101. package/src/market/tickers/schemas.ts +2 -6
  102. package/src/models/strategy-profile.ts +39 -39
  103. package/src/sync/block-sync.ts +44 -65
  104. package/src/sync/index.ts +1 -4
  105. package/src/sync/metadata.ts +14 -20
  106. package/src/test-exports.ts +127 -123
  107. package/src/tools/analysis.ts +180 -159
  108. package/src/tools/batch-exit-analysis.ts +100 -59
  109. package/src/tools/blocks/analysis.ts +116 -101
  110. package/src/tools/blocks/comparison.ts +281 -364
  111. package/src/tools/blocks/core.ts +208 -253
  112. package/src/tools/blocks/health.ts +571 -563
  113. package/src/tools/blocks/similarity.ts +316 -283
  114. package/src/tools/edge-decay.ts +124 -197
  115. package/src/tools/exit-analysis.ts +130 -77
  116. package/src/tools/greeks-attribution.ts +84 -35
  117. package/src/tools/guides.ts +4 -6
  118. package/src/tools/imports.ts +9 -12
  119. package/src/tools/market-data.ts +1067 -757
  120. package/src/tools/market-enrichment.ts +3 -3
  121. package/src/tools/market-fetch.ts +148 -67
  122. package/src/tools/market-imports.ts +12 -12
  123. package/src/tools/middleware/sync-middleware.ts +5 -6
  124. package/src/tools/performance.ts +185 -302
  125. package/src/tools/profile-analysis.ts +52 -66
  126. package/src/tools/profiles.ts +106 -69
  127. package/src/tools/regime-advisor.ts +20 -45
  128. package/src/tools/replay.ts +81 -77
  129. package/src/tools/reports/discrepancies.ts +298 -328
  130. package/src/tools/reports/fields.ts +7 -25
  131. package/src/tools/reports/helpers.ts +18 -49
  132. package/src/tools/reports/predictive.ts +27 -70
  133. package/src/tools/reports/slippage-trends.ts +315 -345
  134. package/src/tools/reports/slippage.ts +1 -4
  135. package/src/tools/reports/strategy-matches.ts +399 -441
  136. package/src/tools/schema.ts +43 -40
  137. package/src/tools/shared/filters.ts +3 -9
  138. package/src/tools/snapshot.ts +9 -30
  139. package/src/tools/sql.ts +15 -14
  140. package/src/tools/tickers.ts +1 -4
  141. package/src/utils/batch-exit-analysis.ts +31 -42
  142. package/src/utils/black-scholes.ts +39 -29
  143. package/src/utils/block-loader.ts +68 -82
  144. package/src/utils/calibration-probe.ts +1 -2
  145. package/src/utils/chain-loader.ts +3 -3
  146. package/src/utils/csv-discovery.ts +16 -22
  147. package/src/utils/data-quality.ts +24 -36
  148. package/src/utils/exit-triggers.ts +91 -96
  149. package/src/utils/field-timing.ts +94 -79
  150. package/src/utils/filter-predicates.ts +13 -9
  151. package/src/utils/flatfile-importer.ts +94 -64
  152. package/src/utils/greeks-decomposition.ts +152 -100
  153. package/src/utils/iv-solver-pool.ts +55 -25
  154. package/src/utils/iv-solver-worker.ts +5 -5
  155. package/src/utils/market-enricher.ts +528 -497
  156. package/src/utils/market-importer.ts +31 -12
  157. package/src/utils/market-provider.ts +21 -23
  158. package/src/utils/massive-tier.ts +5 -7
  159. package/src/utils/migrate-option-data-helpers.ts +2 -8
  160. package/src/utils/option-quote-greeks.ts +25 -31
  161. package/src/utils/option-time.ts +4 -8
  162. package/src/utils/output-formatter.ts +1 -4
  163. package/src/utils/provider-capabilities.ts +1 -4
  164. package/src/utils/providers/massive.ts +59 -93
  165. package/src/utils/providers/thetadata/backfill.ts +14 -23
  166. package/src/utils/providers/thetadata/client.ts +12 -8
  167. package/src/utils/providers/thetadata/decode.ts +2 -20
  168. package/src/utils/providers/thetadata/endpoints.ts +32 -40
  169. package/src/utils/providers/thetadata/join.ts +11 -10
  170. package/src/utils/providers/thetadata/proto.ts +12 -10
  171. package/src/utils/providers/thetadata/quote-mid-greeks.ts +5 -5
  172. package/src/utils/providers/thetadata.ts +11 -10
  173. package/src/utils/quote-enricher.ts +4 -4
  174. package/src/utils/quote-parquet-projection.ts +3 -11
  175. package/src/utils/sample-date-selector.ts +3 -5
  176. package/src/utils/schema-metadata.ts +102 -70
  177. package/src/utils/ticker.ts +5 -9
  178. package/src/utils/trade-replay.ts +77 -68
  179. package/dist/chunk-4BLCXNQ6.js.map +0 -1
  180. package/dist/chunk-BKQ4PM4Y.js.map +0 -1
  181. package/dist/chunk-FGZH632F.js.map +0 -1
  182. package/dist/chunk-LDKTV7GW.js.map +0 -1
  183. package/dist/chunk-PRAYH3RT.js.map +0 -1
  184. package/dist/chunk-W2PP3LEH.js.map +0 -1
  185. package/dist/chunk-XXYOUIZY.js.map +0 -1
  186. package/dist/daily-log-processor-6MWJ23JK.js +0 -9
  187. package/dist/market-provider-VDRJUEF2.js +0 -16
  188. package/dist/trade-processor-NHU4VWRX.js +0 -9
  189. package/server/chunk-5EBXHT6C.js.map +0 -1
  190. package/server/chunk-72GKJE2U.js.map +0 -1
  191. package/server/chunk-CSDVJPBB.js.map +0 -1
  192. package/server/chunk-FBNDMCT5.js.map +0 -1
  193. package/server/chunk-NRFXAJF7.js.map +0 -1
  194. package/server/chunk-NZO6PT64.js.map +0 -1
  195. package/server/chunk-PNKG7RY7.js.map +0 -1
  196. package/server/chunk-WA5AAPCH.js.map +0 -1
  197. package/server/config-6IZXEFEX.js.map +0 -1
  198. package/server/daily-log-processor-Y3PVSVBM.js +0 -10
  199. package/server/market-provider-VOYYVYWT.js +0 -17
  200. package/server/trade-processor-JWVS37KM.js +0 -10
  201. /package/dist/{daily-log-processor-6MWJ23JK.js.map → daily-log-processor-BY3ISY6K.js.map} +0 -0
  202. /package/dist/{daily-logs-store-D3QC2XPV.js.map → daily-logs-store-3C3OTGPK.js.map} +0 -0
  203. /package/dist/{market-provider-VDRJUEF2.js.map → market-provider-H3ARIVZ4.js.map} +0 -0
  204. /package/dist/{proto-3HZTCWK4.js.map → proto-V23GIZG2.js.map} +0 -0
  205. /package/dist/{sync-PO4IPCYV.js.map → sync-EVLKB3ZJ.js.map} +0 -0
  206. /package/dist/{trade-processor-NHU4VWRX.js.map → trade-processor-EYA3I3XB.js.map} +0 -0
  207. /package/dist/{trades-store-LOL3FQSF.js.map → trades-store-R3NL25T2.js.map} +0 -0
  208. /package/server/{daily-log-processor-Y3PVSVBM.js.map → daily-log-processor-ENEUT22A.js.map} +0 -0
  209. /package/server/{daily-logs-store-NU7M4L5C.js.map → daily-logs-store-YFNXTB7J.js.map} +0 -0
  210. /package/server/{market-provider-VOYYVYWT.js.map → market-provider-B437HKLW.js.map} +0 -0
  211. /package/server/{proto-DWRZJO4E.js.map → proto-YZ4TLX2N.js.map} +0 -0
  212. /package/server/{sync-QFI5L7S7.js.map → sync-V25UQJA3.js.map} +0 -0
  213. /package/server/{trade-processor-JWVS37KM.js.map → trade-processor-L3PIQ5TG.js.map} +0 -0
  214. /package/server/{trades-store-VY26MWER.js.map → trades-store-RTTEYMXH.js.map} +0 -0
@@ -0,0 +1,9 @@
1
+ import {
2
+ TradeProcessor
3
+ } from "./chunk-AP7IHUUR.js";
4
+ import "./chunk-6S37CXUA.js";
5
+ import "./chunk-5WRI5ZAA.js";
6
+ export {
7
+ TradeProcessor
8
+ };
9
+ //# sourceMappingURL=trade-processor-EYA3I3XB.js.map
@@ -12,7 +12,7 @@ import {
12
12
  getTradesPage,
13
13
  searchTrades,
14
14
  updateTradesForBlock
15
- } from "./chunk-LDKTV7GW.js";
15
+ } from "./chunk-27S67XW3.js";
16
16
  import "./chunk-5WRI5ZAA.js";
17
17
  export {
18
18
  addTrades,
@@ -29,4 +29,4 @@ export {
29
29
  searchTrades,
30
30
  updateTradesForBlock
31
31
  };
32
- //# sourceMappingURL=trades-store-LOL3FQSF.js.map
32
+ //# sourceMappingURL=trades-store-R3NL25T2.js.map
package/manifest.json CHANGED
@@ -21,9 +21,7 @@
21
21
  "entry_point": "server/index.js",
22
22
  "mcp_config": {
23
23
  "command": "node",
24
- "args": [
25
- "${__dirname}/server/index.js"
26
- ],
24
+ "args": ["${__dirname}/server/index.js"],
27
25
  "env": {
28
26
  "BLOCKS_DIRECTORY": "${user_config.blocks_directory}"
29
27
  }
@@ -96,9 +94,7 @@
96
94
  {
97
95
  "name": "analyze_strategy",
98
96
  "description": "Comprehensive strategy analysis workflow",
99
- "arguments": [
100
- "block_id"
101
- ],
97
+ "arguments": ["block_id"],
102
98
  "text": "Analyze the strategy '${arguments.block_id}' comprehensively:\n\n1. First get basic statistics with `get_statistics`\n2. Run walk-forward analysis with `run_walk_forward` to check for overfitting\n3. Run Monte Carlo simulation with `run_monte_carlo` for risk assessment\n4. Calculate position sizing with `calculate_position_sizing`\n5. Check tail risk with `get_tail_risk`\n\nProvide insights on:\n- Is this strategy robust or potentially overfit?\n- What position size is appropriate given the risk?\n- What are the worst-case scenarios?\n- Any red flags or concerns?"
103
99
  },
104
100
  {
@@ -128,11 +124,7 @@
128
124
  },
129
125
  "compatibility": {
130
126
  "claude_desktop": ">=0.10.0",
131
- "platforms": [
132
- "darwin",
133
- "win32",
134
- "linux"
135
- ],
127
+ "platforms": ["darwin", "win32", "linux"],
136
128
  "runtimes": {
137
129
  "node": ">=18.0.0"
138
130
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tradeblocks-mcp",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "MCP server for options trade analysis",
5
5
  "author": "David Romeo <davidmromeo@gmail.com>",
6
6
  "type": "module",
@@ -3,7 +3,7 @@ import {
3
3
  REPORTING_TRADE_COLUMN_ALIASES,
4
4
  convertTatRowToReportingTrade,
5
5
  isTatFormat
6
- } from "./chunk-72GKJE2U.js";
6
+ } from "./chunk-BOPHW5M6.js";
7
7
 
8
8
  // src/sync/index.ts
9
9
  import { existsSync as existsSync2 } from "fs";
@@ -248,9 +248,21 @@ var DATASETS_V3 = {
248
248
  spot: { subdir: "spot", partitionKeys: ["ticker", "date"], filename: "data.parquet" },
249
249
  enriched: { subdir: "enriched", partitionKeys: ["ticker"], filename: "data.parquet" },
250
250
  enriched_context: { subdir: "enriched/context", partitionKeys: [], filename: "data.parquet" },
251
- option_chain: { subdir: "option_chain", partitionKeys: ["underlying", "date"], filename: "data.parquet" },
252
- option_quote_minutes: { subdir: "option_quote_minutes", partitionKeys: ["underlying", "date"], filename: "data.parquet" },
253
- option_oi_daily: { subdir: "option_oi_daily", partitionKeys: ["underlying", "date"], filename: "data.parquet" }
251
+ option_chain: {
252
+ subdir: "option_chain",
253
+ partitionKeys: ["underlying", "date"],
254
+ filename: "data.parquet"
255
+ },
256
+ option_quote_minutes: {
257
+ subdir: "option_quote_minutes",
258
+ partitionKeys: ["underlying", "date"],
259
+ filename: "data.parquet"
260
+ },
261
+ option_oi_daily: {
262
+ subdir: "option_oi_daily",
263
+ partitionKeys: ["underlying", "date"],
264
+ filename: "data.parquet"
265
+ }
254
266
  };
255
267
  async function writeSpotPartition(conn, args) {
256
268
  const def = DATASETS_V3.spot;
@@ -341,9 +353,7 @@ async function writeParquetPartition(conn, opts) {
341
353
  const filename = isLegacy ? "data.parquet" : opts.filename ?? "data.parquet";
342
354
  for (const [k, v] of Object.entries(partitions)) {
343
355
  if (!PARTITION_KEY_RE.test(k)) {
344
- throw new Error(
345
- `writeParquetPartition: unsafe partition key: ${JSON.stringify(k)}`
346
- );
356
+ throw new Error(`writeParquetPartition: unsafe partition key: ${JSON.stringify(k)}`);
347
357
  }
348
358
  if (!PARTITION_VALUE_RE.test(v)) {
349
359
  throw new Error(
@@ -351,9 +361,7 @@ async function writeParquetPartition(conn, opts) {
351
361
  );
352
362
  }
353
363
  }
354
- const partitionSegments = Object.entries(partitions).map(
355
- ([k, v]) => `${k}=${v}`
356
- );
364
+ const partitionSegments = Object.entries(partitions).map(([k, v]) => `${k}=${v}`);
357
365
  const targetPath = path2.join(opts.baseDir, ...partitionSegments, filename);
358
366
  return writeParquetAtomic(conn, {
359
367
  targetPath,
@@ -581,9 +589,7 @@ async function loadEnrichmentWatermarks(dataDir) {
581
589
  if (raw === null) return { version: 1, watermarks: {} };
582
590
  const parsed = EnrichmentWatermarksSchema.safeParse(raw);
583
591
  if (!parsed.success) {
584
- throw new Error(
585
- `enrichment-watermarks.json is malformed: ${parsed.error.message}`
586
- );
592
+ throw new Error(`enrichment-watermarks.json is malformed: ${parsed.error.message}`);
587
593
  }
588
594
  return parsed.data;
589
595
  }
@@ -624,13 +630,27 @@ async function ensureProfilesSchema(conn) {
624
630
  await conn.run(`
625
631
  ALTER TABLE profiles.strategy_profiles ADD COLUMN IF NOT EXISTS position_sizing JSON
626
632
  `);
627
- await conn.run(`ALTER TABLE profiles.strategy_profiles ADD COLUMN IF NOT EXISTS underlying VARCHAR`);
628
- await conn.run(`ALTER TABLE profiles.strategy_profiles ADD COLUMN IF NOT EXISTS re_entry BOOLEAN`);
629
- await conn.run(`ALTER TABLE profiles.strategy_profiles ADD COLUMN IF NOT EXISTS cap_profits BOOLEAN`);
630
- await conn.run(`ALTER TABLE profiles.strategy_profiles ADD COLUMN IF NOT EXISTS cap_losses BOOLEAN`);
631
- await conn.run(`ALTER TABLE profiles.strategy_profiles ADD COLUMN IF NOT EXISTS require_two_prices_pt BOOLEAN`);
632
- await conn.run(`ALTER TABLE profiles.strategy_profiles ADD COLUMN IF NOT EXISTS close_on_completion BOOLEAN`);
633
- await conn.run(`ALTER TABLE profiles.strategy_profiles ADD COLUMN IF NOT EXISTS ignore_margin_req BOOLEAN`);
633
+ await conn.run(
634
+ `ALTER TABLE profiles.strategy_profiles ADD COLUMN IF NOT EXISTS underlying VARCHAR`
635
+ );
636
+ await conn.run(
637
+ `ALTER TABLE profiles.strategy_profiles ADD COLUMN IF NOT EXISTS re_entry BOOLEAN`
638
+ );
639
+ await conn.run(
640
+ `ALTER TABLE profiles.strategy_profiles ADD COLUMN IF NOT EXISTS cap_profits BOOLEAN`
641
+ );
642
+ await conn.run(
643
+ `ALTER TABLE profiles.strategy_profiles ADD COLUMN IF NOT EXISTS cap_losses BOOLEAN`
644
+ );
645
+ await conn.run(
646
+ `ALTER TABLE profiles.strategy_profiles ADD COLUMN IF NOT EXISTS require_two_prices_pt BOOLEAN`
647
+ );
648
+ await conn.run(
649
+ `ALTER TABLE profiles.strategy_profiles ADD COLUMN IF NOT EXISTS close_on_completion BOOLEAN`
650
+ );
651
+ await conn.run(
652
+ `ALTER TABLE profiles.strategy_profiles ADD COLUMN IF NOT EXISTS ignore_margin_req BOOLEAN`
653
+ );
634
654
  const strategyCols = [
635
655
  { name: "slippage_entry", type: "DOUBLE" },
636
656
  { name: "slippage_exit", type: "DOUBLE" },
@@ -644,7 +664,9 @@ async function ensureProfilesSchema(conn) {
644
664
  { name: "default_to_date", type: "VARCHAR" }
645
665
  ];
646
666
  for (const col of strategyCols) {
647
- await conn.run(`ALTER TABLE profiles.strategy_profiles ADD COLUMN IF NOT EXISTS ${col.name} ${col.type}`);
667
+ await conn.run(
668
+ `ALTER TABLE profiles.strategy_profiles ADD COLUMN IF NOT EXISTS ${col.name} ${col.type}`
669
+ );
648
670
  }
649
671
  await migrateExpectedRegimes(conn);
650
672
  }
@@ -1014,7 +1036,11 @@ async function createMarketParquetViews(conn, dataDir) {
1014
1036
  const viewsCreated = [];
1015
1037
  const tablesKept = [];
1016
1038
  const hiveViews = [
1017
- { name: "option_chain", subdir: resolveCanonicalMarketPartitionDir(dataDir, "option_chain"), partitionKey: "underlying" }
1039
+ {
1040
+ name: "option_chain",
1041
+ subdir: resolveCanonicalMarketPartitionDir(dataDir, "option_chain"),
1042
+ partitionKey: "underlying"
1043
+ }
1018
1044
  ];
1019
1045
  for (const { name, subdir, partitionKey } of hiveViews) {
1020
1046
  const dirPath = subdir;
@@ -1282,12 +1308,7 @@ async function migrateProfiles(conn, blocksDir) {
1282
1308
  createdAt: createdAt.toISOString(),
1283
1309
  updatedAt: updatedAt.toISOString()
1284
1310
  };
1285
- const filePath = path6.join(
1286
- blocksDir,
1287
- blockId,
1288
- "profiles",
1289
- toFileSlug(strategyName) + ".json"
1290
- );
1311
+ const filePath = path6.join(blocksDir, blockId, "profiles", toFileSlug(strategyName) + ".json");
1291
1312
  await writeJsonFile(filePath, profileJson);
1292
1313
  }
1293
1314
  return rows.length;
@@ -1346,7 +1367,9 @@ async function migrateMarketImportMetadata(conn, dataDir) {
1346
1367
  return rows.length;
1347
1368
  }
1348
1369
  async function migrateFlatImportLog(conn, dataDir) {
1349
- const existingFile = await readJsonFile(path6.join(dataDir, "market-meta", "flat-import-log.json"));
1370
+ const existingFile = await readJsonFile(
1371
+ path6.join(dataDir, "market-meta", "flat-import-log.json")
1372
+ );
1350
1373
  if (existingFile !== null) return 0;
1351
1374
  let rows;
1352
1375
  try {
@@ -1585,10 +1608,13 @@ async function openReadWriteConnection(dbPath, threads, memoryLimit) {
1585
1608
  await createMarketParquetViews(connection, dataRoot);
1586
1609
  await ensureMarketDataTables(connection);
1587
1610
  try {
1588
- const blocksDir = (await import("./sync-QFI5L7S7.js")).getBlocksDir(dataRoot);
1611
+ const blocksDir = (await import("./sync-V25UQJA3.js")).getBlocksDir(dataRoot);
1589
1612
  await migrateMetadataToJson(connection, dataRoot, blocksDir);
1590
1613
  } catch (err) {
1591
- console.warn("[json-migration] Migration failed (non-fatal):", err instanceof Error ? err.message : err);
1614
+ console.warn(
1615
+ "[json-migration] Migration failed (non-fatal):",
1616
+ err instanceof Error ? err.message : err
1617
+ );
1592
1618
  }
1593
1619
  connectionMode = "read_write";
1594
1620
  return connection;
@@ -1643,7 +1669,11 @@ async function getConnection(dataDir) {
1643
1669
  } catch (error) {
1644
1670
  const errorMessage = error instanceof Error ? error.message : String(error);
1645
1671
  if (isLockError(errorMessage)) {
1646
- const recovered = await tryRecoverLockByTerminatingStaleProcess(errorMessage, dbPath, forceRecovery);
1672
+ const recovered = await tryRecoverLockByTerminatingStaleProcess(
1673
+ errorMessage,
1674
+ dbPath,
1675
+ forceRecovery
1676
+ );
1647
1677
  if (recovered) {
1648
1678
  for (let attempt = 0; attempt < 3; attempt++) {
1649
1679
  await new Promise((r) => setTimeout(r, 500 * (attempt + 1)));
@@ -1813,18 +1843,13 @@ async function deleteSyncMetadata(conn, blockId, blocksDir) {
1813
1843
  await deleteSyncMetadataJson(blockId, blocksDir);
1814
1844
  return;
1815
1845
  }
1816
- await conn.run(
1817
- `DELETE FROM trades._sync_metadata WHERE block_id = $1`,
1818
- [blockId]
1819
- );
1846
+ await conn.run(`DELETE FROM trades._sync_metadata WHERE block_id = $1`, [blockId]);
1820
1847
  }
1821
1848
  async function getAllSyncedBlockIds(conn, blocksDir) {
1822
1849
  if (isParquetMode() && blocksDir) {
1823
1850
  return getAllSyncedBlockIdsJson(blocksDir);
1824
1851
  }
1825
- const reader = await conn.runAndReadAll(
1826
- `SELECT block_id FROM trades._sync_metadata`
1827
- );
1852
+ const reader = await conn.runAndReadAll(`SELECT block_id FROM trades._sync_metadata`);
1828
1853
  const rows = reader.getRows();
1829
1854
  return rows.map((row) => row[0]);
1830
1855
  }
@@ -1961,12 +1986,8 @@ async function detectCsvType(filePath) {
1961
1986
  const reportingAliases = Object.keys(REPORTING_TRADE_COLUMN_ALIASES).map(
1962
1987
  (k) => k.toLowerCase()
1963
1988
  );
1964
- const hasReportingColumns = reportingAliases.some(
1965
- (alias) => headers.includes(alias)
1966
- );
1967
- const hasActualPl = headers.some(
1968
- (h) => h.includes("actual") && h.includes("p")
1969
- );
1989
+ const hasReportingColumns = reportingAliases.some((alias) => headers.includes(alias));
1990
+ const hasActualPl = headers.some((h) => h.includes("actual") && h.includes("p"));
1970
1991
  const hasReportedStyle = headers.includes("trade id") || headers.some((h) => h.includes("reported"));
1971
1992
  if (hasActualPl || hasReportingColumns || hasReportedStyle) {
1972
1993
  if (!hasPl || hasActualPl) {
@@ -2228,9 +2249,7 @@ async function loadDailyLogs(blockPath, blockId, filename = "dailylog.csv") {
2228
2249
  entries.push(entry);
2229
2250
  }
2230
2251
  }
2231
- entries.sort(
2232
- (a, b) => new Date(a.date).getTime() - new Date(b.date).getTime()
2233
- );
2252
+ entries.sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime());
2234
2253
  return entries.length > 0 ? entries : void 0;
2235
2254
  } catch {
2236
2255
  return void 0;
@@ -2439,14 +2458,12 @@ async function listBlocks(baseDir) {
2439
2458
  }
2440
2459
  function normalizeRecordHeaders(raw) {
2441
2460
  const normalized = { ...raw };
2442
- Object.entries(REPORTING_TRADE_COLUMN_ALIASES).forEach(
2443
- ([alias, canonical]) => {
2444
- if (normalized[alias] !== void 0) {
2445
- normalized[canonical] = normalized[alias];
2446
- delete normalized[alias];
2447
- }
2461
+ Object.entries(REPORTING_TRADE_COLUMN_ALIASES).forEach(([alias, canonical]) => {
2462
+ if (normalized[alias] !== void 0) {
2463
+ normalized[canonical] = normalized[alias];
2464
+ delete normalized[alias];
2448
2465
  }
2449
- );
2466
+ });
2450
2467
  return normalized;
2451
2468
  }
2452
2469
  function convertToReportingTrade(raw) {
@@ -2499,9 +2516,7 @@ async function loadReportingLog(baseDir, blockId) {
2499
2516
  trades.push(trade);
2500
2517
  }
2501
2518
  }
2502
- trades.sort(
2503
- (a, b) => new Date(a.dateOpened).getTime() - new Date(b.dateOpened).getTime()
2504
- );
2519
+ trades.sort((a, b) => new Date(a.dateOpened).getTime() - new Date(b.dateOpened).getTime());
2505
2520
  return trades;
2506
2521
  }
2507
2522
  function toKebabCase(str) {
@@ -2541,9 +2556,7 @@ function validateCsvColumns(records, csvType) {
2541
2556
  }
2542
2557
  const dateOpenedAliases = ["Date Opened", "date_opened"];
2543
2558
  const plAliases = ["P/L", "pl"];
2544
- const hasDateOpened = dateOpenedAliases.some(
2545
- (col) => headers.includes(col)
2546
- );
2559
+ const hasDateOpened = dateOpenedAliases.some((col) => headers.includes(col));
2547
2560
  const hasPl = plAliases.some((col) => headers.includes(col));
2548
2561
  const missing = [];
2549
2562
  if (!hasDateOpened) missing.push("Date Opened");
@@ -2583,9 +2596,7 @@ async function importCsv(baseDir, options) {
2583
2596
  const name = blockName;
2584
2597
  const blockId = toKebabCase(name);
2585
2598
  if (!blockId) {
2586
- throw new Error(
2587
- "Could not derive a valid block ID from the filename or provided name"
2588
- );
2599
+ throw new Error("Could not derive a valid block ID from the filename or provided name");
2589
2600
  }
2590
2601
  const blockPath = path9.join(blocksDir, blockId);
2591
2602
  try {
@@ -2744,10 +2755,7 @@ async function insertTradeBatch(conn, blockId, records, startIdx, batchSize) {
2744
2755
  for (let rowIdx = 0; rowIdx < batch.length; rowIdx++) {
2745
2756
  const record = batch[rowIdx];
2746
2757
  const baseParam = rowIdx * columnsPerRow + 1;
2747
- const rowPlaceholders = Array.from(
2748
- { length: columnsPerRow },
2749
- (_, i) => `$${baseParam + i}`
2750
- );
2758
+ const rowPlaceholders = Array.from({ length: columnsPerRow }, (_, i) => `$${baseParam + i}`);
2751
2759
  placeholders.push(`(${rowPlaceholders.join(", ")})`);
2752
2760
  const premium = parseFloat(record["Premium"]);
2753
2761
  const numContracts = parseInt(record["No. of Contracts"], 10);
@@ -2815,10 +2823,7 @@ async function insertReportingBatch(conn, blockId, trades, tickers, startIdx, ba
2815
2823
  for (let rowIdx = 0; rowIdx < batch.length; rowIdx++) {
2816
2824
  const trade = batch[rowIdx];
2817
2825
  const baseParam = rowIdx * columnsPerRow + 1;
2818
- const rowPlaceholders = Array.from(
2819
- { length: columnsPerRow },
2820
- (_, i) => `$${baseParam + i}`
2821
- );
2826
+ const rowPlaceholders = Array.from({ length: columnsPerRow }, (_, i) => `$${baseParam + i}`);
2822
2827
  placeholders.push(`(${rowPlaceholders.join(", ")})`);
2823
2828
  params.push(
2824
2829
  blockId,
@@ -2860,14 +2865,8 @@ async function syncBlockInternal(conn, blockId, blockPath) {
2860
2865
  if (existingMetadata) {
2861
2866
  await conn.run("BEGIN TRANSACTION");
2862
2867
  try {
2863
- await conn.run(
2864
- "DELETE FROM trades.trade_data WHERE block_id = $1",
2865
- [blockId]
2866
- );
2867
- await conn.run(
2868
- "DELETE FROM trades.reporting_data WHERE block_id = $1",
2869
- [blockId]
2870
- );
2868
+ await conn.run("DELETE FROM trades.trade_data WHERE block_id = $1", [blockId]);
2869
+ await conn.run("DELETE FROM trades.reporting_data WHERE block_id = $1", [blockId]);
2871
2870
  await deleteSyncMetadata(conn, blockId, blocksDir);
2872
2871
  await conn.run("COMMIT");
2873
2872
  return { blockId, status: "deleted" };
@@ -2902,10 +2901,7 @@ async function syncBlockInternal(conn, blockId, blockPath) {
2902
2901
  }
2903
2902
  await conn.run("BEGIN TRANSACTION");
2904
2903
  try {
2905
- await conn.run(
2906
- "DELETE FROM trades.trade_data WHERE block_id = $1",
2907
- [blockId]
2908
- );
2904
+ await conn.run("DELETE FROM trades.trade_data WHERE block_id = $1", [blockId]);
2909
2905
  const csvContent = await fs8.readFile(tradelogPath, "utf-8");
2910
2906
  const records = parseCSV2(csvContent);
2911
2907
  const batchSize = 500;
@@ -2917,24 +2913,21 @@ async function syncBlockInternal(conn, blockId, blockPath) {
2917
2913
  let reportinglogHash = null;
2918
2914
  if (optionalLogs.dailylog) {
2919
2915
  try {
2920
- dailylogHash = versionedHash(await hashFileContent(
2921
- path10.join(blockPath, optionalLogs.dailylog)
2922
- ));
2916
+ dailylogHash = versionedHash(
2917
+ await hashFileContent(path10.join(blockPath, optionalLogs.dailylog))
2918
+ );
2923
2919
  } catch {
2924
2920
  }
2925
2921
  }
2926
2922
  if (optionalLogs.reportinglog) {
2927
2923
  try {
2928
- reportinglogHash = versionedHash(await hashFileContent(
2929
- path10.join(blockPath, optionalLogs.reportinglog)
2930
- ));
2924
+ reportinglogHash = versionedHash(
2925
+ await hashFileContent(path10.join(blockPath, optionalLogs.reportinglog))
2926
+ );
2931
2927
  } catch {
2932
2928
  }
2933
2929
  }
2934
- await conn.run(
2935
- "DELETE FROM trades.reporting_data WHERE block_id = $1",
2936
- [blockId]
2937
- );
2930
+ await conn.run("DELETE FROM trades.reporting_data WHERE block_id = $1", [blockId]);
2938
2931
  if (optionalLogs.reportinglog && reportinglogHash) {
2939
2932
  const reportingPath = path10.join(blockPath, optionalLogs.reportinglog);
2940
2933
  const reportingContent = await fs8.readFile(reportingPath, "utf-8");
@@ -2949,7 +2942,14 @@ async function syncBlockInternal(conn, blockId, blockPath) {
2949
2942
  }
2950
2943
  }
2951
2944
  for (let i = 0; i < reportingTrades.length; i += batchSize) {
2952
- await insertReportingBatch(conn, blockId, reportingTrades, reportingTickers, i, batchSize);
2945
+ await insertReportingBatch(
2946
+ conn,
2947
+ blockId,
2948
+ reportingTrades,
2949
+ reportingTickers,
2950
+ i,
2951
+ batchSize
2952
+ );
2953
2953
  }
2954
2954
  }
2955
2955
  const newMetadata = {
@@ -2972,14 +2972,8 @@ async function syncBlockInternal(conn, blockId, blockPath) {
2972
2972
  if (existingMetadata) {
2973
2973
  try {
2974
2974
  await conn.run("BEGIN TRANSACTION");
2975
- await conn.run(
2976
- "DELETE FROM trades.trade_data WHERE block_id = $1",
2977
- [blockId]
2978
- );
2979
- await conn.run(
2980
- "DELETE FROM trades.reporting_data WHERE block_id = $1",
2981
- [blockId]
2982
- );
2975
+ await conn.run("DELETE FROM trades.trade_data WHERE block_id = $1", [blockId]);
2976
+ await conn.run("DELETE FROM trades.reporting_data WHERE block_id = $1", [blockId]);
2983
2977
  await deleteSyncMetadata(conn, blockId, blocksDir);
2984
2978
  await conn.run("COMMIT");
2985
2979
  } catch {
@@ -3009,7 +3003,8 @@ async function detectBlockChanges(conn, baseDir) {
3009
3003
  for (const entry of entries) {
3010
3004
  if (!entry.isDirectory()) continue;
3011
3005
  if (entry.name.startsWith(".") || entry.name.startsWith("_")) continue;
3012
- if (entry.name.endsWith(".tmp") || entry.name.endsWith(".duckdb") || entry.name.endsWith(".duckdb.tmp")) continue;
3006
+ if (entry.name.endsWith(".tmp") || entry.name.endsWith(".duckdb") || entry.name.endsWith(".duckdb.tmp"))
3007
+ continue;
3013
3008
  const blockId = entry.name;
3014
3009
  folderNames.add(blockId);
3015
3010
  const blockPath = path10.join(baseDir, blockId);
@@ -3058,14 +3053,8 @@ async function cleanupDeletedBlocks(conn, deletedBlockIds, blocksDir) {
3058
3053
  for (const blockId of deletedBlockIds) {
3059
3054
  await conn.run("BEGIN TRANSACTION");
3060
3055
  try {
3061
- await conn.run(
3062
- "DELETE FROM trades.trade_data WHERE block_id = $1",
3063
- [blockId]
3064
- );
3065
- await conn.run(
3066
- "DELETE FROM trades.reporting_data WHERE block_id = $1",
3067
- [blockId]
3068
- );
3056
+ await conn.run("DELETE FROM trades.trade_data WHERE block_id = $1", [blockId]);
3057
+ await conn.run("DELETE FROM trades.reporting_data WHERE block_id = $1", [blockId]);
3069
3058
  await deleteSyncMetadata(conn, blockId, blocksDir);
3070
3059
  await conn.run("COMMIT");
3071
3060
  } catch (err) {
@@ -3183,4 +3172,4 @@ export {
3183
3172
  loadReportingLog,
3184
3173
  importCsv
3185
3174
  };
3186
- //# sourceMappingURL=chunk-NZO6PT64.js.map
3175
+ //# sourceMappingURL=chunk-4P7D7YZP.js.map