public override void trade(CStrategy strategy, int?leg, OrderSide?side, CProduct product, Double size, Double price) { try { server.AddLog("Init " + side + " " + product.Symbol + " Trade on " + api.Name); ExchangeTicker ticker = api.GetTicker(product.Symbol); ExchangeOrderResult result = api.PlaceOrder(new ExchangeOrderRequest { Amount = (Decimal)size, IsBuy = (side == OrderSide.Buy), Price = (Decimal)price, Symbol = product.Symbol }); System.Threading.Thread.Sleep(100); String orderID = result.OrderId; server.AddLog("Calling Order OrderID: " + result.OrderId + " Date: " + result.OrderDate + " Result: " + result.Result); COrder order = new COrder(orderID); order.Product = product; order.Side = side.GetValueOrDefault(); order.Size = size; order.Price = price; String orderStatus = result.Result.ToString(); if (orderStatus.Equals("OK") || orderStatus.Equals("Sent")) { order.Status = COrder.OrderState.Sent; } else { order.Status = COrder.OrderState.Unknown; } order.Strategy = strategy; order.Exchange = this; order.TimeStampSent = result.OrderDate; server.AddLog("Created Order " + this.Name + " " + orderID + " " + product + " " + side + " " + size + " " + price); // add order to global Orders server.colServerOrders.Add(order); server.dctIdToOrder[orderID] = order; // add order to strategy orders strategy.DctStrategyOrders[orderID] = order; if (leg != null) { strategy.DctLegToOrder[(int)leg] = order; } // cleanup order.updateGUI(); } catch (Exception ex) { server.AddLog(ex.Message); } }
public override async void trade(CStrategy strategy, int?leg, OrderSide?side, CProduct product, Double size, Double price) { try { String endpoint = "/v1/order"; Dictionary <string, string> parameters = new Dictionary <string, string> { { "amount", size.ToString() }, { "price", price.ToString() }, { "symbol", product.Symbol }, { "type", side.GetValueOrDefault().ToString().ToUpper() } }; HttpRequestMessage requestMessage = KuCoinPrivate(endpoint, parameters, HttpMethod.Post); // Create a client HttpClient httpClient = new HttpClient(); // Send the request to the server HttpResponseMessage response = await httpClient.SendAsync(requestMessage); // get json back string json = await response.Content.ReadAsStringAsync(); // parse order String dynamic orderData = JsonConvert.DeserializeObject(json); String orderID; try { orderID = orderData.data.orderOid; } catch (Exception ex) { server.AddLog(ex.Message); orderID = ""; } if (!orderID.Equals("")) { COrder order = new COrder(orderID); order.Product = product; order.Side = side.GetValueOrDefault(); order.Size = size; order.Price = price; String orderStatus = orderData.msg.ToString(); if (orderStatus.Equals("OK") || orderStatus.Equals("Sent")) { order.Status = COrder.OrderState.Sent; } else { order.Status = COrder.OrderState.Unknown; } order.Strategy = strategy; order.Exchange = this; Double timeStamp = orderData.timestamp; order.TimeStampSent = CHelper.ConvertFromUnixTimestamp(timeStamp); server.AddLog("Created Order " + this.Name + " " + orderID + " " + product + " " + side + " " + size + " " + price); // add order to global Orders server.colServerOrders.Add(order); server.dctIdToOrder[orderID] = order; // add order to strategy orders strategy.DctStrategyOrders[orderID] = order; if (leg != null) { strategy.DctLegToOrder[(int)leg] = order; } // cleanup order.updateGUI(); server.AddLog(json); } } catch (Exception ex) { server.AddLog(ex.Message); } }
public abstract void trade(CStrategy strategy, int?leg, OrderSide?side, CProduct product, Double size, Double price);