Skip to content

Commit 7469583

Browse files
author
robaho
committed
fix issue #6 - correct handling of order state with gRPC
1 parent 35e4dba commit 7469583

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

cmd/client/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ func (MyCallback) OnOrderStatus(order *Order) {
9494
activeOrderLock.Lock()
9595
defer activeOrderLock.Unlock()
9696
activeOrders[order.Id] = order
97+
vlogf("log", "order %d is %s (active)\n", order.Id, order.OrderState)
9798
} else {
9899
activeOrderLock.Lock()
99100
defer activeOrderLock.Unlock()
100101
delete(activeOrders, order.Id)
101-
vlogf("log", "order %d is %s\n", order.Id, order.OrderState)
102+
vlogf("log", "order %d is %s (inactive)\n", order.Id, order.OrderState)
102103
}
103104
gui.Update(func(g *gocui.Gui) error {
104105
v, err := g.View("orders")

internal/exchange/grpc.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ func (c *grpcClient) SendOrderStatus(so sessionOrder) {
2626
rpt.Symbol = so.order.Symbol()
2727
rpt.ExOrdId = so.order.ExchangeId
2828
rpt.ReportType = protocol.ExecutionReport_Status
29+
switch so.order.OrderState {
30+
case New, Booked:
31+
rpt.OrderState = protocol.ExecutionReport_Booked
32+
case PartialFill:
33+
rpt.OrderState = protocol.ExecutionReport_Partial
34+
case Filled:
35+
rpt.OrderState = protocol.ExecutionReport_Filled
36+
case Cancelled:
37+
rpt.OrderState = protocol.ExecutionReport_Cancelled
38+
case Rejected:
39+
rpt.OrderState = protocol.ExecutionReport_Rejected
40+
}
41+
rpt.RejectReason = so.order.RejectReason
2942
rpt.ClOrdId = int32(so.order.Id)
3043
rpt.Quantity = ToFloat(so.order.Quantity)
3144
rpt.Price = ToFloat(so.order.Price)
@@ -69,6 +82,23 @@ func (c *grpcClient) sendTradeExecutionReport(so sessionOrder, price Fixed, quan
6982
} else {
7083
rpt.Side = protocol.CreateOrderRequest_Sell
7184
}
85+
switch so.order.OrderState {
86+
case New, Booked:
87+
rpt.OrderState = protocol.ExecutionReport_Booked
88+
case PartialFill:
89+
rpt.OrderState = protocol.ExecutionReport_Partial
90+
case Filled:
91+
rpt.OrderState = protocol.ExecutionReport_Filled
92+
case Cancelled:
93+
rpt.OrderState = protocol.ExecutionReport_Cancelled
94+
case Rejected:
95+
rpt.OrderState = protocol.ExecutionReport_Rejected
96+
}
97+
98+
if !remaining.Equal(ZERO) {
99+
rpt.OrderState = protocol.ExecutionReport_Partial
100+
}
101+
72102
rpt.Remaining = ToFloat(remaining)
73103
reply := &protocol.OutMessage_Execrpt{Execrpt: rpt}
74104
so.client.(*grpcClient).conn.Send(&protocol.OutMessage{Reply: reply})

pkg/connector/grpc/connector.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ func (c *grpcConnector) GetOrder(id OrderID) *Order {
276276
}
277277
return _order.(*Order)
278278
}
279+
279280
func (c *grpcConnector) handleExecutionReport(rpt *protocol.ExecutionReport) {
280281
exchangeId := rpt.ExOrdId
281282
var id OrderID

0 commit comments

Comments
 (0)