core: add order update trigger channel

This commit is contained in:
c9s 2023-07-05 15:51:29 +08:00
parent e19aa8fa10
commit 1abb301af1
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 9 additions and 0 deletions

View File

@ -15,12 +15,14 @@ type OrderStore struct {
RemoveCancelled bool
RemoveFilled bool
AddOrderUpdate bool
C chan types.Order
}
func NewOrderStore(symbol string) *OrderStore {
return &OrderStore{
Symbol: symbol,
orders: make(map[uint64]types.Order),
C: make(chan types.Order),
}
}
@ -129,6 +131,7 @@ func (s *OrderStore) BindStream(stream types.Stream) {
}
func (s *OrderStore) HandleOrderUpdate(order types.Order) {
switch order.Status {
case types.OrderStatusNew, types.OrderStatusPartiallyFilled, types.OrderStatusFilled:
@ -152,4 +155,9 @@ func (s *OrderStore) HandleOrderUpdate(order types.Order) {
case types.OrderStatusRejected:
s.Remove(order)
}
select {
case s.C <- order:
default:
}
}

View File

@ -66,6 +66,7 @@ func (m Market) TruncateQuantity(quantity fixedpoint.Value) fixedpoint.Value {
qf := math.Trunc(quantity.Float64() * pow10)
qf = qf / pow10
qs := strconv.FormatFloat(qf, 'f', prec, 64)
return fixedpoint.MustNewFromString(qs)
}