public Task <IEnumerable <ScannerDataMessage> > GetScannerDataAsync(ScannerSubscription subscription, string scannerSubscriptionOptions, string scannerSubscriptionFilterOptions) { var reqId = GetUniqueRequestId(); var reqScannerSubscription = new Action(() => _clientSocket.reqScannerSubscription(reqId, subscription, scannerSubscriptionOptions, scannerSubscriptionFilterOptions)); return(GetScannerDataAsync(reqId, reqScannerSubscription)); }
public void RequestScannerSubscription(int requestId, ScannerSubscription subscription, IList <Tag>?subscriptionOptions = null, IList <Tag>?filterOptions = null) { if (subscription == null) { throw new ArgumentNullException(nameof(subscription)); } var m = CreateMessage().Write(RequestCode.RequestScannerSubscription); if (Config.ServerVersionCurrent < ServerVersion.ScannerGenericOpts) { m.Write("4"); } m.Write(requestId, subscription.NumberOfRows, subscription.Instrument, subscription.LocationCode, subscription.ScanCode, subscription.AbovePrice, subscription.BelowPrice, subscription.AboveVolume, subscription.MarketCapAbove, subscription.MarketCapBelow, subscription.MoodyRatingAbove, subscription.MoodyRatingBelow, subscription.SpRatingAbove, subscription.SpRatingBelow, subscription.MaturityDateAbove, subscription.MaturityDateBelow, subscription.CouponRateAbove, subscription.CouponRateBelow, subscription.ExcludeConvertible, subscription.AverageOptionVolumeAbove, subscription.ScannerSettingPairs, subscription.StockType); if (Config.SupportsServerVersion(ServerVersion.ScannerGenericOpts)) { m.Write(Tag.Combine(filterOptions)); } m.Write(Tag.Combine(subscriptionOptions)).Send(); }
//######################################################## // Market Scanners //######################################################## #region Market Scanners public List <scannerData_Struct> reqScannerSubscription(int reqId, ScannerSubscription subscription) { testImpl.this_ScannerData_List.Clear(); clientSocket.reqScannerSubscription(reqId, subscription, new List <TagValue>()); while (testImpl.scannerDataActive) { } return(testImpl.this_ScannerData_List); }
public static ScannerSubscription GetScannerSubscription() { ScannerSubscription scanSub = new ScannerSubscription(); scanSub.Instrument = "STOCK.EU"; scanSub.LocationCode = "STK.EU.IBIS"; scanSub.ScanCode = "HOT_BY_VOLUME"; return(scanSub); }
public static ScannerSubscription ToScannerSubscription(this ScannerParameter param) { var res = new ScannerSubscription(); if (param.NumberOfRows.HasValue) { res.NumberOfRows = (int)param.NumberOfRows; } if (param.AbovePrice.HasValue) { res.AbovePrice = (double)param.AbovePrice; } if (param.BelowPrice.HasValue) { res.BelowPrice = (double)param.BelowPrice; } if (param.AboveVolume.HasValue) { res.AboveVolume = (int)param.AboveVolume; } if (param.AverageOptionVolumeAbove.HasValue) { res.AverageOptionVolumeAbove = (int)param.AverageOptionVolumeAbove; } if (param.MarketCapAbove.HasValue) { res.MarketCapAbove = (double)param.MarketCapAbove; } if (param.MarketCapBelow.HasValue) { res.MarketCapBelow = (double)param.MarketCapBelow; } if (param.CouponRateAbove.HasValue) { res.CouponRateAbove = (double)param.CouponRateAbove; } if (param.CouponRateBelow.HasValue) { res.CouponRateBelow = (double)param.CouponRateBelow; } res.Instrument = param.Instrument; res.LocationCode = param.LocationCode; res.ScanCode = param.ScanCode; res.MoodyRatingAbove = param.MoodyRatingAbove; res.MoodyRatingBelow = param.MoodyRatingBelow; res.SpRatingAbove = param.SpRatingAbove; res.SpRatingBelow = param.SpRatingBelow; res.MaturityDateAbove = param.MaturityDateAbove; res.MaturityDateBelow = param.MaturityDateBelow; res.ExcludeConvertible = param.ExcludeConvertible; res.ScannerSettingPairs = param.ScannerSettingPairs; res.StockTypeFilter = param.StockTypeFilter; return(res); }
public static ScannerSubscription TopPercentGainersIbis() { //! [toppercentgaineribis] //Top % gainers at IBIS ScannerSubscription scanSub = new ScannerSubscription(); scanSub.Instrument = "STOCK.EU"; scanSub.LocationCode = "STK.EU.IBIS"; scanSub.ScanCode = "TOP_PERC_GAIN"; //! [toppercentgaineribis] return(scanSub); }
public static ScannerSubscription HotUSStkByVolume() { //! [hotusvolume] //Hot US stocks by volume ScannerSubscription scanSub = new ScannerSubscription(); scanSub.Instrument = "STK"; scanSub.LocationCode = "STK.US.MAJOR"; scanSub.ScanCode = "HOT_BY_VOLUME"; //! [hotusvolume] return(scanSub); }
public static ScannerSubscription HighOptVolumePCRatioUSIndexes() { //! [highoptvolume] //High option volume P/C ratio US indexes ScannerSubscription scanSub = new ScannerSubscription(); scanSub.Instrument = "IND.US"; scanSub.LocationCode = "IND.US"; scanSub.ScanCode = "HIGH_OPT_VOLUME_PUT_CALL_RATIO"; //! [highoptvolume] return(scanSub); }
public static ScannerSubscription ComplexOrdersAndTrades() { //! [combolatesttrade] //Complex orders and trades scan, latest trades ScannerSubscription scanSub = new ScannerSubscription(); scanSub.Instrument = "NATCOMB"; scanSub.LocationCode = "NATCOMB.OPT.US"; scanSub.ScanCode = "COMBO_LATEST_TRADE"; //! [combolatesttrade] return(scanSub); }
public static ScannerSubscription MostActiveFutSoffex() { //! [mostactivefutsoffex] //Most active futures at SOFFEX ScannerSubscription scanSub = new ScannerSubscription(); scanSub.Instrument = "FUT.EU"; scanSub.LocationCode = "FUT.EU.SOFFEX"; scanSub.ScanCode = "MOST_ACTIVE"; //! [mostactivefutsoffex] return(scanSub); }
private void scannerRequest_Button_Click(object sender, EventArgs e) { if (isConnected) { ScannerSubscription subscription = new ScannerSubscription(); subscription.ScanCode = scanCode.Text; subscription.Instrument = scanInstrument.Text; subscription.LocationCode = scanLocation.Text; subscription.StockTypeFilter = scanStockType.Text; subscription.NumberOfRows = Int32.Parse(scanNumRows.Text); scannerManager.AddRequest(subscription); ShowTab(marketData_MDT, scannerTab); } }
public IObservable <IList <ScannerDataItem> > ScannerObservable(ScannerSubscription subscription, IList <Tag>?subscriptionOptions = null, IList <Tag>?filterOptions = null) { if (subscription == null) { throw new ArgumentNullException(nameof(subscription)); } return(Response .ToObservable <ScannerData>( Request.NextId, requestId => Request.RequestScannerSubscription(requestId, subscription, subscriptionOptions, filterOptions), Request.CancelScannerSubscription) .Select(m => m.Items) .ToShareSource()); }
/// <summary> /// Creates an observable which, upon subscription, emits scanner results, then completes. /// </summary> public IObservable <IReadOnlyList <ScannerDataItem> > ScannerObservable(ScannerSubscription subscription, params Tag[] options) { if (subscription == null) { throw new ArgumentNullException(nameof(subscription)); } return(Response .ToObservable <ScannerData>( Request.NextId, requestId => Request.RequestScannerSubscription(requestId, subscription, options), Request.CancelScannerSubscription) .Select(m => m.Items) .ToShareSource()); }
public async Task Should_GetScannerDataAsync_Tags() { // Arrange var subscription = new ScannerSubscription() { ScanCode = "MOST_ACTIVE", Instrument = "STK", LocationCode = "STK.US" }; // Act var scanners = await _client.GetScannerDataAsync(subscription, new List <TagValue>(), new List <TagValue>()); // Assert var symbols = scanners.Select(x => x.ContractDetails.Contract.Symbol); Assert.Positive(symbols.Count()); }
public Task <Scanner[]> GetScannerAsync(ScannerSubscription scannerSubscription, List <TagValue> scannerSubscriptionOptions = null) { var ct = new CancellationTokenSource(DefaultTimeoutMs); var res = new TaskCompletionSource <Scanner[]>(); ct.Token.Register(() => res.TrySetCanceled(), false); var reqId = new Random(DateTime.Now.Millisecond).Next(); scannerSubscriptionOptions = scannerSubscriptionOptions ?? new List <TagValue>(); var scanners = new List <Scanner>(); EventHandler <ScannerEventArgs> scanner = (sender, args) => { if (args.RequestId != reqId) { return; } scanners.Add(new Scanner(args.Rank, args.ContractDetails, args.Distance, args.Benchmark, args.Projection, args.LegsStr)); }; EventHandler <ScannerEndEventArgs> scannerEnd = (sender, args) => { if (args.RequestId != reqId) { return; } res.SetResult(scanners.ToArray()); }; EventDispatcher.Scanner += scanner; EventDispatcher.ScannerEnd += scannerEnd; ClientSocket.reqScannerSubscription(reqId, scannerSubscription, scannerSubscriptionOptions); res.Task.ContinueWith(x => { ClientSocket.cancelScannerSubscription(reqId); EventDispatcher.Scanner -= scanner; EventDispatcher.ScannerEnd -= scannerEnd; }, TaskContinuationOptions.None); return(res.Task); }
/// <summary> /// Starts an individual scanner /// </summary> /// <param name="choice"></param> private void ScanStart(int choice) { ScannerSubscription scanSub = new ScannerSubscription(); int reqId = -1; switch (choice) { case 0: reqId = 300; scanSub.Instrument = "STK"; scanSub.LocationCode = "STK.US.MAJOR"; scanSub.ScanCode = "MOST_ACTIVE"; scanSub.AbovePrice = 10; scanSub.AboveVolume = 30000; scanSub.NumberOfRows = 50; break; case 1: reqId = 301; scanSub.Instrument = "STK"; scanSub.LocationCode = "STK.US.MAJOR"; scanSub.ScanCode = "TOP_PERC_GAIN"; scanSub.AbovePrice = 10; scanSub.AboveVolume = 50000; scanSub.NumberOfRows = 20; break; case 2: reqId = 302; scanSub.Instrument = "STK"; scanSub.LocationCode = "STK.US.MAJOR"; scanSub.ScanCode = "TOP_PERC_LOSE"; scanSub.AbovePrice = 10; scanSub.AboveVolume = 50000; scanSub.NumberOfRows = 20; break; default: Log.Error(3, string.Format("ScanStart Bad Choice= {0}", choice)); break; } Program.myIB.ibClient.ClientSocket.reqScannerSubscription(reqId, scanSub, null, (string)null); }
private async void RequestScanner() { var delayTimeSec = 30; var scannerSubscription = new ScannerSubscription { ScanCode = ScanCode.TOP_PERC_GAIN, Instrument = "STK", LocationCode = "STK.US", NumberOfRows = 25 }; while (true) { try { Logger.Info("Requesting scanner..."); var scanners = await _realTimeDataProviderExample.GetScannerAsync(scannerSubscription); StringBuilder sb = new StringBuilder(); for (var i = 0; i < scanners.Length; i++) { var scanner = scanners[i]; if (i != 0) { sb.Append(", "); } sb.Append($"[{scanner.Rank}]: {scanner.ContractDetails.Summary.Symbol}"); } Logger.Info($"Scanner results: {sb}"); } catch (Exception e) { Logger.Error(e); } Logger.Info($"Waiting {delayTimeSec} seconds before the next scanner request..."); await Task.Delay((int)TimeSpan.FromSeconds(delayTimeSec).TotalMilliseconds); } }
public void AddRequest(ScannerSubscription scannerSubscription, List <TagValue> filterOptions) { ibClient.ClientSocket.reqScannerSubscription(currentTicker, scannerSubscription, null, filterOptions); }
/// <summary> /// Call the reqScannerSubscription() method to start receiving market scanner results through the scannerData() EWrapper method. /// </summary> /// <param name="requestId">the Id for the subscription. Must be a unique value. When the subscription data is received, it will be identified by this Id. This is also used when canceling the scanner.</param> /// <param name="subscription">summary of the scanner subscription parameters including filters.</param> public void RequestScannerSubscription(int requestId, ScannerSubscription subscription, string scannerSubscriptionOptions, string scannerSubscriptionFilterOptions) { lock (this) ClientSocket.reqScannerSubscription(requestId, subscription, scannerSubscriptionOptions, scannerSubscriptionFilterOptions); }
public void AddRequest(ScannerSubscription scannerSubscription) { ibClient.ClientSocket.reqScannerSubscription(currentTicker, scannerSubscription); }
public void reqScannerSubscription(int reqId, ScannerSubscription subscription, List <TagValue> scannerSubscriptionOptions) { throw new NotImplementedException(); }
public void RequestScannerSubscription(int tickerId, ScannerSubscription subscription) { lock (_socketLock) { // not connected? if (!IsConnected) throw new NotConnectedException(); if (ServerInfo.Version < 24) throw new TWSOutdatedException(); const int VERSION = 3; try { _enc.Encode(ServerMessage.RequestScannerSubscription); _enc.Encode(VERSION); _enc.Encode(tickerId); _enc.EncodeMax(subscription.NumberOfRows); _enc.Encode(subscription.Instrument); _enc.Encode(subscription.LocationCode); _enc.Encode(subscription.ScanCode); _enc.EncodeMax(subscription.AbovePrice); _enc.EncodeMax(subscription.BelowPrice); _enc.EncodeMax(subscription.AboveVolume); _enc.EncodeMax(subscription.MarketCapAbove); _enc.EncodeMax(subscription.MarketCapBelow); _enc.Encode(subscription.MoodyRatingAbove); _enc.Encode(subscription.MoodyRatingBelow); _enc.Encode(subscription.SPRatingAbove); _enc.Encode(subscription.SPRatingBelow); _enc.Encode(subscription.MaturityDateAbove); _enc.Encode(subscription.MaturityDateBelow); _enc.EncodeMax(subscription.CouponRateAbove); _enc.EncodeMax(subscription.CouponRateBelow); _enc.Encode(subscription.ExcludeConvertible); if (ServerInfo.Version >= 25) { _enc.Encode(subscription.AverageOptionVolumeAbove); _enc.Encode(subscription.ScannerSettingPairs); } if (ServerInfo.Version >= 27) _enc.Encode(subscription.StockTypeFilter); } catch (Exception) { Disconnect(); throw; } } }
public void AddRequest(ScannerSubscription scannerSubscription) { ibClient.ClientSocket.reqScannerSubscription(currentTicker, scannerSubscription, new List <TagValue>()); }