implemented persistence
This commit is contained in:
@@ -271,3 +271,47 @@ func TestFillerQueue_AdjustForSplit_NilReceiver(t *testing.T) {
|
||||
var fq *FillerQueue
|
||||
fq.AdjustForSplit(decimal.NewFromFloat(5)) // must not panic
|
||||
}
|
||||
|
||||
func TestNewFillerFromState(t *testing.T) {
|
||||
// The underlying Record reports very different values; NewFillerFromState
|
||||
// must ignore them and use the caller-supplied overrides instead.
|
||||
rec := &testRecord{
|
||||
quantity: decimal.NewFromFloat(999),
|
||||
price: decimal.NewFromFloat(999),
|
||||
}
|
||||
|
||||
qty := decimal.NewFromFloat(50)
|
||||
price := decimal.NewFromFloat(20)
|
||||
filled := qty // fully filled on load
|
||||
|
||||
f := NewFillerFromState(rec, qty, price, filled)
|
||||
|
||||
if !f.Quantity().Equal(qty) {
|
||||
t.Errorf("want quantity %v but got %v", qty, f.Quantity())
|
||||
}
|
||||
if !f.Price().Equal(price) {
|
||||
t.Errorf("want price %v but got %v", price, f.Price())
|
||||
}
|
||||
if !f.IsFilled() {
|
||||
t.Errorf("want IsFilled() to be true when filled == quantity")
|
||||
}
|
||||
|
||||
// Partially filled: filled < quantity => IsFilled must be false.
|
||||
partial := NewFillerFromState(rec, qty, price, decimal.NewFromFloat(10))
|
||||
if partial.IsFilled() {
|
||||
t.Errorf("want IsFilled() to be false when filled < quantity")
|
||||
}
|
||||
if !partial.Quantity().Equal(qty) {
|
||||
t.Errorf("want quantity %v but got %v", qty, partial.Quantity())
|
||||
}
|
||||
if !partial.Price().Equal(price) {
|
||||
t.Errorf("want price %v but got %v", price, partial.Price())
|
||||
}
|
||||
|
||||
// Filled from Fill() on a restored lot must work correctly against the
|
||||
// restored (not Record-derived) quantity/price.
|
||||
_, done := partial.Fill(decimal.NewFromFloat(40))
|
||||
if !done {
|
||||
t.Errorf("after filling the remaining 40, IsFilled() should be true")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user