caishen

PDSP — Price Data Services Persistence (“The Spider Database”)

RISE Framework Specification Set — Index & Source Map

Spec Set ID: PDSP (70–77) Version: 1.0 Last Updated: 2026-08-01 Status: Reverse-engineered from the deprecated .NET Framework 4.8 implementation


What This Spec Set Covers

The Caishen platform persisted market price data into a relational database (Microsoft SQL Server) and drove downstream analysis from that store. Two databases were involved:

Database Role
PDSDb The price store. OHLC bid/ask bars, instrument properties, and derived indicator panels. This is the “price service deployed inside the database”.
SpiderDb The strategy/analysis store. Breakout strategies, order requests/responses, trades, timelines, chart annotations, goals.

Both ran in the same SQL Server instance (host codename ZEUS, a Docker container). The name “Spider database” is commonly used for the whole deployment, though strictly SpiderDb is only the strategy half.

The behaviour that made this system valuable — and the reason it is worth re-implementing rather than rewriting from scratch — is incremental convergence: the store never re-downloads history it already has, it tracks which bar is still forming, and it repairs that bar in place until it closes. That is specified in 72-pdsp-incremental-update.spec.md.


Reading Order

Spec File What it defines
70 70-pdsp-persistence-architecture.spec.md Layer decomposition (entities → data → business → service → CLI), component contracts, state machine
71 71-pdsp-database-schema.spec.md PDSDb schema, technology-agnostic. Tables, keys, indexes, views, access patterns
72 72-pdsp-incremental-update.spec.md The incremental update algorithm. Bar identity, completeness lifecycle, range fast-path, convergence rules
73 73-pdsp-event-hooks.spec.md Event-driven architecture. In-process events, out-of-process hook contracts, CLI chaining, in-database triggers
74 74-pdsp-engine-cli.spec.md The batch engine CLI contract, argument grammar, timeframe/instrument context expansion
75 75-pdsp-in-database-export.spec.md In-database export pipeline (CSV / gzip / broker format), normalization, in-database compute
76 76-spiderdb-schema.spec.md SpiderDb schema — strategy, ordering, timeline, annotation, goal domains
77 77-message-bus.spec.md The distributed event backbone. Message envelope, publisher/subscriber contracts, topology, transport adapters, target event-driven architecture

Cross-cutting specs already in rispecs/:


Source Map — Where The Original Code Lives

Everything below is in this repository and was the basis for these specs.

Database artifacts

Artifact Path Notes
PDSDb full script export src/Caishen/Databases/SpiderDbDatabase/gia-mssql/PDSDb.script-221031.sql UTF-16LE encoded. 7,620 lines. Most complete PDSDb export (2022-10-31)
PDSDb earlier exports .../PDSDb__scriptExport__{2208091244,220907,220922}.sql Useful for diffing schema evolution
SpiderDb full script export .../SpiderDb__scriptExport__220907.sql UTF-16LE. 7,253 lines, 66 tables, 26 views, 42 procedures
SpiderDb earlier export .../SpiderDb__scriptExport__2208091252.sql  
Original creation script src/Caishen/Databases/SpiderDbDatabase/Create_SpiderDb__200424.sql The 2020-04-24 genesis script
Import variant .../gia-mssql/Create_SpiderDb__200424__220112import.sql  
Binary backups db/SpiderDb.bak, db/RESTORE/SpiderDb.bak, db/RESTORE/spiderdb_backup_2018_09_20_180829.bak, db/SpiderDb.zip ~93 MB of SQL Server backup files
BACPAC export .../gia-mssql/exports/dac-220211/spiderdb-dac-220211.bacpac Portable schema+data package
SQL project src/Caishen/Databases/SpiderDbDatabase/SpiderDbDatabase.sqlproj  

Encoding note for implementers: the *scriptExport*.sql and several .altering.sql files are UTF-16LE with BOM. Convert before grepping: iconv -f UTF-16LE -t UTF-8 in.sql > out.sql

C# implementation (the layers)

Layer Project Key files
Entities src/Caishen/PDSP/PDSP.Entities/ Entities/PDSDataProvider2203Model.PDSPPrice.cs, ...PDSPInstrumentProperty.cs, PDSPRawPriceCollection.cs, Entities/Collections/PDSPPriceCollection.cs
Data (ORM) src/Caishen/PDSP/PDSP.Data/ Ctx/PDSDataProvider2203Model.PDSEntities2203.cs — the query + persistence logic, Ctx/PDSPEntitiesExtensions.cs, Ctx/PDSPExtensions.cs
Data (direct SQL) src/Caishen/PDSP/PDSP.Data.SQL/ Model/PDSDb_SP220623_DataContext.cs, SP/CTX/PDSPExportSP221022.PDSDbSPExportDataContext.cs — stored-procedure bindings
Data (LINQ2SQL) src/Caishen/PDSP/PDSP.Data.Linq2SQL/ Ctx/PDSPricesLINQ2SQL220430.* — a second, lighter read path
Business src/Caishen/PDSP/PDSP.Business/ PDSPPriceComponent.cs (UpdateLastFrom = the incremental algorithm), PDSPPriceComponentDbContext.cs, PDSPPriceComponentFsm.cs (1,264 lines, generated state machine), PDSPPriceComponentStateEnum.cs, PDSPInstrumentPropertyComponent.cs
Contracts src/Caishen/PDSP/PDSP.Contracts/ SvcContracts/IPDSPService.cs, Dtos/PDSPPriceDto.cs, Dtos/PDSPInstrumentPropertyDto.cs
Services src/Caishen/PDSP/PDSP.Services/ PDSPHistoryServices.cs, PDSPService.cs, Converting/*Converter.cs
CLI src/Caishen/PDSP/PDSEngine2203/ Program.cs (3,055 lines — the batch engine), hooks/*.bat, plus two dated snapshots of Program.cs kept for reference
Model definition src/Caishen/PDSP/PDS.Data.Provider2203/DataModel/PDSDataProvider2203Model.edps The code-generator model that produced the .Generated.cs files

Cross-cutting supporting code

Concern Path
Bar identity / key generation src/Caishen/Common/PS.Common.Framework/PovType/BarTlider.cs
Timeframe period arithmetic src/Caishen/Common/PS.Common.Charting/DateTimeUtilities/DtChartingHelper.cs
Hook firing (in-process events) src/Caishen/PDS/PDS.Hooks/PDSHooks.cs
Hook name constants src/Caishen/Common/PS.Common.Hooks/ → HookConstants.cs
Hook scripts (out-of-process) src/Caishen/Common/PS.Common.Hooks/*.bat, src/Caishen/PDSP/PDSEngine2203/hooks/*.bat
Bus publisher/subscriber contracts src/Caishen/Common/PS.Common.StateTransitionMachineries.Std/StateForge.StateMachine/CreasTypes/IBusPublisher.cs, .../IMessageReceiver.cs
Message envelope src/Caishen/Common/PS.Common.Messages/SMEventArgsBase.cs
The working message bus src/Caishen/Common/PS.Common.Services.ServiceBus/ — MyBus171208.cs (Rebus/MSMQ), AzureBus/BusZure.cs, BDSBus*.cs
Bus domain wrappers + hub src/Caishen/GDS/GDS.PrototypeApp1712/GDSBus.cs, src/Caishen/WDS/WDS.WritingGuide.WDSLib/Services/{WDSBus,WDSServiceHub}.cs
Working end-to-end bus example src/Caishen/WDS/WDS.WriterGuide.StoreServiceApp/Program.cs
Acquisition side (broker) src/Caishen/PDS/ (see spec 03)

Deployment

Artifact Path
Database container images src/Caishen/Databases/SpiderDbDatabase/gia-mssql/ZEUS/, .../gia-server-mssql-00-base-v2019*/, .../gia-server-zeus-*/
Volume backup/restore tooling .../gia-mssql/x-volume/
Backup/restore/attach runbook .../gia-mssql/README.md, .../gia-mssql/inst__Attach__SpiderDb_from_slash_data.sql, .../gia-mssql/adm__Backup_Copy__PDSDb__220809.sql
Server initialization .../gia-mssql/svr-Initializsation-2212.sql, .../gia-mssql/inst__Enable_Machine_Learning_Services.sql, .../gia-mssql/inst__ServerRAM.sql
Index maintenance .../gia-mssql/adm__INDEX_Rebuild.sql, .../gia-mssql/adm__INDEX_Reorg.sql

Security Note For Re-implementation

The original App.config files carried SQL Server credentials inline (src/Caishen/PDSP/PDSEngine2203/App.config and siblings). Any re-implementation must externalize these to environment variables or a secret store. Treat every credential found in the historical source as compromised and rotate it — do not carry the values forward.

The in-database export procedures (spec 75) execute Python inside the database engine and shell out to bash. That is a deliberate design choice with real blast radius; spec 75 documents both the original behaviour and a safer target-architecture alternative.


Non-Goals

Projects under src/Caishen/PDSP/ deliberately not specified

Project Why omitted
PDSP.UI.WinForms Desktop retrieval-request form. UI concern — see spec 20
PDSP.Services.DevelopmentHost Developer harness for hosting the service locally
PDSP.Data.NetService Remoting client shim, superseded by the service contract in spec 70
PDSP.CsvDataSetMaker.Tests, PDSP.Services.Tests Test projects. Useful as behavioural reference when implementing spec 72’s verification matrix, but not specified
PDSP.Data.Linq2SQL A second read path over the same tables; its contract is covered by spec 70’s PriceStore
PDSEngine2203/Program-2209*.cs Dated snapshots of the engine kept alongside the live file. Two of them contain a fix the live file lacks (spec 72, defect 10) — read them for that, do not port them

Content boundaries

These specs describe what the system did and why, not how to reproduce the .NET code. They deliberately avoid:

Any target stack that can satisfy the contracts in specs 70–77 is a valid implementation.