private void tickdataArrived(TickData data) { priceHistoryDatabase.setPrice(data); insertedSets++; if (prices.ContainsKey(data.instrument) == false) { prices.Add(data.instrument, data.getAvgPrice()); } else { prices[data.instrument] = data.getAvgPrice(); } lastUpdatedPair = data.instrument; }
private void tickdataArrived(TickData data) { priceHistoryDatabase.setPrice(data); insertedSets++; if (prices.ContainsKey(data.instrument) == false) { prices.Add(data.instrument, data.getAvgPrice()); } else { prices[data.instrument] = data.getAvgPrice(); } lastUpdatedPair = data.instrument; if (continueLiveTradingThread) { streamer.pushDataAndTrade(data); } }
void IDataminingDatabase.addOutcome(long timeframe, string instrument) { //Do in walker? Faster? Todo... //{ outcome_max_1800: { $exists: true } } List <Thread> threads = new List <Thread>(); long start = database.getFirstTimestamp(); long end = database.getLastTimestamp(); long oneThreadTimeframe = (end - start) / threadsCount; int threadId = 0; var collection = mongodb.getDB().GetCollection("prices"); while (threadId < threadsCount) { long threadBeginning = start + (oneThreadTimeframe * threadId); long threadEnd = threadBeginning + oneThreadTimeframe; Thread thread = new Thread(delegate() { string name = "outcome " + timeframe + " ID_" + threadBeginning + ":" + threadEnd; progress.setProgress(name, 0); int done = 0; long count = 0; var docs = collection.FindAs <BsonDocument>(Query.And(Query.EQ("instrument", instrument), Query.NotExists("outcome_max_" + timeframe), Query.LT("timestamp", threadEnd), Query.GTE("timestamp", threadBeginning))).SetSortOrder(SortBy.Ascending("timestamp")); docs.SetFlags(QueryFlags.NoCursorTimeout); count = docs.Count(); foreach (BsonDocument doc in docs) { done++; progress.setProgress(name, Convert.ToInt32(Convert.ToDouble(done) / Convert.ToDouble(count) * 100d)); try { TickData inTimeframe = database.getPrice(doc["timestamp"].AsInt64 + timeframe, doc["instrument"].AsString); var min_doc = collection.FindAs <BsonDocument>(Query.And(Query.EQ("instrument", doc["instrument"].AsString), Query.LT("timestamp", doc["timestamp"].AsInt64 + timeframe), Query.GT("timestamp", doc["timestamp"].AsInt64))) .SetSortOrder(SortBy.Ascending("bid")) .SetLimit(1) .SetFields("bid") .Single(); var max_doc = collection.FindAs <BsonDocument>(Query.And(Query.EQ("instrument", doc["instrument"].AsString), Query.LT("timestamp", doc["timestamp"].AsInt64 + timeframe), Query.GT("timestamp", doc["timestamp"].AsInt64))) .SetSortOrder(SortBy.Descending("ask")) .SetLimit(1) .SetFields("ask") .Single(); string s = max_doc["ask"].AsDouble.ToString(); s = s + ""; collection.FindAndModify(new FindAndModifyArgs() { Query = Query.EQ("_id", doc["_id"]), Update = Update.Combine( Update.Set("outcome_max_" + timeframe, max_doc["ask"]), Update.Set("outcome_min_" + timeframe, min_doc["bid"]), Update.Set("outcome_actual_" + timeframe, inTimeframe.getAvgPrice()) ) }); } catch { } } progress.remove(name); }); thread.Start(); threads.Add(thread); threadId++; } waitForThreads(threads); }