public async Task PlaceOrders(ConditionalOrderParam conditionalOrderParam)
        {
            Config.SaveConditionalOrderParam(conditionalOrderParam);

            foreach (TrailingOrder order in Global._previewOrders)
            {
                order.TargetOrPercent = conditionalOrderParam.TargetOrPercent;
                order.ProfitParam     = order.TargetOrPercent
                    ? conditionalOrderParam.ProfitTarget : conditionalOrderParam.ProfitPercent;
                order.TrailingStopBuyDistance = conditionalOrderParam.Distance;
                order.Fee = conditionalOrderParam.Fee;
            }

            var notPlacedOrders = new List <TrailingOrder>();

            string response = await NetHelper.SendMultiOrders(
                Global.API_PUBLIC_KEY, Global.API_SECRET_KEY, true, Global._previewOrders);

            if (string.IsNullOrEmpty(response))
            {
                notPlacedOrders.AddRange(Global._previewOrders);
            }
            else
            {
                Helper.Log(string.Format("create multi sell orders {0}", response));
                dynamic data            = JsonConvert.DeserializeObject(response);
                dynamic orders_response = data[4];
                var     index           = 0;
                foreach (dynamic order_reponse in orders_response)
                {
                    if (order_reponse[6] != "SUCCESS")
                    {
                        Helper.Log($"Not success in creating order {order_reponse[7]}");
                        notPlacedOrders.Add(Global._previewOrders.ElementAt(index));
                    }
                    else
                    {
                        var pendingOrder = Global._previewOrders.ElementAt(index);
                        pendingOrder.LinkedSellOrderId = Convert.ToString(order_reponse[4][0][0]);
                        lock (Global._pendingOrders)
                        {
                            Global._pendingOrders.Add(pendingOrder);
                        }
                    }
                    index++;
                }
            }

            Global._previewOrders.Clear();
            if (notPlacedOrders.Count > 0)
            {
                Global._previewOrders.AddRange(notPlacedOrders);
            }

            Helper.Log(string.Format("Place orders {0}",
                                     string.Join <TrailingOrder>(Environment.NewLine, Global._previewOrders)));
        }
Esempio n. 2
0
        public static bool SaveConditionalOrderParam(ConditionalOrderParam conditionalOrderParam)
        {
            Helper.Log("Saving conditional order param to config file...");
            Configuration conf = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            AddConf(conf, "PROFIT_TARGET", Convert.ToString(conditionalOrderParam.ProfitTarget));
            AddConf(conf, "PROFIT_PERCENT", Convert.ToString(conditionalOrderParam.ProfitPercent));
            AddConf(conf, "DISTANCE", Convert.ToString(conditionalOrderParam.Distance));
            AddConf(conf, "FEE", Convert.ToString(conditionalOrderParam.Fee));
            AddConf(conf, "TARGET_OR_PERCENT", Convert.ToString(conditionalOrderParam.TargetOrPercent));
            conf.Save(ConfigurationSaveMode.Full);
            ConfigurationManager.RefreshSection("appSettings");
            Helper.Log("Saved conditional order param to config file...");
            return(true);
        }
Esempio n. 3
0
        private void btnPlaceOrders_Click(object sender, EventArgs e)
        {
            var handler = UIEventListener;

            if (handler != null)
            {
                ConditionalOrderParam condOrderParam = new ConditionalOrderParam
                {
                    ProfitTarget    = (double)spinProfitTarget.Value,
                    ProfitPercent   = (double)spinProfitPercent.Value,
                    Distance        = (double)spinDistance.Value,
                    Fee             = (double)spinFee.Value,
                    TargetOrPercent = radioProfitTarget.Checked
                };
                handler(UI_EVENT.PLACE_CLICK, condOrderParam);
            }
        }