public override Dictionary <string, string> BuildQueryParams()
        {
            var qp = new Dictionary <string, string>()
            {
                { "symbol", Symbol },
                { "side", Side.GetValue() },
                { "recvWindow", "6500" },
                { "type", Type.GetValue() },
                { "timeInForce", TimeInForce.GetValue() },
                { "quantity", Quantity.ToString() },
                { "price", Price.ToString() }
            };

            if (NewClientOrderId != null)
            {
                qp.Add("newClientOrderId", NewClientOrderId);
            }

            if (StopPrice.HasValue)
            {
                qp.Add("stopPrice", StopPrice.ToString());
            }

            if (IcebergQty.HasValue)
            {
                qp.Add("icebergQty", IcebergQty.ToString());
            }

            if (RecvWindow.HasValue)
            {
                qp.Add("recvWindow", RecvWindow.ToString());
            }

            return(qp);
        }
示例#2
0
        public async void Calc(float curPrice, string symbol = null)
        {
            CurPrice = curPrice;
            foreach (var stat in Strategy.AccountStat)
            {
                stat.Value.CurPrice = curPrice;
            }
            if (EntryPrice > 0)
            {
                if (Level > 0)
                {
                    if (ActionType == ActionType.Long)
                    {
                        HighestProfit = Math.Max(HighestProfit, curPrice - EntryPrice);
                    }
                    else
                    {
                        HighestProfit = Math.Max(HighestProfit, EntryPrice - curPrice);
                    }

                    // ignore the duplicated signal processing
                    if (HighestProfit - _highestProfitSinceLastSent >= (double)(ModifyThreshold * Strategy.Symbol.MinTick))
                    {
                        int profit_class = HighestProfit / EntryPrice < ProfitTarget / 100 ? 0 :
                                           1 + (int)((HighestProfit / EntryPrice - ProfitTarget / 100) / (ProfitTarget / 100 * TargetIncrement));
                        profit_class = profit_class > Level ? Level : profit_class;
                        ProfitClass  = Math.Max(ProfitClass, profit_class);

                        if (ProfitClass > 0)
                        {
                            TypeAccessor accessor = BaseOrderTypeAccessor.GetAccessor(OT_stopProfit);
                            if (ActionType == ActionType.Long)
                            {
                                StopPrice = EntryPrice + HighestProfit * (BaseLine / 100 + DropIncrement / 100 * (ProfitClass - 1));
                                if (curPrice <= StopPrice + (float)(SubmitThreshold * Strategy.Symbol.MinTick))
                                {
                                    accessor[OT_stopProfit, "LmtPrice"] = StopPrice.ToString();
                                    accessor[OT_stopProfit, "AuxPrice"] = StopPrice.ToString();
                                    bool r = await Controllers.OrderManager.ProcessSignal(Strategy.Script, Strategy, OrderAction.APSLong, DateTime.Now, OT_stopProfit, curPrice);

                                    if (r)
                                    {
                                        _highestProfitSinceLastSent = HighestProfit;
                                    }
                                }
                            }
                            else if (ActionType == ActionType.Short)
                            {
                                StopPrice = EntryPrice - HighestProfit * (BaseLine / 100 + DropIncrement / 100 * (ProfitClass - 1));
                                if (curPrice >= StopPrice - (float)(SubmitThreshold * Strategy.Symbol.MinTick))
                                {
                                    accessor[OT_stopProfit, "LmtPrice"] = StopPrice.ToString();
                                    accessor[OT_stopProfit, "AuxPrice"] = StopPrice.ToString();
                                    bool r = await Controllers.OrderManager.ProcessSignal(Strategy.Script, Strategy, OrderAction.APSShort, DateTime.Now, OT_stopProfit, curPrice);

                                    if (r)
                                    {
                                        _highestProfitSinceLastSent = HighestProfit;
                                    }
                                }
                            }
                        }
                    }
                }

                // stop loss
                if (Stoploss > 0)
                {
                    // ignore duplicated signal processing
                    if (Stoploss != _stoplossLastSent)
                    {
                        float        sp       = 0; // stop price
                        TypeAccessor accessor = BaseOrderTypeAccessor.GetAccessor(OT_stopLoss);
                        float        stoploss = (float)Stoploss;
                        switch (StoplossSelector)
                        {
                        case 0:     // in points/dollars(actual value)
                            // remain unchanged
                            break;

                        case 1:     // in ticks
                            stoploss *= (float)Strategy.Symbol.MinTick;
                            break;

                        case 2:     // in percentage
                            stoploss = (float)(EntryPrice * Stoploss * 0.01);
                            break;

                        case 3:     // from AFL sript;
                            // remain unchanged
                            break;
                        }
                        if (ActionType == ActionType.Long)
                        {
                            StopLossPrice = sp = EntryPrice - stoploss;
                            if (curPrice <= sp + (float)(SubmitThreshold * Strategy.Symbol.MinTick))
                            {
                                accessor[OT_stopLoss, "LmtPrice"] = sp.ToString();
                                accessor[OT_stopLoss, "AuxPrice"] = sp.ToString();
                                bool r = await Controllers.OrderManager.ProcessSignal(Strategy.Script, Strategy, OrderAction.StoplossLong, DateTime.Now, OT_stopLoss, curPrice);

                                if (r)
                                {
                                    _stoplossLastSent = Stoploss;
                                }
                            }
                        }
                        else if (ActionType == ActionType.Short)
                        {
                            StopLossPrice = sp = EntryPrice + stoploss;
                            if (curPrice >= sp - (float)(SubmitThreshold * Strategy.Symbol.MinTick))
                            {
                                accessor[OT_stopLoss, "LmtPrice"] = sp.ToString();
                                accessor[OT_stopLoss, "AuxPrice"] = sp.ToString();
                                bool r = await Controllers.OrderManager.ProcessSignal(Strategy.Script, Strategy, OrderAction.StoplossShort, DateTime.Now, OT_stopLoss, curPrice);

                                if (r)
                                {
                                    _stoplossLastSent = Stoploss;
                                }
                            }
                        }
                    }
                }
            }
        }
示例#3
0
 public string ToString(int decimals)
 {
     if (IsFilled)
     {
         return(base.ToString());
     }
     return((Direction == Direction.Long ? "Long" : "Short") + UnsignedSize + " " + Symbol + "@" + (Type == OrderType.Market ? "Mkt" : (Type == OrderType.Limit || Type == OrderType.StopLimit ? LimitPrice.ToString("N" + decimals) : StopPrice.ToString("N" + decimals) + "stp")) + " [" + AccountName + "] " + Id + (Type == OrderType.Stop || Type == OrderType.StopLimit ? " stop: " + StopPrice.ToString("N" + decimals) : string.Empty));
 }