package internal import ( "context" "encoding/json" "github.com/shopspring/decimal" ) // StateVersion is the schema version of the persisted State struct. const StateVersion = "2" // State is the platform-agnostic representation of the buy-queue state that is // written to disk after a successful run and reloaded on the next run. type State struct { Version string `json:"version"` Platform string `json:"platform"` Queues map[string][]persistedFiller `json:"queues"` } // persistedFiller is the on-disk representation of a single Filler. The // Record-specific data is kept as opaque bytes so the internal package does // not need to know about any broker package's concrete Record type. type persistedFiller struct { RecordData json.RawMessage `json:"record_data"` Quantity decimal.Decimal `json:"quantity"` Price decimal.Decimal `json:"price"` Filled decimal.Decimal `json:"filled"` } // RecordEncoder encodes a Record into its broker-specific JSON representation. type RecordEncoder interface { MarshalRecord(context.Context, Record) (json.RawMessage, error) } // RecordDecoder decodes broker-specific JSON back into a Record. type RecordDecoder interface { UnmarshalRecord(context.Context, json.RawMessage) (Record, error) } // RecordSerializer composes encoding and decoding of Records. Broker packages // own the implementation so that lazy/closured Record fields can be re-wired // on load. type RecordSerializer interface { RecordEncoder RecordDecoder }