示例#1
0
        public void ClearClosedOperations(TimeSpan keepRange)
        {
            var timeLimit = Time - keepRange;

            foreach (var op in ClosedOperations.Where(op => op.LastInvestmentTime < timeLimit).ToArray())
            {
                _ClosedOperations.Remove(op);
            }
        }
示例#2
0
        public void SaveNonVolatileVars()
        {
            lock (DbLock)
            {
                //save my internal state
                BsonDocument state = new BsonDocument();
                state["_id"]   = "TradingAlgoState";
                state["State"] = Db.Mapper.Serialize(State);

                //Save derived state
                state["DerivedClassState"] = Db.Mapper.Serialize(GetState());

                //save module states
                state["Sentry"]      = Db.Mapper.Serialize(Sentry.GetState());
                state["Allocator"]   = Db.Mapper.Serialize(Allocator.GetState());
                state["Executor"]    = Db.Mapper.Serialize(Executor.GetState());
                state["RiskManager"] = Db.Mapper.Serialize(RiskManager.GetState());

                Db.GetCollection("State").Upsert(state);

                foreach (var symData in SymbolsData.Values)
                {
                    Db.GetCollection <SymbolData>("SymbolsData").Upsert(symData);
                }

                Db.BeginTrans();
                foreach (var op in ActiveOperations.Where(op => op.IsChanged))
                {
                    DbActiveOperations.Upsert(op);
                }
                foreach (var op in ClosedOperations.Where(op => op.IsChanged))
                {
                    DbClosedOperations.Upsert(op);
                }
                Db.Commit();

                Db.Checkpoint();
            }
        }