<p style="font-size:small;">Content-Length: 3251 | <a href="http://clevelandohioweatherforecast.com//pFad.php?u=" style="font-size:small;">pFad</a> | <a href="http://github.com/robaho/go-trader/commit/7469583687ed04882775e556240e07a75ffd19d4.patch" style="font-size:small;">http://github.com/robaho/go-trader/commit/7469583687ed04882775e556240e07a75ffd19d4.patch</a></p>ED

From 7469583687ed04882775e556240e07a75ffd19d4 Mon Sep 17 00:00:00 2001
From: robaho <rengels@ix.netcom.com>
Date: Fri, 24 Jan 2020 00:12:59 -0600
Subject: [PATCH] fix issue #6 - correct handling of order state with gRPC

---
 cmd/client/main.go              |  3 ++-
 internal/exchange/grpc.go       | 30 ++++++++++++++++++++++++++++++
 pkg/connector/grpc/connector.go |  1 +
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/cmd/client/main.go b/cmd/client/main.go
index 25c96ef..75dfb5f 100644
--- a/cmd/client/main.go
+++ b/cmd/client/main.go
@@ -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")
diff --git a/internal/exchange/grpc.go b/internal/exchange/grpc.go
index d7b9917..bd86638 100644
--- a/internal/exchange/grpc.go
+++ b/internal/exchange/grpc.go
@@ -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)
@@ -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})
diff --git a/pkg/connector/grpc/connector.go b/pkg/connector/grpc/connector.go
index c4480df..4bf4a68 100644
--- a/pkg/connector/grpc/connector.go
+++ b/pkg/connector/grpc/connector.go
@@ -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
<!-- URL input box at the bottom -->
<form method="GET" action="">
    <label for="targeturl-bottom"><b>Enter URL:</b></label>
    <input type="text" id="targeturl-bottom" name="u" value="http://github.com/robaho/go-trader/commit/7469583687ed04882775e556240e07a75ffd19d4.patch" required><br><small>
    <label for="useWeserv-bottom">Disable Weserv Image Reduction:</label>
    <input type="checkbox" id="useWeserv-bottom" name="useWeserv" value="false"><br>
    <label for="stripJS-bottom">Strip JavaScript:</label>
    <input type="checkbox" id="stripJS-bottom" name="stripJS" value="true"><br>
    <label for="stripImages-bottom">Strip Images:</label>
    <input type="checkbox" id="stripImages-bottom" name="stripImages" value="true"><br>
    <label for="stripFnts-bottom">Stripout Font Forcing:</label>
    <input type="checkbox" id="stripFnts-bottom" name="stripFnts" value="true"><br>
    <label for="stripCSS-bottom">Strip CSS:</label>
    <input type="checkbox" id="stripCSS-bottom" name="stripCSS" value="true"><br>
    <label for="stripVideos-bottom">Strip Videos:</label>
    <input type="checkbox" id="stripVideos-bottom" name="stripVideos" value="true"><br>
    <label for="removeMenus-bottom">Remove Headers and Menus:</label>
    <input type="checkbox" id="removeMenus-bottom" name="removeMenus" value="true"><br></small>
<!-- New form elements Sandwich Strip -->
        <label for="start"><small>Remove from after:</label>
        <input type="text" id="start" name="start" value="<body>">
        <label for="end"><small>to before:</label>
        <input type="text" id="end" name="end">
        <input type="checkbox" id="applySandwichStrip" name="applySandwichStrip" value="1" onclick="submitForm()"> ApplySandwichStrip<br></small>
    <button type="submit">Fetch</button>
</form><!-- Header banner at the bottom -->
<p><h1><a href="http://clevelandohioweatherforecast.com//pFad.php?u=" title="pFad">pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <i>Saves Data!</i></a></h1><br><em>--- a PPN by Garber Painting Akron. <b> With Image Size Reduction </b>included!</em></p><p>Fetched URL: <a href="http://github.com/robaho/go-trader/commit/7469583687ed04882775e556240e07a75ffd19d4.patch" target="_blank">http://github.com/robaho/go-trader/commit/7469583687ed04882775e556240e07a75ffd19d4.patch</a></p><p>Alternative Proxies:</p><p><a href="http://clevelandohioweatherforecast.com/php-proxy/index.php?q=http://github.com/robaho/go-trader/commit/7469583687ed04882775e556240e07a75ffd19d4.patch" target="_blank">Alternative Proxy</a></p><p><a href="http://clevelandohioweatherforecast.com/pFad/index.php?u=http://github.com/robaho/go-trader/commit/7469583687ed04882775e556240e07a75ffd19d4.patch&useWeserv=true" target="_blank">pFad Proxy</a></p><p><a href="http://clevelandohioweatherforecast.com/pFad/v3index.php?u=http://github.com/robaho/go-trader/commit/7469583687ed04882775e556240e07a75ffd19d4.patch&useWeserv=true" target="_blank">pFad v3 Proxy</a></p><p><a href="http://clevelandohioweatherforecast.com/pFad/v4index.php?u=http://github.com/robaho/go-trader/commit/7469583687ed04882775e556240e07a75ffd19d4.patch&useWeserv=true" target="_blank">pFad v4 Proxy</a></p>