コード例 #1
0
        public dynamic OrderDataForApi(bool isSell)
        {
            var market_price = TickerAgent.TickerPrice(Symbol);

            dynamic orderData = new List <dynamic>();

            orderData.Add("on");
            dynamic orderBody = new System.Dynamic.ExpandoObject();

            orderBody.type   = (isSell ? SellType : BuyType);
            orderBody.symbol = Symbol;
            if (orderBody.type == "TRAILING STOP")
            {
                orderBody.price = Convert.ToString(Math.Abs(Price - market_price));
            }
            else
            {
                orderBody.price = Convert.ToString(Price);
            }

            orderBody.amount = Convert.ToString(isSell ? -SellAmount : BuyAmount);
            orderBody.flags  = 0;
            orderData.Add(orderBody);

            return(orderData);
        }
コード例 #2
0
        public MainController()
        {
            Config.LoadConfig();
            MainUI.UIEventListener += new UIEvent(this.OnUIEvent);

            _orderAgent     = new OrderAgent();
            _subscribeAgent = new SubscribeAgent();
            _subscribeAgent.ActionWalletSnapshot   = this.WalletSnapshot;
            _subscribeAgent.ActionWalletUpdate     = this.WalletUpdate;
            _subscribeAgent.ActionOrderSnapshot    = this.OrderSnapshot;
            _subscribeAgent.ActionOrderUpdate      = this.OrderUpdate;
            _subscribeAgent.ActionPositionSnapshot = this.PositionSnapshot;
            _subscribeAgent.ActionPositionUpdate   = this.PositionUpdate;
            _tickerAgent = new TickerAgent();
        }
コード例 #3
0
        public List <string> PreviewOrders(ShortOrderParam shortOrderParam)
        {
            Helper.Log(string.Format("Making orders preview with input {0}...", shortOrderParam.ToString()));
            var previews = new List <string>();
            var ticker   = shortOrderParam.TickerChoice;

            if (ticker == null)
            {
                return(previews);
            }

            Config.SaveShortOrderParams(shortOrderParam);
            var    market_price       = TickerAgent.TickerPrice(ticker.Pair);
            var    limited_order_size = TickerAgent.LimitedOrderSize(ticker.Pair);
            double amount             = shortOrderParam.Amount;
            double low        = shortOrderParam.LowerPrice;
            double high       = shortOrderParam.UpperPrice;
            int    count      = shortOrderParam.OrderCount;
            double pstep      = (high - low) / (count - 1);
            var    scale_type = shortOrderParam.DistributionType;
            double min_size   = Math.Max(limited_order_size, shortOrderParam.MinSize);
            double exp        = shortOrderParam.Coefficient;

            if (min_size * count > amount)
            {
                count = (int)Math.Floor(amount / min_size) - 1;
                Helper.Log(string.Format("min_size {0} amount {1} count was reset to {2}", min_size, amount, count));
                if (count < 0)
                {
                    return(previews);
                }
                previews.Add(count.ToString());
            }
            else
            {
                previews.Add("match");
            }
            if (count <= 0)
            {
                return(previews);
            }

            double size_max    = ((amount - min_size * count) * 2) / count + min_size;
            double sum         = 0;
            double first_value = 1;

            for (double i = 0; i < count; i++)
            {
                sum = sum + Math.Pow(exp, i);
            }
            first_value = (amount - min_size * count) / sum;
            if (first_value < 0)
            {
                first_value = 0;
            }

            double[] sizes = new double[count];
            for (int i = 0; i < count; i++)
            {
                switch (scale_type)
                {
                case DISTRIBUTION_TYPE.FLAT:
                    sizes[i] = amount / count;
                    break;

                case DISTRIBUTION_TYPE.LINEAR_UP:
                    sizes[i] = min_size + (size_max - min_size) / (count - 1) * i;
                    break;

                case DISTRIBUTION_TYPE.LINEAR_DN:
                    sizes[i] = min_size + (size_max - min_size) / (count - 1) * (count - i - 1);
                    break;

                case DISTRIBUTION_TYPE.EXPONENTIAL_UP:
                    sizes[i] = min_size + first_value * Math.Pow(exp, i);
                    break;

                case DISTRIBUTION_TYPE.EXPONENTIAL_DN:
                    sizes[i] = min_size + first_value * Math.Pow(exp, count - i - 1);
                    break;

                default:
                    sizes[i] = amount / count;
                    break;
                }
            }

            var previewContent = "";

            previewContent  = string.Format("Current price: {0}", market_price);
            previewContent += Environment.NewLine;

            lock (Global._previewOrders)
            {
                Global._previewOrders.Clear();
                for (int i = 0; i < count; i++)
                {
                    double p        = low + i * pstep;
                    string ex_price = p.ToString("F5");
                    var    txt      = "at " + ex_price;

                    var order = new TrailingOrder();
                    order.Symbol   = ticker.Pair;
                    order.Price    = Convert.ToDouble(ex_price);
                    order.Exchange = "bitfinex";

                    // buy order
                    order.BuyAmount = sizes[i];
                    var type = "TRAILING STOP";
                    order.BuyType = type;
                    txt          += string.Format(" buy {0} size: {1}", type, sizes[i].ToString());

                    // sell order
                    order.SellAmount = sizes[count - i - 1];
                    type             = p > market_price ? "LIMIT" : "TRAILING STOP";
                    order.SellType   = type;
                    txt += string.Format(" sell {0} size: {1}", type, sizes[count - i - 1].ToString());
                    txt += Environment.NewLine;

                    previewContent += txt;
                    Global._previewOrders.Add(order);
                }

                previews.Add(previewContent);
                Helper.Log(string.Format("order data was made {0} (preview {1})",
                                         string.Join <TrailingOrder>(" ", Global._previewOrders), previewContent));
            }

            return(previews);
        }