protected override async Task <ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { var payload = await OnGetNoncePayloadAsync(); payload["amount"] = order.Amount; payload["price"] = order.Price; payload["symbol"] = order.Symbol; payload["type"] = order.IsBuy ? "BUY" : "SELL"; order.ExtraParameters.CopyTo(payload); // {"orderOid": "596186ad07015679730ffa02" } JToken token = await MakeJsonRequestAsync <JToken>("/order?" + CryptoUtility.GetFormForPayload(payload, false), null, payload, "POST"); return(new ExchangeOrderResult() { OrderId = token["orderOid"].ToStringInvariant() }); // this is different than the oid created when filled }
private ExchangeOrderResult ParsePlaceOrder(JToken token, ExchangeOrderRequest order) { /* * {"result":true,"order_id":123456} */ ExchangeOrderResult result = new ExchangeOrderResult { Amount = order.Amount, Price = order.Price, IsBuy = order.IsBuy, OrderId = token["order_id"].ToStringInvariant(), Symbol = order.Symbol }; result.AveragePrice = result.Price; result.Result = ExchangeAPIOrderResult.Pending; return(result); }
private ExchangeOrderResult ParsePlaceOrder(JToken token, ExchangeOrderRequest order) { /* * { * "status": "ok", * "data": "59378" * } */ ExchangeOrderResult result = new ExchangeOrderResult { Amount = order.Amount, Price = order.Price, IsBuy = order.IsBuy, OrderId = token.ToStringInvariant(), Symbol = order.Symbol }; result.AveragePrice = result.Price; result.Result = ExchangeAPIOrderResult.Pending; return(result); }
protected override async Task <ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { string symbol = NormalizeSymbol(order.Symbol); var accounts = await OnGetAccountsAsync(); var payload = await OnGetNoncePayloadAsync(); payload.Add("account-id", order.IsMargin ? accounts["margin"] : accounts["spot"]); payload.Add("symbol", symbol); payload.Add("type", order.IsBuy ? "buy" : "sell"); payload.Add("source", order.IsMargin ? "margin-api" : "api"); payload["method"] = "POST"; decimal outputQuantity = await ClampOrderQuantity(symbol, order.Amount); decimal outputPrice = await ClampOrderPrice(symbol, order.Price); payload["amount"] = outputQuantity.ToStringInvariant(); if (order.OrderType == OrderType.Market) { payload["type"] += "-market"; } else { payload["type"] += "-limit"; payload["price"] = outputPrice.ToStringInvariant(); } order.ExtraParameters.CopyTo(payload); JToken obj = await MakeJsonRequestAsync <JToken>("/order/orders/place", PrivateUrlV1, payload, "POST"); order.Amount = outputQuantity; order.Price = outputPrice; return(ParsePlaceOrder(obj, order)); }
protected override async Task <ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { string symbol = NormalizeSymbol(order.Symbol); Dictionary <string, object> payload = new Dictionary <string, object> { { "nonce", GenerateNonce() }, { "type", order.OrderType.ToStringLowerInvariant() }, { "side", (order.IsBuy ? "buy" : "sell") }, { "product_id", symbol }, { "size", order.RoundAmount().ToStringInvariant() } }; if (order.OrderType != OrderType.Market) { payload["time_in_force"] = "GTC"; // good til cancel payload["price"] = order.Price.ToStringInvariant(); } order.ExtraParameters.CopyTo(payload); JToken result = await MakeJsonRequestAsync <JToken>("/orders", null, payload, "POST"); return(ParseOrder(result)); }
protected override async Task <ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { var payload = await OnGetNoncePayloadAsync(); payload.Add("method", "Trade"); payload.Add("pair", order.Symbol); payload.Add("type", order.IsBuy ? "buy" : "sell"); payload.Add("rate", order.Price); payload.Add("amount", order.Amount); order.ExtraParameters.CopyTo(payload); // "return":{"received":0.1,"remains":0,"order_id":12345,"funds":{"btc":15,"ltc":51.82, "nvc":0, ... }} JToken token = await MakeJsonRequestAsync <JToken>("/", PrivateURL, payload, "POST"); ExchangeOrderResult result = new ExchangeOrderResult() { OrderId = token["order_id"].ToStringInvariant(), OrderDate = DateTime.UtcNow, // since they don't pass it back AmountFilled = token["received"].ConvertInvariant <decimal>(), }; result.Amount = token["remains"].ConvertInvariant <decimal>() + result.AmountFilled; if (result.Amount == result.AmountFilled) { result.Result = ExchangeAPIOrderResult.Filled; } else if (result.AmountFilled == 0m) { result.Result = ExchangeAPIOrderResult.Pending; } else { result.Result = ExchangeAPIOrderResult.FilledPartially; } return(result); }
protected override async Task <ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { if (order.OrderType == OrderType.Market) { throw new NotSupportedException("Order type " + order.OrderType + " not supported"); } string symbol = NormalizeSymbol(order.Symbol); Dictionary <string, object> payload = new Dictionary <string, object> { { "nonce", GenerateNonce() }, { "client_order_id", "ExchangeSharp_" + DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture) }, { "symbol", symbol }, { "amount", order.RoundAmount().ToStringInvariant() }, { "price", order.Price.ToStringInvariant() }, { "side", (order.IsBuy ? "buy" : "sell") }, { "type", "exchange limit" } }; order.ExtraParameters.CopyTo(payload); JToken obj = await MakeJsonRequestAsync <JToken>("/order/new", null, payload); return(ParseOrder(obj)); }