Badges / coveralls (push) Successful in 1m4s
Allow us to generate year over year reports without having to rerun everything from the beginning. Co-authored-by: Natercio Moniz <[email protected]>
47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package internal
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/shopspring/decimal"
|
|
)
|
|
|
|
// StateVersion is the schema version of the persisted State struct.
|
|
const StateVersion = "1"
|
|
|
|
// 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 []byte `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 byte representation.
|
|
type RecordEncoder interface {
|
|
MarshalRecord(context.Context, Record) ([]byte, error)
|
|
}
|
|
|
|
// RecordDecoder decodes broker-specific bytes back into a Record.
|
|
type RecordDecoder interface {
|
|
UnmarshalRecord(context.Context, []byte) (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
|
|
}
|