public async Task <string> Buy(string market, decimal quantity, decimal rate) { var request = new ExchangeSharp.ExchangeOrderRequest() { Amount = quantity, IsBuy = true, OrderType = ExchangeSharp.OrderType.Limit, Price = rate, Symbol = market }; var order = await _api.PlaceOrderAsync(request); return(order.OrderId); }
protected override async Task <ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { var payload = await GetNoncePayloadAsync(); 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 }
public override ExchangeOrderResult PlaceOrder(ExchangeOrderRequest order) { 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().ToString(CultureInfo.InvariantCulture.NumberFormat) }, { "price", order.Price.ToString(CultureInfo.InvariantCulture.NumberFormat) }, { "side", (order.IsBuy ? "buy" : "sell") }, { "type", "exchange limit" } }; JToken obj = MakeJsonRequest <JToken>("/order/new", null, payload); CheckError(obj); return(ParseOrder(obj)); }
protected override async Task <ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { if (order.OrderType == OrderType.Market) { throw new NotSupportedException("Order type " + order.OrderType + " not supported"); } decimal orderAmount = await ClampOrderQuantity(order.MarketSymbol, order.Amount); decimal orderPrice = await ClampOrderPrice(order.MarketSymbol, order.Price); List <object> orderParams = new List <object> { "currencyPair", order.MarketSymbol, "rate", orderPrice.ToStringInvariant(), "amount", orderAmount.ToStringInvariant() }; foreach (KeyValuePair <string, object> kv in order.ExtraParameters) { orderParams.Add(kv.Key); orderParams.Add(kv.Value); } JToken result = null; try { result = await MakePrivateAPIRequestAsync(order.IsBuy?(order.IsMargin ? "marginBuy" : "buy") : (order.IsMargin ? "marginSell" : "sell"), orderParams); } catch (Exception e) { if (!e.Message.Contains("Unable to fill order completely")) { throw; } result = JToken.FromObject(new { orderNumber = "0", currencyPair = order.MarketSymbol }); } ExchangeOrderResult exchangeOrderResult = ParsePlacedOrder(result, order); exchangeOrderResult.MarketSymbol = order.MarketSymbol; exchangeOrderResult.FeesCurrency = ParseFeesCurrency(order.IsBuy, order.MarketSymbol); return(exchangeOrderResult); }
protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { var payload = await GetNoncePayloadAsync(); //payload["clientOrderId"] = "neuMedia" + payload["nonce"]; Currently letting hitbtc assign this, but may not be unique for more than 24 hours payload["quantity"] = order.Amount; payload["symbol"] = order.MarketSymbol; payload["side"] = order.IsBuy ? "buy" : "sell"; payload["type"] = order.OrderType == OrderType.Limit ? "limit" : "market"; if (order.OrderType == OrderType.Limit) { payload["price"] = order.Price; payload["timeInForce"] = "GTC"; } order.ExtraParameters.CopyTo(payload); // { "id": 0,"clientOrderId": "d8574207d9e3b16a4a5511753eeef175","symbol": "ETHBTC","side": "sell","status": "new","type": "limit","timeInForce": "GTC","quantity": "0.063","price": "0.046016","cumQuantity": "0.000","createdAt": "2017-05-15T17:01:05.092Z","updatedAt": "2017-05-15T17:01:05.092Z" } JToken token = await MakeJsonRequestAsync<JToken>("/order", null, payload, "POST"); ExchangeOrderResult result = new ExchangeOrderResult { OrderId = token["id"].ToStringInvariant(), MarketSymbol = token["symbol"].ToStringInvariant(), OrderDate = token["createdAt"].ToDateTimeInvariant(), Amount = token["quantity"].ConvertInvariant<decimal>(), Price = token["price"].ConvertInvariant<decimal>(), AmountFilled = token["cumQuantity"].ConvertInvariant<decimal>(), Message = token["clientOrderId"].ToStringInvariant() }; if (result.AmountFilled >= result.Amount) { result.Result = ExchangeAPIOrderResult.Filled; } else if (result.AmountFilled > 0m) { result.Result = ExchangeAPIOrderResult.FilledPartially; } else { result.Result = ExchangeAPIOrderResult.Pending; } ParseAveragePriceAndFeesFromFills(result, token["tradesReport"]); return result; }
protected override async Task <ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { var roundedAmount = order.RoundAmount(); var amountInt = converterToEight.FromDecimal(roundedAmount); var feeCurrency = (order.ExtraParameters.ContainsKey("fee_currency") ? order.ExtraParameters["fee_currency"] ?? DefaultFeeCurrency : DefaultFeeCurrency) .ToString() .ToUpperInvariant(); var data = new Dictionary <string, object> { { "amount_int", amountInt }, { "type", order.IsBuy ? "bid" : "ask" }, { "fee_currency", feeCurrency }, }; switch (order.OrderType) { case OrderType.Limit: data["price_int"] = converterToFive.FromDecimal(order.Price); break; case OrderType.Market: data["amount_funds_int"] = converterToFive.FromDecimal(roundedAmount * order.Price); break; default: throw new NotSupportedException($"{order.OrderType} is not supported"); } var resultBody = await MakeRequestAsync( $"/{order.MarketSymbol}/money/order/add", payload : data ); var result = JsonConvert.DeserializeObject <BL3POrderAddResponse>(resultBody) .Except(); var orderDetails = await GetOrderDetailsAsync(result.OrderId, order.MarketSymbol); return(orderDetails); }
public override ExchangeOrderResult PlaceOrder(ExchangeOrderRequest order) { string symbol = NormalizeSymbolV1(order.Symbol); Dictionary <string, object> payload = GetNoncePayload(); payload["symbol"] = symbol; payload["amount"] = order.RoundAmount().ToStringInvariant(); payload["side"] = (order.IsBuy ? "buy" : "sell"); payload["type"] = (order.OrderType == OrderType.Market ? "exchange market" : "exchange limit"); if (order.OrderType != OrderType.Market) { payload["price"] = order.Price.ToStringInvariant(); } JToken obj = MakeJsonRequest <JToken>("/order/new", BaseUrlV1, payload); CheckError(obj); return(ParseOrder(obj)); }
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(), MarketSymbol = order.MarketSymbol }; result.AveragePrice = result.Price; result.Result = ExchangeAPIOrderResult.Pending; return(result); }
protected override async Task <ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { var account_id = await GetAccountID(order.IsMargin, order.MarketSymbol); var payload = await GetNoncePayloadAsync(); payload.Add("account-id", account_id); payload.Add("symbol", order.MarketSymbol); payload.Add("type", order.IsBuy ? "buy" : "sell"); payload.Add("source", order.IsMargin ? "margin-api" : "api"); decimal outputQuantity = await ClampOrderQuantity(order.MarketSymbol, order.Amount); decimal outputPrice = await ClampOrderPrice(order.MarketSymbol, order.Price.Value); payload["amount"] = outputQuantity.ToStringInvariant(); if (order.OrderType == OrderType.Market) { payload["type"] += "-market"; } else { payload["type"] += "-limit"; if (order.Price == null) { throw new ArgumentNullException(nameof(order.Price)); } payload["price"] = outputPrice.ToStringInvariant(); } if (order.IsPostOnly == true) { payload["timeInForce"] += "boc"; // timeInForce enum values: gtc - good till cancel,boc - book or cancel (also called as post only, or book only), ioc - immediate or cancel, fok - fill or kill } 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) { if (string.IsNullOrEmpty(order.MarketSymbol)) { throw new ArgumentNullException(nameof(order.MarketSymbol), "Okex place order request requires symbol"); } var payload = await GetNoncePayloadAsync(); payload["instId"] = order.MarketSymbol; payload["tdMode"] = order.IsMargin ? "isolated" : "cash"; if (!string.IsNullOrEmpty(order.ClientOrderId)) { payload["clOrdId"] = order.ClientOrderId; } payload["side"] = order.IsBuy ? "buy" : "sell"; payload["posSide"] = "net"; payload["ordType"] = order.OrderType switch { OrderType.Limit => "limit", OrderType.Market => "market", OrderType.Stop => throw new ArgumentException("Okex does not support stop order", nameof(order.OrderType)), _ => throw new ArgumentOutOfRangeException(nameof(order.OrderType), "Invalid order type.") }; payload["sz"] = order.Amount.ToStringInvariant(); if (order.OrderType != OrderType.Market) { if (!order.Price.HasValue) { throw new ArgumentNullException(nameof(order.Price), "Okex place order request requires price"); } payload["px"] = order.Price.ToStringInvariant(); } order.ExtraParameters.CopyTo(payload); var token = await MakeJsonRequestAsync <JToken>("/trade/order", BaseUrlV5, payload, "POST"); var orderInfo = await GetOrderDetailsAsync(token[0]["ordId"].ToStringInvariant(), order.MarketSymbol); return(orderInfo); }
protected override async Task <ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { var payload = await GetNoncePayloadAsync(); payload["clientOid"] = Guid.NewGuid(); payload["size"] = order.Amount; payload["price"] = order.Price; payload["symbol"] = order.MarketSymbol; payload["side"] = order.IsBuy ? "buy" : "sell"; order.ExtraParameters.CopyTo(payload); // {"orderOid": "596186ad07015679730ffa02" } JToken token = await MakeJsonRequestAsync <JToken>("/orders", null, payload, "POST"); return(new ExchangeOrderResult() { OrderId = token["orderId"].ToStringInvariant() }); // this is different than the oid created when filled }
public override ExchangeOrderResult PlaceOrder(ExchangeOrderRequest order) { if (order.OrderType == OrderType.Market) { throw new NotSupportedException(); } string symbol = NormalizeSymbol(order.Symbol); decimal amount = order.RoundAmount(); string url = (order.IsBuy ? "/market/buylimit" : "/market/selllimit") + "?market=" + symbol + "&quantity=" + amount.ToStringInvariant() + "&rate=" + order.Price.ToStringInvariant(); JObject obj = MakeJsonRequest <JObject>(url, null, GetNoncePayload()); JToken result = CheckError(obj); string orderId = result["uuid"].ToStringInvariant(); return(new ExchangeOrderResult { Amount = amount, IsBuy = order.IsBuy, OrderDate = DateTime.UtcNow, OrderId = orderId, Result = ExchangeAPIOrderResult.Pending, Symbol = symbol }); }
protected override async Task <ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { string symbol = NormalizeSymbolV1(order.Symbol); Dictionary <string, object> payload = await OnGetNoncePayloadAsync(); payload["symbol"] = symbol; payload["amount"] = ClampOrderQuantity(symbol, order.Amount).ToStringInvariant(); payload["side"] = (order.IsBuy ? "buy" : "sell"); payload["type"] = (order.OrderType == OrderType.Market ? "exchange market" : "exchange limit"); if (order.OrderType != OrderType.Market) { payload["price"] = ClampOrderPrice(symbol, order.Price).ToStringInvariant(); } order.ExtraParameters.CopyTo(payload); JToken obj = await MakeJsonRequestAsync <JToken>("/order/new", BaseUrlV1, payload); return(ParseOrder(obj)); }
protected override async Task <ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { decimal orderAmount = await ClampOrderQuantity(order.MarketSymbol, order.Amount); if (order.Price == null) { throw new ArgumentNullException(nameof(order.Price)); } decimal orderPrice = await ClampOrderPrice(order.MarketSymbol, order.Price.Value); string url = "/orders"; Dictionary <string, object> orderParams = await GetNoncePayloadAsync(); orderParams.Add("marketSymbol", order.MarketSymbol); orderParams.Add("direction", order.IsBuy ? "BUY" : "SELL"); orderParams.Add("type", order.OrderType == ExchangeSharp.OrderType.Market ? "MARKET" : "LIMIT"); orderParams.Add("quantity", orderAmount); if (order.OrderType == ExchangeSharp.OrderType.Limit) { orderParams.Add("limit", orderPrice); orderParams.Add("timeInForce", "GOOD_TIL_CANCELLED"); } foreach (KeyValuePair <string, object> kv in order.ExtraParameters) { orderParams.Add(kv.Key, kv.Value); } JToken result = await MakeJsonRequestAsync <JToken>(url, null, orderParams, "POST"); return(new ExchangeOrderResult { Amount = orderAmount, AmountFilled = decimal.Parse(result["fillQuantity"].ToStringInvariant()), IsBuy = order.IsBuy, OrderDate = result["createdAt"].ToDateTimeInvariant(), OrderId = result["id"].ToStringInvariant(), Result = ExchangeAPIOrderResult.Pending, MarketSymbol = result["marketSymbol"].ToStringInvariant(), Price = decimal.Parse(result["limit"].ToStringInvariant()) }); }
protected override async Task <ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { var orderType = 0; var side = order.IsBuy? 0: 1; switch (order.OrderType) { case OrderType.Market: orderType = 1; break; case OrderType.Limit: orderType = 2; break; case OrderType.Stop: orderType = 3; break; default: throw new ArgumentOutOfRangeException(); } var result = await MakeJsonRequestAsync <SendOrderResponse>("SendOrder", null, new Dictionary <string, object>() { { "InstrumentId", await GetInstrumentIdFromMarketSymbol(order.MarketSymbol) }, { "Quantity", order.Amount }, { "LimitPrice", order.Price }, { "OrderType", orderType }, { "Side", side }, { "StopPrice", order.StopPrice }, { "TimeInForce", 0 }, { "nonce", await GenerateNonceAsync() } }.Concat(order.ExtraParameters).ToDictionary(pair => pair.Key, pair => pair.Value), "POST"); if (result.Status.Equals("accepted", StringComparison.InvariantCultureIgnoreCase)) { return(await GetOrderDetailsAsync(result.OrderId.ToString())); } throw new APIException($"{result.ErrorMsg}"); }
public override ExchangeOrderResult PlaceOrder(ExchangeOrderRequest orderRequest) { string symbol = NormalizeSymbol(orderRequest.Symbol); string url = orderRequest.IsBuy ? string.Format("/buy/{0}/", symbol) : string.Format("/sell/{0}/", symbol); Dictionary <string, object> payload = GetNoncePayload(); payload["price"] = orderRequest.Price.ToStringInvariant(); payload["amount"] = orderRequest.Amount.ToStringInvariant(); JObject responseObject = MakeJsonRequest <JObject>(url, null, payload, "POST"); CheckError(responseObject); return(new ExchangeOrderResult { OrderDate = DateTime.UtcNow, OrderId = responseObject["id"].ToStringInvariant(), IsBuy = orderRequest.IsBuy, Symbol = orderRequest.Symbol }); }
protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { ExchangeOrderResult newOrder = new ExchangeOrderResult() { Result = ExchangeAPIOrderResult.Error }; var payload = GetNoncePayload(); payload["Market"] = order.Symbol; payload["Type"] = order.IsBuy ? "Buy" : "Sell"; payload["Rate"] = order.Price; payload["Amount"] = order.Amount; // { "OrderId": 23467, "FilledOrders": [44310,44311] } - They don't say what those FilledOrders are. It's possible they represent partially filled order ids for this orders. Don't know. JToken token = await MakeJsonRequestAsync<JToken>("/SubmitTrade", null, payload, "POST"); token = CheckError(token); if (token.HasValues && token["OrderId"] != null) { newOrder.OrderId = token["OrderId"].ConvertInvariant<int>().ToStringInvariant(); newOrder.Result = ExchangeAPIOrderResult.Pending; // Might we change this depending on what the filled orders are? } return newOrder; }
public void Test() { try { var or = new ExchangeOrderRequest() { IsBuy = false, MarketSymbol = "VITAE_BTC", Amount = 0.5m, Price = 0.1m }; var co = OnPlaceOrderAsync(or).Result; var o = OnGetOpenOrderDetailsAsync("VITAE_BTC").Result; OnCancelOrderAsync(o.First().OrderId).Wait(); } catch (Exception ex) { throw ex; } }
public override ExchangeOrderResult PlaceOrder(ExchangeOrderRequest order) { string symbol = NormalizeSymbol(order.Symbol); Dictionary <string, object> payload = GetNoncePayload(); payload["symbol"] = symbol; payload["side"] = (order.IsBuy ? "BUY" : "SELL"); payload["type"] = order.OrderType.ToString().ToUpperInvariant(); payload["quantity"] = order.RoundAmount(); if (order.OrderType != OrderType.Market) { payload["timeInForce"] = "GTC"; payload["price"] = order.Price; } JToken token = MakeJsonRequest <JToken>("/order", BaseUrlPrivate, payload, "POST"); CheckError(token); return(ParseOrder(token)); }
protected override async Task <ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { if (order.IsPostOnly != null) { throw new NotImplementedException("Post Only orders are not supported by this exchange or not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature."); } var payload = await GetNoncePayloadAsync(); payload.Add("method", "Trade"); payload.Add("pair", order.MarketSymbol); 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 = CryptoUtility.UtcNow, // since they don't pass it back AmountFilled = token["received"].ConvertInvariant <decimal>(), }; result.Amount = token["remains"].ConvertInvariant <decimal>() + result.AmountFilled.Value; if (result.Amount == result.AmountFilled) { result.Result = ExchangeAPIOrderResult.Filled; } else if (result.AmountFilled == 0m) { result.Result = ExchangeAPIOrderResult.Open; } else { result.Result = ExchangeAPIOrderResult.FilledPartially; } return(result); }
//PlaceOrder 9 protected override async Task <ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { if (order.IsPostOnly != null) { throw new NotSupportedException("Post Only orders are not supported by this exchange or not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature."); } Dictionary <string, object> payload = new Dictionary <string, object> { { "amount", order.Amount }, { "api_key", PublicApiKey.ToUnsecureString() }, { "price", order.Price }, { "symbol", order.MarketSymbol }, { "type", order.IsBuy ? "buy" : "sell" } }; JToken resp = await MakeJsonRequestAsync <JToken>("/create_order.do", null, payload, "POST"); CheckResponseToken(resp); return(ParsePlaceOrder(resp, payload)); }
protected override async Task <ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { if (order.OrderType == OrderType.Stop) { throw new NotSupportedException("Bitbank does not support stop order"); } Dictionary <string, object> payload = await GetNoncePayloadAsync(); if (order.IsPostOnly != null) { payload["post_only"] = order.IsPostOnly; } payload.Add("pair", NormalizeMarketSymbol(order.MarketSymbol)); payload.Add("amount", order.Amount.ToStringInvariant()); payload.Add("side", order.IsBuy ? "buy" : "sell"); payload.Add("type", order.OrderType.ToStringLowerInvariant()); payload.Add("price", order.Price); JToken token = await MakeJsonRequestAsync <JToken>("/user/spot/order", baseUrl : BaseUrlPrivate, payload : payload, requestMethod : "POST"); return(ParseOrder(token)); }
protected override async Task <ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { string ordertype = "/exchange/"; if (order.OrderType == OrderType.Market) { ordertype += order.IsBuy ? "buymarket" : "sellmarket"; } else { ordertype += order.IsBuy ? "buylimit" : "selllimit"; } //{ "success": true, "added": true, "orderId": 4912 JToken token = await MakeJsonRequestAsync <JToken>(string.Format("{0}?currencyPair={1}&price={2}&quantity={3}", ordertype, order.Symbol, order.Price, order.Amount), null, GetNoncePayload(), "POST"); token = CheckError(token); return(new ExchangeOrderResult() { OrderId = token["orderId"].ToStringInvariant(), Result = ExchangeAPIOrderResult.Pending }); }
protected override async Task <ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { object nonce = await GenerateNonceAsync(); Dictionary <string, object> payload = new Dictionary <string, object> { { "nonce", nonce }, { "type", order.OrderType.ToStringLowerInvariant() }, { "side", (order.IsBuy ? "buy" : "sell") }, { "product_id", order.MarketSymbol }, { "size", order.RoundAmount().ToStringInvariant() } }; payload["time_in_force"] = "GTC"; // good til cancel payload["price"] = order.Price.ToStringInvariant(); switch (order.OrderType) { case OrderType.Limit: // set payload["post_only"] to true for default scenario when order.ExtraParameters["post_only"] is not specified // to place non-post-only limit order one can set and pass order.ExtraParameters["post_only"]="false" payload["post_only"] = order.ExtraParameters.TryGetValueOrDefault("post_only", "true"); break; case OrderType.Stop: payload["stop"] = (order.IsBuy ? "entry" : "loss"); payload["stop_price"] = order.StopPrice.ToStringInvariant(); payload["type"] = order.Price > 0m ? "limit" : "market"; break; case OrderType.Market: default: break; } order.ExtraParameters.CopyTo(payload); JToken result = await MakeJsonRequestAsync <JToken>("/orders", null, payload, "POST"); return(ParseOrder(result)); }
public override ExchangeOrderResult PlaceOrder(ExchangeOrderRequest order) { string symbol = NormalizeSymbol(order.Symbol); Dictionary <string, object> payload = new Dictionary <string, object> { { "nonce", GenerateNonce() }, { "type", order.OrderType.ToString().ToLowerInvariant() }, { "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(); } JObject result = MakeJsonRequest <JObject>("/orders", null, payload, "POST"); return(ParseOrder(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) { ExchangeOrderResult result = new ExchangeOrderResult() { Result = ExchangeAPIOrderResult.Error }; var payload = await GetNoncePayloadAsync(); order.ExtraParameters.CopyTo(payload); // Only limit order is supported - no indication on how it is filled JToken token = await MakeJsonRequestAsync <JToken>((order.IsBuy ? "/market/buylimit?" : "market/selllimit?") + "market=" + order.MarketSymbol + "&rate=" + order.Price.ToStringInvariant() + "&quantity=" + order.RoundAmount().ToStringInvariant(), null, payload); if (token.HasValues) { // Only the orderid is returned on success result.OrderId = token["orderid"].ToStringInvariant(); result.Result = ExchangeAPIOrderResult.Filled; } return(result); }
protected override async Task <ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrderRequest order) { string symbol = NormalizeSymbol(order.Symbol); var account_id = await GetAccountID(order.IsMargin, order.Symbol); var payload = await GetNoncePayloadAsync(); payload.Add("account-id", account_id); 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) { string symbol = NormalizeSymbolV1(order.Symbol); Dictionary <string, object> payload = GetNoncePayload(); payload["symbol"] = symbol; payload["amount"] = order.RoundAmount().ToStringInvariant(); payload["side"] = (order.IsBuy ? "buy" : "sell"); payload["type"] = (order.OrderType == OrderType.Market ? "exchange market" : "exchange limit"); if (order.OrderType != OrderType.Market) { payload["price"] = order.Price.ToStringInvariant(); } foreach (var kv in order.ExtraParameters) { payload[kv.Key] = kv.Value; } JToken obj = await MakeJsonRequestAsync <JToken>("/order/new", BaseUrlV1, payload); CheckError(obj); return(ParseOrder(obj)); }