private void AddSourceToList(List <Indicator> list, IMetaSource source)
 {
     if (source.SourceType == SourceType.Indicator)
     {
         AddIndicatorToList(list, source as IndicatorSource);
     }
 }
Exemplo n.º 2
0
        public string Generate(IMetaSource source)
        {
            switch (source.SourceType)
            {
            case SourceType.Indicator:
                return(string.Format("indicator_{0}", ++_indicatorSourcesCount));

            case SourceType.Instrument:
                return(string.Format("instrument_{0}", ++_instrumentSourcesCount));
            }
            return("source");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generate code for the source.
        /// </summary>
        /// <param name="source">Source</param>
        /// <exception cref="NotSupportedSourceException">When source is not supported.</exception>
        /// <returns>Generated code</returns>
        internal static string Generate(IMetaSource source)
        {
            switch (source)
            {
            case IndicatorSource indicatorSource:
                return(Generate(indicatorSource));

            case InstrumentSource instrumentSource:
                return(Generate(instrumentSource));

            case MainInstrumentSource mainInstrumentSource:
            default:
                throw new NotSupportedSourceException(source.SourceType);
            }
        }
        private List <IPrimitive> AddCreateSourcesCode(IMetaSource source, string parentSourceId)
        {
            var lines    = new List <IPrimitive>();
            var sourceId = source.Id;

            switch (source)
            {
            case IndicatorSource indicatorSource:
                var createIndicatorCall = new FunctionCall("core.indicators:create")
                                          .AddParameter(new QuotedStringPrimitive(indicatorSource.Name.ToUpper()))
                                          .AddParameter(GetIndicatorSourceId(indicatorSource.Source));
                AddParameters(indicatorSource, createIndicatorCall);
                lines.Add(new AssigmentStatement("    " + sourceId, createIndicatorCall));
                if (_model.Debug)
                {
                    lines.Add(new FunctionCall("    debug_helper:AddIndicator", true).AddParameter(sourceId));
                }
                break;

            case MainInstrumentSource maintInstrumentSource:
                sourceId = "trading_logic.MainSource";
                break;

            case InstrumentSource instrumentSource:
                if (parentSourceId == null)
                {
                    parentSourceId = sourceId;
                }
                var extSubscribeCall = new FunctionCall("ExtSubscribe")
                                       .AddParameter(sourceId + "_id")
                                       .AddParameter("nil")
                                       .AddParameter(ReplaceStringParameter(instrumentSource.Timeframe))
                                       .AddParameter(instrumentSource.PriceType)
                                       .AddParameter(new QuotedStringPrimitive("bar"));
                lines.Add(new AssigmentStatement($"    {sourceId}", extSubscribeCall));
                if (_model.Debug)
                {
                    lines.Add(new FunctionCall("    debug_helper:AddInstrument", true).AddParameter(sourceId));
                }
                break;
            }
            return(lines);
        }
        private List <IPrimitive> GenerateVariableForSource(IMetaSource source)
        {
            var code     = new List <IPrimitive>();
            var sourceId = source.Id;

            switch (source)
            {
            case IndicatorSource indicatorSource:
                code.Add($"local {sourceId} = nil;".MakePrimitive());
                break;

            case InstrumentSource instrumentSource:
            {
                code.Add($"local {sourceId} = nil;".MakePrimitive());
                var sourceIdCookie = ++_lastCoookie;
                code.Add($"local {sourceId}_id = {sourceIdCookie};".MakePrimitive());
            }
            break;
            }
            return(code);
        }