예제 #1
0
        public async Task <string> CreateExperiment(ForexExperiment experiment)
        {
            experiment.starttime = DateTime.Now.ToLongTimeString();
            await AddExperiment(_mapper.Map <ForexExperimentMongo>(experiment));

            List <Strategy> _strategies = experiment.GetStrategies();
            int             counter     = 0;

            foreach (Strategy _strategy in _strategies)
            {
                TradingSession session = new TradingSession();
                session.Name            = $"{experiment.name}_{counter}";
                session.StartDate       = experiment.startdate;
                session.EndDate         = experiment.enddate;
                session.TradingStrategy = _mapper.Map <StrategyMongo>(_strategy);
                session.Read            = false;
                session.ExperimentId    = experiment.name;
                session.StartAmount     = experiment.startamount;
                await PushTradingStrategySession(session);

                counter++;
            }

            return($"{experiment.name} added");
        }
예제 #2
0
        public async Task SaveExperimentTime(ForexExperiment experiment)
        {
            var expMongo = _mapper.Map <ForexExperimentMongo>(experiment);
            var filter   = Builders <ForexExperimentMongo> .Filter.Eq(exp => exp.name, expMongo.name);

            await _context.Experiments.ReplaceOneAsync(filter, expMongo, new UpdateOptions { IsUpsert = true });


            /* await _context.Experiments.FindOneAndUpdateAsync<ForexExperimentMongo>(
             *                  e=>e.name==expMongo.name,
             *                  Builders<ForexExperimentMongo>.Update.Set(e=>e.endtime,experiment.endtime)
             *                  );
             * await _context.Experiments.FindOneAndUpdateAsync<ForexExperimentMongo>(
             *                  e=>e.name==item.name,
             *                  Builders<ForexExperimentMongo>.Update.Set(e=>e.elapsedtime,experiment.elapsedtime)
             *                  );*/
        }
        public async Task <ActionResult> CreateExperiment([FromBody] ForexExperiment experiment)
        {
            var result = await _forexExperimentMap.CreateExperiment(experiment);

            return(Ok(JsonConvert.SerializeObject(result)));
        }