Content-Length: 302611 | pFad | http://github.com/robaho/go-trader/commit/7469583687ed04882775e556240e07a75ffd19d4

06 fix issue #6 - correct handling of order state with gRPC · robaho/go-trader@7469583 · GitHub
Skip to content

Commit

Permalink
fix issue #6 - correct handling of order state with gRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
robaho committed Jan 24, 2020
1 parent 35e4dba commit 7469583
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ func (MyCallback) OnOrderStatus(order *Order) {
activeOrderLock.Lock()
defer activeOrderLock.Unlock()
activeOrders[order.Id] = order
vlogf("log", "order %d is %s (active)\n", order.Id, order.OrderState)
} else {
activeOrderLock.Lock()
defer activeOrderLock.Unlock()
delete(activeOrders, order.Id)
vlogf("log", "order %d is %s\n", order.Id, order.OrderState)
vlogf("log", "order %d is %s (inactive)\n", order.Id, order.OrderState)
}
gui.Update(func(g *gocui.Gui) error {
v, err := g.View("orders")
Expand Down
30 changes: 30 additions & 0 deletions internal/exchange/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ func (c *grpcClient) SendOrderStatus(so sessionOrder) {
rpt.Symbol = so.order.Symbol()
rpt.ExOrdId = so.order.ExchangeId
rpt.ReportType = protocol.ExecutionReport_Status
switch so.order.OrderState {
case New, Booked:
rpt.OrderState = protocol.ExecutionReport_Booked
case PartialFill:
rpt.OrderState = protocol.ExecutionReport_Partial
case Filled:
rpt.OrderState = protocol.ExecutionReport_Filled
case Cancelled:
rpt.OrderState = protocol.ExecutionReport_Cancelled
case Rejected:
rpt.OrderState = protocol.ExecutionReport_Rejected
}
rpt.RejectReason = so.order.RejectReason
rpt.ClOrdId = int32(so.order.Id)
rpt.Quantity = ToFloat(so.order.Quantity)
rpt.Price = ToFloat(so.order.Price)
Expand Down Expand Up @@ -69,6 +82,23 @@ func (c *grpcClient) sendTradeExecutionReport(so sessionOrder, price Fixed, quan
} else {
rpt.Side = protocol.CreateOrderRequest_Sell
}
switch so.order.OrderState {
case New, Booked:
rpt.OrderState = protocol.ExecutionReport_Booked
case PartialFill:
rpt.OrderState = protocol.ExecutionReport_Partial
case Filled:
rpt.OrderState = protocol.ExecutionReport_Filled
case Cancelled:
rpt.OrderState = protocol.ExecutionReport_Cancelled
case Rejected:
rpt.OrderState = protocol.ExecutionReport_Rejected
}

if !remaining.Equal(ZERO) {
rpt.OrderState = protocol.ExecutionReport_Partial
}

rpt.Remaining = ToFloat(remaining)
reply := &protocol.OutMessage_Execrpt{Execrpt: rpt}
so.client.(*grpcClient).conn.Send(&protocol.OutMessage{Reply: reply})
Expand Down
1 change: 1 addition & 0 deletions pkg/connector/grpc/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ func (c *grpcConnector) GetOrder(id OrderID) *Order {
}
return _order.(*Order)
}

func (c *grpcConnector) handleExecutionReport(rpt *protocol.ExecutionReport) {
exchangeId := rpt.ExOrdId
var id OrderID
Expand Down

0 comments on commit 7469583

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/robaho/go-trader/commit/7469583687ed04882775e556240e07a75ffd19d4

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy