sixth version
This commit is contained in:
@@ -25,3 +25,15 @@ func TestFreeOrderBudgetSubmittedPolicy(t *testing.T) {
|
||||
t.Fatalf("expected ErrFreeOrderBudget, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFreeOrderBudgetRequiresExplicitPolicy(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
budget := NewFreeOrderBudget(NewMemoryFreeOrderStore())
|
||||
date := time.Date(2024, 1, 2, 0, 0, 0, 0, time.UTC)
|
||||
if _, err := budget.Check(ctx, date, domain.Instrument{InstrumentUID: "uid"}, 1); !errors.Is(err, ErrFreeOrderPolicyUnspecified) {
|
||||
t.Fatalf("expected ErrFreeOrderPolicyUnspecified, got %v", err)
|
||||
}
|
||||
if _, err := budget.Check(ctx, date, domain.Instrument{InstrumentUID: "uid", FreeOrderLimitPerDay: -1}, 1); err != nil {
|
||||
t.Fatalf("explicit no-cap policy should pass, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoSizingCapacity = errors.New("no sizing capacity")
|
||||
ErrFreeOrderBudget = errors.New("free order budget is insufficient")
|
||||
ErrNoSizingCapacity = errors.New("no sizing capacity")
|
||||
ErrFreeOrderBudget = errors.New("free order budget is insufficient")
|
||||
ErrFreeOrderPolicyUnspecified = errors.New("free order policy is not configured")
|
||||
)
|
||||
|
||||
type SizingConfig struct {
|
||||
@@ -131,9 +132,12 @@ func NewFreeOrderBudget(store FreeOrderStore) FreeOrderBudget {
|
||||
}
|
||||
|
||||
func (b FreeOrderBudget) Check(ctx context.Context, tradeDate time.Time, instr domain.Instrument, ordersNeeded int) (int, error) {
|
||||
if instr.FreeOrderLimitPerDay <= 0 {
|
||||
if instr.FreeOrderLimitPerDay < 0 {
|
||||
return 0, nil
|
||||
}
|
||||
if instr.FreeOrderLimitPerDay == 0 {
|
||||
return 0, ErrFreeOrderPolicyUnspecified
|
||||
}
|
||||
sent, err := b.store.GetFreeOrdersSent(ctx, tradeDate, instr.InstrumentUID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
Reference in New Issue
Block a user