コード例 #1
0
ファイル: Client.cs プロジェクト: kwood/ExchangeApi
        void CancelOrder(IReader <IMessageIn> reader, IWriter <IMessageOut> writer, Product product, long orderId)
        {
            var req = new CancelOrderRequest()
            {
                Product = product, OrderId = orderId
            };

            writer.Send(req);
            var deadline = DateTime.UtcNow + CancelTimeout;

            while (true)
            {
                TimestampedMsg <IMessageIn> resp;
                if (!reader.PeekWithTimeout(DateTime.UtcNow - deadline, out resp))
                {
                    throw new Exception("Timed out waiting for response to our order cancellation request");
                }
                var reply = resp.Value as CancelOrderResponse;
                if (reply != null)
                {
                    if (reply.Error.HasValue &&
                        reply.Error.Value != ErrorCode.OrderDoesNotExist1 &&
                        reply.Error.Value != ErrorCode.OrderDoesNotExist2)
                    {
                        throw new Exception(String.Format("Unable to cancel order {0}: {1}", orderId, reply));
                    }
                    // We need to consume the response so that it doesn't confuse Gateway.
                    reader.Consume();
                    break;
                }
                reader.Skip();
            }
        }
コード例 #2
0
ファイル: Client.cs プロジェクト: kwood/ExchangeApi
 // See Send() above.
 public void Send(CancelOrderRequest req, Action <TimestampedMsg <CancelOrderResponse> > done)
 {
     _gateway.Send(req, CastCallback(done));
 }