Skip to content

Commit bb4a104

Browse files
authored
Merge pull request #3 from DerekMelchin/bug-invalid-tickers
Handle invalid tickers provided by the API
2 parents e5715a4 + 320b942 commit bb4a104

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

DataProcessing/QuiverCNBCDataDownloader.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Globalization;
2020
using System.IO;
2121
using System.Linq;
22+
using System.Text.RegularExpressions;
2223
using Newtonsoft.Json;
2324
using QuantConnect.Data.Auxiliary;
2425
using QuantConnect.DataSource;
@@ -99,6 +100,16 @@ public bool Run(DateTime processDate)
99100
}
100101

101102
ticker = ticker.Split(':').Last().Replace("\"", string.Empty).ToUpperInvariant().Trim();
103+
// Strip characters not allowed in tickers (only letters, digits, and mid-string dots are valid)
104+
ticker = Regex.Replace(ticker, @"[^A-Z0-9.]", string.Empty);
105+
ticker = ticker.Trim('.');
106+
107+
// Validate: must be non-empty, only letters/digits/dots, dot not at start or end
108+
if (!Regex.IsMatch(ticker, @"^[A-Z0-9][A-Z0-9.]*[A-Z0-9]$") && !Regex.IsMatch(ticker, @"^[A-Z0-9]$"))
109+
{
110+
Log.Trace($"QuiverCNBCDataDownloader.Run(): Skipping invalid ticker '{ticker}' on {processDate:yyyyMMdd}");
111+
continue;
112+
}
102113

103114
if (!cnbcByTicker.TryGetValue(ticker, out var _))
104115
{

0 commit comments

Comments
 (0)