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.
- package/README.md +82 -68
- package/dist/{chunk-LDKTV7GW.js → chunk-27S67XW3.js} +24 -52
- package/dist/chunk-27S67XW3.js.map +1 -0
- package/dist/{chunk-FGZH632F.js → chunk-2E63THNI.js} +13 -11
- package/dist/chunk-2E63THNI.js.map +1 -0
- package/dist/{chunk-BKQ4PM4Y.js → chunk-6S37CXUA.js} +11 -13
- package/dist/chunk-6S37CXUA.js.map +1 -0
- package/dist/{chunk-PRAYH3RT.js → chunk-AP7IHUUR.js} +29 -12
- package/dist/chunk-AP7IHUUR.js.map +1 -0
- package/dist/{chunk-QTTR7AAW.js → chunk-C6LL746C.js} +67 -84
- package/dist/{chunk-QTTR7AAW.js.map → chunk-C6LL746C.js.map} +1 -1
- package/dist/{chunk-W2PP3LEH.js → chunk-SEUZYQGQ.js} +17 -8
- package/dist/chunk-SEUZYQGQ.js.map +1 -0
- package/dist/{chunk-4BLCXNQ6.js → chunk-UBUC5A66.js} +105 -114
- package/dist/chunk-UBUC5A66.js.map +1 -0
- package/dist/{chunk-XXYOUIZY.js → chunk-VDU25Z6X.js} +63 -80
- package/dist/chunk-VDU25Z6X.js.map +1 -0
- package/dist/daily-log-processor-BY3ISY6K.js +9 -0
- package/dist/{daily-logs-store-D3QC2XPV.js → daily-logs-store-3C3OTGPK.js} +2 -2
- package/dist/iv-solver-worker.js +9 -1
- package/dist/market-provider-H3ARIVZ4.js +16 -0
- package/dist/{proto-3HZTCWK4.js → proto-V23GIZG2.js} +2 -2
- package/dist/{sync-PO4IPCYV.js → sync-EVLKB3ZJ.js} +7 -7
- package/dist/test-exports.js +358 -254
- package/dist/test-exports.js.map +1 -1
- package/dist/trade-processor-EYA3I3XB.js +9 -0
- package/dist/{trades-store-LOL3FQSF.js → trades-store-R3NL25T2.js} +2 -2
- package/manifest.json +3 -11
- package/package.json +1 -1
- package/server/{chunk-NZO6PT64.js → chunk-4P7D7YZP.js} +102 -113
- package/server/chunk-4P7D7YZP.js.map +1 -0
- package/server/{chunk-72GKJE2U.js → chunk-BOPHW5M6.js} +521 -235
- package/server/chunk-BOPHW5M6.js.map +1 -0
- package/server/{chunk-WA5AAPCH.js → chunk-GH2552SE.js} +17 -8
- package/server/chunk-GH2552SE.js.map +1 -0
- package/server/{chunk-5EBXHT6C.js → chunk-OBYKFW2B.js} +11 -13
- package/server/chunk-OBYKFW2B.js.map +1 -0
- package/server/{chunk-FBNDMCT5.js → chunk-T66KH2XH.js} +13 -11
- package/server/chunk-T66KH2XH.js.map +1 -0
- package/server/{chunk-NRFXAJF7.js → chunk-W5E7FHC4.js} +24 -52
- package/server/chunk-W5E7FHC4.js.map +1 -0
- package/server/{chunk-CSDVJPBB.js → chunk-YUCOAJ4Z.js} +29 -12
- package/server/chunk-YUCOAJ4Z.js.map +1 -0
- package/server/{chunk-PNKG7RY7.js → chunk-ZBJCF4ZG.js} +63 -80
- package/server/chunk-ZBJCF4ZG.js.map +1 -0
- package/server/{config-6IZXEFEX.js → config-DK7KOMNL.js} +1 -1
- package/server/config-DK7KOMNL.js.map +1 -0
- package/server/daily-log-processor-ENEUT22A.js +10 -0
- package/server/{daily-logs-store-NU7M4L5C.js → daily-logs-store-YFNXTB7J.js} +2 -2
- package/server/http-server.js +2 -5
- package/server/index.js +1771 -1538
- package/server/index.js.map +1 -1
- package/server/iv-solver-worker.js +9 -1
- package/server/market-provider-B437HKLW.js +17 -0
- package/server/{proto-DWRZJO4E.js → proto-YZ4TLX2N.js} +2 -2
- package/server/{sync-QFI5L7S7.js → sync-V25UQJA3.js} +7 -7
- package/server/trade-processor-L3PIQ5TG.js +10 -0
- package/server/{trades-store-VY26MWER.js → trades-store-RTTEYMXH.js} +2 -2
- package/src/auth/clients-store.ts +4 -4
- package/src/auth/code-store.ts +1 -1
- package/src/auth/config.ts +11 -12
- package/src/auth/login-page.ts +8 -10
- package/src/auth/provider.ts +35 -30
- package/src/auth/token.ts +17 -15
- package/src/db/backtest-schemas.ts +12 -4
- package/src/db/connection.ts +107 -40
- package/src/db/index.ts +37 -5
- package/src/db/json-adapters.ts +22 -31
- package/src/db/json-migration.ts +11 -15
- package/src/db/json-store.ts +5 -3
- package/src/db/market-datasets.ts +48 -15
- package/src/db/market-schemas.ts +11 -5
- package/src/db/market-views.ts +119 -32
- package/src/db/parquet-writer.ts +7 -7
- package/src/db/profile-schemas.ts +39 -22
- package/src/db/schemas.ts +2 -2
- package/src/http-server.ts +7 -12
- package/src/index.ts +8 -9
- package/src/market/ingestor/index.ts +1 -4
- package/src/market/ingestor/market-ingestor.ts +140 -67
- package/src/market/ingestor/types.ts +1 -3
- package/src/market/stores/chain-sql.ts +2 -8
- package/src/market/stores/chain-store.ts +1 -4
- package/src/market/stores/duckdb-chain-store.ts +3 -14
- package/src/market/stores/duckdb-enriched-store.ts +3 -13
- package/src/market/stores/duckdb-quote-store.ts +10 -27
- package/src/market/stores/duckdb-spot-store.ts +4 -20
- package/src/market/stores/enriched-sql.ts +3 -9
- package/src/market/stores/enriched-store.ts +2 -2
- package/src/market/stores/parquet-chain-store.ts +5 -22
- package/src/market/stores/parquet-enriched-store.ts +4 -16
- package/src/market/stores/parquet-oi-daily-store.ts +3 -14
- package/src/market/stores/parquet-quote-store.ts +9 -29
- package/src/market/stores/parquet-spot-store.ts +14 -33
- package/src/market/stores/quote-store.ts +2 -10
- package/src/market/stores/spot-sql.ts +3 -15
- package/src/market/stores/spot-store.ts +1 -1
- package/src/market/tickers/defaults.json +6 -6
- package/src/market/tickers/loader.ts +2 -7
- package/src/market/tickers/registry.ts +5 -15
- package/src/market/tickers/schemas.ts +2 -6
- package/src/models/strategy-profile.ts +39 -39
- package/src/sync/block-sync.ts +44 -65
- package/src/sync/index.ts +1 -4
- package/src/sync/metadata.ts +14 -20
- package/src/test-exports.ts +127 -123
- package/src/tools/analysis.ts +180 -159
- package/src/tools/batch-exit-analysis.ts +100 -59
- package/src/tools/blocks/analysis.ts +116 -101
- package/src/tools/blocks/comparison.ts +281 -364
- package/src/tools/blocks/core.ts +208 -253
- package/src/tools/blocks/health.ts +571 -563
- package/src/tools/blocks/similarity.ts +316 -283
- package/src/tools/edge-decay.ts +124 -197
- package/src/tools/exit-analysis.ts +130 -77
- package/src/tools/greeks-attribution.ts +84 -35
- package/src/tools/guides.ts +4 -6
- package/src/tools/imports.ts +9 -12
- package/src/tools/market-data.ts +1067 -757
- package/src/tools/market-enrichment.ts +3 -3
- package/src/tools/market-fetch.ts +148 -67
- package/src/tools/market-imports.ts +12 -12
- package/src/tools/middleware/sync-middleware.ts +5 -6
- package/src/tools/performance.ts +185 -302
- package/src/tools/profile-analysis.ts +52 -66
- package/src/tools/profiles.ts +106 -69
- package/src/tools/regime-advisor.ts +20 -45
- package/src/tools/replay.ts +81 -77
- package/src/tools/reports/discrepancies.ts +298 -328
- package/src/tools/reports/fields.ts +7 -25
- package/src/tools/reports/helpers.ts +18 -49
- package/src/tools/reports/predictive.ts +27 -70
- package/src/tools/reports/slippage-trends.ts +315 -345
- package/src/tools/reports/slippage.ts +1 -4
- package/src/tools/reports/strategy-matches.ts +399 -441
- package/src/tools/schema.ts +43 -40
- package/src/tools/shared/filters.ts +3 -9
- package/src/tools/snapshot.ts +9 -30
- package/src/tools/sql.ts +15 -14
- package/src/tools/tickers.ts +1 -4
- package/src/utils/batch-exit-analysis.ts +31 -42
- package/src/utils/black-scholes.ts +39 -29
- package/src/utils/block-loader.ts +68 -82
- package/src/utils/calibration-probe.ts +1 -2
- package/src/utils/chain-loader.ts +3 -3
- package/src/utils/csv-discovery.ts +16 -22
- package/src/utils/data-quality.ts +24 -36
- package/src/utils/exit-triggers.ts +91 -96
- package/src/utils/field-timing.ts +94 -79
- package/src/utils/filter-predicates.ts +13 -9
- package/src/utils/flatfile-importer.ts +94 -64
- package/src/utils/greeks-decomposition.ts +152 -100
- package/src/utils/iv-solver-pool.ts +55 -25
- package/src/utils/iv-solver-worker.ts +5 -5
- package/src/utils/market-enricher.ts +528 -497
- package/src/utils/market-importer.ts +31 -12
- package/src/utils/market-provider.ts +21 -23
- package/src/utils/massive-tier.ts +5 -7
- package/src/utils/migrate-option-data-helpers.ts +2 -8
- package/src/utils/option-quote-greeks.ts +25 -31
- package/src/utils/option-time.ts +4 -8
- package/src/utils/output-formatter.ts +1 -4
- package/src/utils/provider-capabilities.ts +1 -4
- package/src/utils/providers/massive.ts +59 -93
- package/src/utils/providers/thetadata/backfill.ts +14 -23
- package/src/utils/providers/thetadata/client.ts +12 -8
- package/src/utils/providers/thetadata/decode.ts +2 -20
- package/src/utils/providers/thetadata/endpoints.ts +32 -40
- package/src/utils/providers/thetadata/join.ts +11 -10
- package/src/utils/providers/thetadata/proto.ts +12 -10
- package/src/utils/providers/thetadata/quote-mid-greeks.ts +5 -5
- package/src/utils/providers/thetadata.ts +11 -10
- package/src/utils/quote-enricher.ts +4 -4
- package/src/utils/quote-parquet-projection.ts +3 -11
- package/src/utils/sample-date-selector.ts +3 -5
- package/src/utils/schema-metadata.ts +102 -70
- package/src/utils/ticker.ts +5 -9
- package/src/utils/trade-replay.ts +77 -68
- package/dist/chunk-4BLCXNQ6.js.map +0 -1
- package/dist/chunk-BKQ4PM4Y.js.map +0 -1
- package/dist/chunk-FGZH632F.js.map +0 -1
- package/dist/chunk-LDKTV7GW.js.map +0 -1
- package/dist/chunk-PRAYH3RT.js.map +0 -1
- package/dist/chunk-W2PP3LEH.js.map +0 -1
- package/dist/chunk-XXYOUIZY.js.map +0 -1
- package/dist/daily-log-processor-6MWJ23JK.js +0 -9
- package/dist/market-provider-VDRJUEF2.js +0 -16
- package/dist/trade-processor-NHU4VWRX.js +0 -9
- package/server/chunk-5EBXHT6C.js.map +0 -1
- package/server/chunk-72GKJE2U.js.map +0 -1
- package/server/chunk-CSDVJPBB.js.map +0 -1
- package/server/chunk-FBNDMCT5.js.map +0 -1
- package/server/chunk-NRFXAJF7.js.map +0 -1
- package/server/chunk-NZO6PT64.js.map +0 -1
- package/server/chunk-PNKG7RY7.js.map +0 -1
- package/server/chunk-WA5AAPCH.js.map +0 -1
- package/server/config-6IZXEFEX.js.map +0 -1
- package/server/daily-log-processor-Y3PVSVBM.js +0 -10
- package/server/market-provider-VOYYVYWT.js +0 -17
- package/server/trade-processor-JWVS37KM.js +0 -10
- /package/dist/{daily-log-processor-6MWJ23JK.js.map → daily-log-processor-BY3ISY6K.js.map} +0 -0
- /package/dist/{daily-logs-store-D3QC2XPV.js.map → daily-logs-store-3C3OTGPK.js.map} +0 -0
- /package/dist/{market-provider-VDRJUEF2.js.map → market-provider-H3ARIVZ4.js.map} +0 -0
- /package/dist/{proto-3HZTCWK4.js.map → proto-V23GIZG2.js.map} +0 -0
- /package/dist/{sync-PO4IPCYV.js.map → sync-EVLKB3ZJ.js.map} +0 -0
- /package/dist/{trade-processor-NHU4VWRX.js.map → trade-processor-EYA3I3XB.js.map} +0 -0
- /package/dist/{trades-store-LOL3FQSF.js.map → trades-store-R3NL25T2.js.map} +0 -0
- /package/server/{daily-log-processor-Y3PVSVBM.js.map → daily-log-processor-ENEUT22A.js.map} +0 -0
- /package/server/{daily-logs-store-NU7M4L5C.js.map → daily-logs-store-YFNXTB7J.js.map} +0 -0
- /package/server/{market-provider-VOYYVYWT.js.map → market-provider-B437HKLW.js.map} +0 -0
- /package/server/{proto-DWRZJO4E.js.map → proto-YZ4TLX2N.js.map} +0 -0
- /package/server/{sync-QFI5L7S7.js.map → sync-V25UQJA3.js.map} +0 -0
- /package/server/{trade-processor-JWVS37KM.js.map → trade-processor-L3PIQ5TG.js.map} +0 -0
- /package/server/{trades-store-VY26MWER.js.map → trades-store-RTTEYMXH.js.map} +0 -0
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
getTradesPage,
|
|
13
13
|
searchTrades,
|
|
14
14
|
updateTradesForBlock
|
|
15
|
-
} from "./chunk-
|
|
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-
|
|
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
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
REPORTING_TRADE_COLUMN_ALIASES,
|
|
4
4
|
convertTatRowToReportingTrade,
|
|
5
5
|
isTatFormat
|
|
6
|
-
} from "./chunk-
|
|
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: {
|
|
252
|
-
|
|
253
|
-
|
|
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(
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
await conn.run(
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
await conn.run(
|
|
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(
|
|
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
|
-
{
|
|
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(
|
|
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-
|
|
1611
|
+
const blocksDir = (await import("./sync-V25UQJA3.js")).getBlocksDir(dataRoot);
|
|
1589
1612
|
await migrateMetadataToJson(connection, dataRoot, blocksDir);
|
|
1590
1613
|
} catch (err) {
|
|
1591
|
-
console.warn(
|
|
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(
|
|
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
|
-
|
|
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
|
|
2444
|
-
|
|
2445
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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"))
|
|
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
|
-
|
|
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-
|
|
3175
|
+
//# sourceMappingURL=chunk-4P7D7YZP.js.map
|