Beispiel #1
0
        public void Parse(HttpStatusCode status, string s)
        {
            status.EnsureSuccess();
            // {
            //   "sequence": 12345,
            //   "bids": [[ "295.96", "0.05", "3b0f1225-7f84-490b-a29f-0faef9de823a" ]...],
            //   "asks": [[ "296.12", "0.17", "da863862-25f4-4868-ac41-005d11ab0a5f" ]...],
            // }
            JObject root = Json.ParseObject(s);
            Func <JArray, List <Order> > ParseOrders = (orders) =>
            {
                Condition.Requires(orders, "orders").IsNotNull();
                var res = new List <Order>();
                foreach (var order in orders)
                {
                    res.Add(new Order()
                    {
                        Id       = (string)order[2],
                        Price    = (decimal)order[0],
                        Quantity = (decimal)order[1],
                    });
                }
                return(res);
            };

            Sequence = (long)root["sequence"];
            Bids     = ParseOrders((JArray)root["bids"]);
            Asks     = ParseOrders((JArray)root["asks"]);
        }
Beispiel #2
0
        public void Parse(HttpStatusCode httpStatus, string s)
        {
            if (httpStatus == HttpStatusCode.BadRequest)
            {
                Result = NewOrderResult.Reject;
                return;
            }
            httpStatus.EnsureSuccess();
            JObject root = Json.ParseObject(s);

            OrderId = (string)root["id"];
            var status = (string)root["status"];

            Result = (string)root["status"] == "rejected" ? NewOrderResult.Reject : NewOrderResult.Success;
        }
Beispiel #3
0
 public void Parse(HttpStatusCode status, string s)
 {
     // We need to differentiate between two types of errors:
     // 1. Order can't be cancelled because it's already done (filled or cancelled).
     // 2. All other errors.
     //
     // Coinbase gives us HTTP 400 plus a JSON object with a specific message string
     // in case of (1) but the error strings aren't documented. We can either rely on the
     // exact undocumented strings or assume that HTTP 400 always means invalid order.
     // In the absence of bugs the latter assumption should hold true, so we go with it.
     if (status == HttpStatusCode.BadRequest)
     {
         Result = CancelOrderResult.InvalidOrder;
         return;
     }
     status.EnsureSuccess();
     Result = CancelOrderResult.Success;
 }
Beispiel #4
0
 public void Parse(HttpStatusCode status, string s)
 {
     status.EnsureSuccess();
     // The response contains order IDs of the cancelled orders. We don't need them.
 }
Beispiel #5
0
 public void Parse(HttpStatusCode status, string s)
 {
     status.EnsureSuccess();
     Time = (DateTime)Json.ParseObject(s)["iso"];
 }