public void GetHistoryAsync(HistoryRequest value) { GetHistoryDelegate dlg = new GetHistoryDelegate(InnerGetHistory); dlg.BeginInvoke(value, new AsyncCallback(DeleteStockScannerDone), dlg); }
internal static void GenerateDayBarMessages(InstrumentOanda instrument, CancellationToken token, GetHistoryDelegate getHistory, Action <QuoteBase> newQuote) { var param = new HistoryRequestParameters(); param.Symbol = instrument.Name.ToUpper(); param.FromTime = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day).AddDays(-5).AddMilliseconds(-1); param.ToTime = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day); GenerateDayBarMessage(param, instrument, token, getHistory, newQuote); }
private static void GenerateDayBarMessage(HistoryRequestParameters param, InstrumentOanda instrument, CancellationToken token, GetHistoryDelegate getHistory, Action <QuoteBase> newQuote) { try { if (token.IsCancellationRequested) { return; } param.HistoryType = HistoryDataTypes.Bid; param.Period = (int)HistoryPeriod.Day; int count = 5000; List <BarHistoryItem> al = getHistory(param, param.FromTime, param.ToTime, (GranularityEnum)GetOandaTimeframe(param.Period), instrument, count); if (al == null || al.Count == 0) { return; } if (token.IsCancellationRequested) { return; } InstrumentDayBarMessage msg = new InstrumentDayBarMessage(); msg.Symbol = param.Symbol; var bi0 = al[al.Count - 1]; if (bi0 == null) { return; } msg.Open = bi0.Open; msg.High = bi0.High; msg.Low = bi0.Low; msg.Ticks = (long)bi0.Volume; if (al.Count > 1) { msg.PreviousClosePrice = al[al.Count - 2].Close; } if (token.IsCancellationRequested) { return; } newQuote(msg); } catch (Exception ex) { } }
internal static void GenerateDayBarMessages(ConcurrentDictionary <string, InstrumentOanda> instruments, CancellationToken cancellationToken, GetHistoryDelegate getHistory, Action <QuoteBase> newQuote) { SemaphoreSlim maxThread = new SemaphoreSlim(LIMIT_THREAD_GENERATE_BAR_MESSAGES); try { foreach (var instrument in instruments.Values) { // Ждем пока освободится семафор maxThread.Wait(); if (cancellationToken.IsCancellationRequested) { return; } Task.Factory.StartNew((object obj) => { GenerateDayBarMessages(obj as InstrumentOanda, cancellationToken, getHistory, newQuote); }, instrument, TaskCreationOptions.LongRunning).ContinueWith((task) => { maxThread.Release(); }); } } catch { } finally { } }