/// <summary> /// Processes a new fill, eventually creating new trades /// </summary> /// <param name="fill">The new fill order event</param> /// <param name="conversionRate">The current security market conversion rate into the account currency</param> /// <param name="feeInAccountCurrency">The current order fee in the account currency</param> /// <param name="multiplier">The contract multiplier</param> public void ProcessFill(OrderEvent fill, decimal conversionRate, decimal feeInAccountCurrency, decimal multiplier = 1.0m) { // If we have multiple fills per order, we assign the order fee only to its first fill // to avoid counting the same order fee multiple times. var orderFee = 0m; if (!_ordersWithFeesAssigned.Contains(fill.OrderId)) { orderFee = feeInAccountCurrency; _ordersWithFeesAssigned.Add(fill.OrderId); } switch (_groupingMethod) { case FillGroupingMethod.FillToFill: ProcessFillUsingFillToFill(fill.Clone(), orderFee, conversionRate, multiplier); break; case FillGroupingMethod.FlatToFlat: ProcessFillUsingFlatToFlat(fill.Clone(), orderFee, conversionRate, multiplier); break; case FillGroupingMethod.FlatToReduced: ProcessFillUsingFlatToReduced(fill.Clone(), orderFee, conversionRate, multiplier); break; } }
public virtual Symbol NextSymbol(SecurityType securityType, string market) { if (securityType == SecurityType.Option || securityType == SecurityType.Future) { throw new ArgumentException("Please use NextOption or NextFuture for SecurityType.Option and SecurityType.Future respectively."); } // let's make symbols all have 3 chars as it's acceptable for all permitted security types in this method var ticker = NextUpperCaseString(3, 3); // by chance we may generate a ticker that actually exists, and if map files exist that match this // ticker then we'll end up resolving the first trading date for use in the SID, otherwise, all // generated symbol will have a date equal to SecurityIdentifier.DefaultDate var symbol = Symbol.Create(ticker, securityType, market); if (_symbols.Add(symbol)) { return(symbol); } // lo' and behold, we created a duplicate --recurse to find a unique value // this is purposefully done as the last statement to enable the compiler to // unroll this method into a tail-recursion loop :) return(NextSymbol(securityType, market)); }
/// <summary> /// Generates random symbol, used further down for asset /// </summary> /// <param name="securityType">security type</param> /// <param name="market">market</param> /// <param name="ticker">Optionally can provide a ticker to use</param> /// <returns>Random symbol</returns> public Symbol NextSymbol(SecurityType securityType, string market, string ticker = null) { if (securityType == SecurityType.Option || securityType == SecurityType.Future) { throw new ArgumentException("Please use OptionSymbolGenerator or FutureSymbolGenerator for SecurityType.Option and SecurityType.Future respectively."); } if (ticker == null) { // we must return a Symbol matching an entry in the Symbol properties database // if there is a wildcard entry, we can generate a truly random Symbol // if there is no wildcard entry, the symbols we can generate are limited by the entries in the database if (SymbolPropertiesDatabase.ContainsKey(market, SecurityDatabaseKey.Wildcard, securityType)) { // let's make symbols all have 3 chars as it's acceptable for all security types with wildcard entries ticker = NextUpperCaseString(3, 3); } else { ticker = NextTickerFromSymbolPropertiesDatabase(securityType, market); } } // by chance we may generate a ticker that actually exists, and if map files exist that match this // ticker then we'll end up resolving the first trading date for use in the SID, otherwise, all // generated Symbol will have a date equal to SecurityIdentifier.DefaultDate var symbol = Symbol.Create(ticker, securityType, market); if (_symbols.Add(symbol)) { return(symbol); } // lo' and behold, we created a duplicate --recurse to find a unique value // this is purposefully done as the last statement to enable the compiler to // unroll this method into a tail-recursion loop :) return(NextSymbol(securityType, market)); }