Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 /// <summary>
 /// Returns a string that represents the current object.
 /// </summary>
 /// <returns>
 /// A string that represents the current object.
 /// </returns>
 /// <filterpriority>2</filterpriority>
 public override string ToString()
 {
     return(string.Format("{0} at stop {1} limit {2}", base.ToString(), StopPrice.SmartRounding(), LimitPrice.SmartRounding()));
 }
Esempio n. 3
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                var hashCode = 41;
                // Suitable nullity checks etc, of course :)

                hashCode = hashCode * 59 + Direction.GetHashCode();
                if (ReduceOnly != null)
                {
                    hashCode = hashCode * 59 + ReduceOnly.GetHashCode();
                }
                if (Triggered != null)
                {
                    hashCode = hashCode * 59 + Triggered.GetHashCode();
                }
                if (OrderId != null)
                {
                    hashCode = hashCode * 59 + OrderId.GetHashCode();
                }
                if (Price != null)
                {
                    hashCode = hashCode * 59 + Price.GetHashCode();
                }

                hashCode = hashCode * 59 + TimeInForce.GetHashCode();
                if (Api != null)
                {
                    hashCode = hashCode * 59 + Api.GetHashCode();
                }

                hashCode = hashCode * 59 + OrderState.GetHashCode();
                if (Implv != null)
                {
                    hashCode = hashCode * 59 + Implv.GetHashCode();
                }

                hashCode = hashCode * 59 + Advanced.GetHashCode();
                if (PostOnly != null)
                {
                    hashCode = hashCode * 59 + PostOnly.GetHashCode();
                }
                if (Usd != null)
                {
                    hashCode = hashCode * 59 + Usd.GetHashCode();
                }
                if (StopPrice != null)
                {
                    hashCode = hashCode * 59 + StopPrice.GetHashCode();
                }

                hashCode = hashCode * 59 + OrderType.GetHashCode();
                if (LastUpdateTimestamp != null)
                {
                    hashCode = hashCode * 59 + LastUpdateTimestamp.GetHashCode();
                }

                hashCode = hashCode * 59 + OriginalOrderType.GetHashCode();
                if (MaxShow != null)
                {
                    hashCode = hashCode * 59 + MaxShow.GetHashCode();
                }
                if (ProfitLoss != null)
                {
                    hashCode = hashCode * 59 + ProfitLoss.GetHashCode();
                }
                if (IsLiquidation != null)
                {
                    hashCode = hashCode * 59 + IsLiquidation.GetHashCode();
                }
                if (FilledAmount != null)
                {
                    hashCode = hashCode * 59 + FilledAmount.GetHashCode();
                }
                if (Label != null)
                {
                    hashCode = hashCode * 59 + Label.GetHashCode();
                }
                if (Commission != null)
                {
                    hashCode = hashCode * 59 + Commission.GetHashCode();
                }
                if (Amount != null)
                {
                    hashCode = hashCode * 59 + Amount.GetHashCode();
                }

                hashCode = hashCode * 59 + Trigger.GetHashCode();
                if (InstrumentName != null)
                {
                    hashCode = hashCode * 59 + InstrumentName.GetHashCode();
                }
                if (CreationTimestamp != null)
                {
                    hashCode = hashCode * 59 + CreationTimestamp.GetHashCode();
                }
                if (AveragePrice != null)
                {
                    hashCode = hashCode * 59 + AveragePrice.GetHashCode();
                }
                return(hashCode);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Returns true if Order instances are equal
        /// </summary>
        /// <param name="other">Instance of Order to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Order other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Direction == other.Direction ||

                     Direction.Equals(other.Direction)
                     ) &&
                 (
                     ReduceOnly == other.ReduceOnly ||
                     ReduceOnly != null &&
                     ReduceOnly.Equals(other.ReduceOnly)
                 ) &&
                 (
                     Triggered == other.Triggered ||
                     Triggered != null &&
                     Triggered.Equals(other.Triggered)
                 ) &&
                 (
                     OrderId == other.OrderId ||
                     OrderId != null &&
                     OrderId.Equals(other.OrderId)
                 ) &&
                 (
                     Price == other.Price ||
                     Price != null &&
                     Price.Equals(other.Price)
                 ) &&
                 (
                     TimeInForce == other.TimeInForce ||

                     TimeInForce.Equals(other.TimeInForce)
                 ) &&
                 (
                     Api == other.Api ||
                     Api != null &&
                     Api.Equals(other.Api)
                 ) &&
                 (
                     OrderState == other.OrderState ||

                     OrderState.Equals(other.OrderState)
                 ) &&
                 (
                     Implv == other.Implv ||
                     Implv != null &&
                     Implv.Equals(other.Implv)
                 ) &&
                 (
                     Advanced == other.Advanced ||

                     Advanced.Equals(other.Advanced)
                 ) &&
                 (
                     PostOnly == other.PostOnly ||
                     PostOnly != null &&
                     PostOnly.Equals(other.PostOnly)
                 ) &&
                 (
                     Usd == other.Usd ||
                     Usd != null &&
                     Usd.Equals(other.Usd)
                 ) &&
                 (
                     StopPrice == other.StopPrice ||
                     StopPrice != null &&
                     StopPrice.Equals(other.StopPrice)
                 ) &&
                 (
                     OrderType == other.OrderType ||

                     OrderType.Equals(other.OrderType)
                 ) &&
                 (
                     LastUpdateTimestamp == other.LastUpdateTimestamp ||
                     LastUpdateTimestamp != null &&
                     LastUpdateTimestamp.Equals(other.LastUpdateTimestamp)
                 ) &&
                 (
                     OriginalOrderType == other.OriginalOrderType ||

                     OriginalOrderType.Equals(other.OriginalOrderType)
                 ) &&
                 (
                     MaxShow == other.MaxShow ||
                     MaxShow != null &&
                     MaxShow.Equals(other.MaxShow)
                 ) &&
                 (
                     ProfitLoss == other.ProfitLoss ||
                     ProfitLoss != null &&
                     ProfitLoss.Equals(other.ProfitLoss)
                 ) &&
                 (
                     IsLiquidation == other.IsLiquidation ||
                     IsLiquidation != null &&
                     IsLiquidation.Equals(other.IsLiquidation)
                 ) &&
                 (
                     FilledAmount == other.FilledAmount ||
                     FilledAmount != null &&
                     FilledAmount.Equals(other.FilledAmount)
                 ) &&
                 (
                     Label == other.Label ||
                     Label != null &&
                     Label.Equals(other.Label)
                 ) &&
                 (
                     Commission == other.Commission ||
                     Commission != null &&
                     Commission.Equals(other.Commission)
                 ) &&
                 (
                     Amount == other.Amount ||
                     Amount != null &&
                     Amount.Equals(other.Amount)
                 ) &&
                 (
                     Trigger == other.Trigger ||

                     Trigger.Equals(other.Trigger)
                 ) &&
                 (
                     InstrumentName == other.InstrumentName ||
                     InstrumentName != null &&
                     InstrumentName.Equals(other.InstrumentName)
                 ) &&
                 (
                     CreationTimestamp == other.CreationTimestamp ||
                     CreationTimestamp != null &&
                     CreationTimestamp.Equals(other.CreationTimestamp)
                 ) &&
                 (
                     AveragePrice == other.AveragePrice ||
                     AveragePrice != null &&
                     AveragePrice.Equals(other.AveragePrice)
                 ));
        }
Esempio n. 5
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Id != null)
         {
             hashCode = hashCode * 59 + Id.GetHashCode();
         }
         if (Instrument != null)
         {
             hashCode = hashCode * 59 + Instrument.GetHashCode();
         }
         if (Qty != null)
         {
             hashCode = hashCode * 59 + Qty.GetHashCode();
         }
         if (Side != null)
         {
             hashCode = hashCode * 59 + Side.GetHashCode();
         }
         if (Type != null)
         {
             hashCode = hashCode * 59 + Type.GetHashCode();
         }
         if (FilledQty != null)
         {
             hashCode = hashCode * 59 + FilledQty.GetHashCode();
         }
         if (AvgPrice != null)
         {
             hashCode = hashCode * 59 + AvgPrice.GetHashCode();
         }
         if (LimitPrice != null)
         {
             hashCode = hashCode * 59 + LimitPrice.GetHashCode();
         }
         if (StopPrice != null)
         {
             hashCode = hashCode * 59 + StopPrice.GetHashCode();
         }
         if (ParentId != null)
         {
             hashCode = hashCode * 59 + ParentId.GetHashCode();
         }
         if (ParentType != null)
         {
             hashCode = hashCode * 59 + ParentType.GetHashCode();
         }
         if (Duration != null)
         {
             hashCode = hashCode * 59 + Duration.GetHashCode();
         }
         if (Status != null)
         {
             hashCode = hashCode * 59 + Status.GetHashCode();
         }
         return(hashCode);
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Returns true if Order instances are equal
        /// </summary>
        /// <param name="other">Instance of Order to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Order other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id != null &&
                     Id.Equals(other.Id)
                     ) &&
                 (
                     Instrument == other.Instrument ||
                     Instrument != null &&
                     Instrument.Equals(other.Instrument)
                 ) &&
                 (
                     Qty == other.Qty ||
                     Qty != null &&
                     Qty.Equals(other.Qty)
                 ) &&
                 (
                     Side == other.Side ||
                     Side != null &&
                     Side.Equals(other.Side)
                 ) &&
                 (
                     Type == other.Type ||
                     Type != null &&
                     Type.Equals(other.Type)
                 ) &&
                 (
                     FilledQty == other.FilledQty ||
                     FilledQty != null &&
                     FilledQty.Equals(other.FilledQty)
                 ) &&
                 (
                     AvgPrice == other.AvgPrice ||
                     AvgPrice != null &&
                     AvgPrice.Equals(other.AvgPrice)
                 ) &&
                 (
                     LimitPrice == other.LimitPrice ||
                     LimitPrice != null &&
                     LimitPrice.Equals(other.LimitPrice)
                 ) &&
                 (
                     StopPrice == other.StopPrice ||
                     StopPrice != null &&
                     StopPrice.Equals(other.StopPrice)
                 ) &&
                 (
                     ParentId == other.ParentId ||
                     ParentId != null &&
                     ParentId.Equals(other.ParentId)
                 ) &&
                 (
                     ParentType == other.ParentType ||
                     ParentType != null &&
                     ParentType.Equals(other.ParentType)
                 ) &&
                 (
                     Duration == other.Duration ||
                     Duration != null &&
                     Duration.Equals(other.Duration)
                 ) &&
                 (
                     Status == other.Status ||
                     Status != null &&
                     Status.Equals(other.Status)
                 ));
        }
Esempio n. 7
0
 /// <summary>
 /// Returns a string that represents the current object.
 /// </summary>
 /// <returns>
 /// A string that represents the current object.
 /// </returns>
 /// <filterpriority>2</filterpriority>
 public override string ToString()
 {
     return(Invariant($"{base.ToString()} at stop {StopPrice.SmartRounding()} limit {LimitPrice.SmartRounding()}"));
 }
Esempio n. 8
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;
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Returns a string that represents the current object.
 /// </summary>
 /// <returns>
 /// A string that represents the current object.
 /// </returns>
 /// <filterpriority>2</filterpriority>
 public override string ToString()
 {
     return(string.Format("{0} order for {1} unit{2} of {3} at stop {4} limit {5}", Type, Quantity, Quantity == 1 ? "" : "s", Symbol, StopPrice.SmartRounding(), LimitPrice.SmartRounding()));
 }
Esempio n. 10
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));
 }