- ago
I have a class which implements DataSetProviderBase, On Initialize I am creating a new DataSet and making an external API call to retrieve some symbols, adding them to the DataSet, adding the DataSet to my dataSets List and have overridden the List<DataSet> DataSets() to return this.dataSets

Now what I am trying to achieve is this, I have a method in this class called UpdateList() this method is called every 5 min via a background service, then this method again makes an API call and retrieves an updated list of symbols, from there I am trying to replace the symbols in my existing dataset that was created on initialize with the new symbols and have my updated datalist reflect within WL every 5 min it gets updated.

Is this possible, maybe via EventRouter but I do not see any documentation for it?

CODE:
using WealthLab.Core; using WealthLab.Data; namespace PropTrading.Shop.WL.DataSets { public class DataSetProviderExample : DataSetProviderBase { public string Name = "DataSetProviderExtExample"; List<DataSet> dataSets = new List<DataSet>(); DataSet highVolatilityDataSet = new DataSet() { Name="Volatile"}; public override void Initialize() { List<string> highVolatilityStocks = new List<string> { "AAPL", "MSFT", "TSLA" };//Call my API to get volatile stocks highVolatilityDataSet.Symbols.AddRange(highVolatilityStocks); //Add symbols to DataSet dataSets.Add(highVolatilityDataSet); //Add DataSet to DataSetList base.Initialize(); } public override List<DataSet> DataSets => this.dataSets; //This method is called every 5 min from a hosted background service public List<DataSet> UpdateList() { List<string> updatedHighVolatilityStocks = new List<string> { "GME", "COST", "PINS" };//Call my API to get updated volatile stocks //create new dataset with same name? var updatedVolatileDataSet = new DataSet() { Name = "Volatile", Symbols = updatedHighVolatilityStocks }; //remove old DataSet from DataSetList? dataSets.RemoveAll(x => x.Name == updatedVolatileDataSet.Name); //add updated DataSet to DataSetList dataSets.Add(updatedVolatileDataSet); return this.dataSets; //return updated list? } } }
0
574
Solved
14 Replies

Reply

Bookmark

Sort
- ago
#1
Yes, it's possible. You could create a BackgroundWorker (for example) and keep it running asynchronously. Whenever it detects an update to the list of symbols, make your changes to the DataSets property and alert WL that it's ready:
CODE:
EventRouter.FireEvent("DataSetProviderReloaded", this);

0
Best Answer
Cone8
 ( 5.88% )
- ago
#2
Just because you can do it, doesn't mean you should. The question is, what are you going to do with this DataSet that keeps changing?

If the idea is to use the result in the Strategy Monitor, it won't work. There, a Strategy item is activated and initialized with a set of symbols in a DataSet. That DataSet is not expected to change, so there is no re-initialization, subscription for new symbols, etc.
0
- ago
#3
@Cone, Yup, that is exactly what I was trying to achieve, to have the list of stocks that my strategy is running up against dynamically change every 5 min.

So it is not possible to achieve doing something similar in WL?
0
- ago
#4
Not for shuffling the list of stocks the strategy is applied to, as @Cone pointed out. Otherwise it's possible which makes sense if you leave WL running for extended periods of time and want some DataSets maintain their actual state for some reason.
0
Cone8
 ( 5.88% )
- ago
#5
There's just no need to create these lists. Your strategy works from a larger list applying a filter to come up with trading candidates. The point is, you have to keep working with this larger DataSet to keep identifying the candidates. The larger list doesn't change, only the candidates do.
0
- ago
#6
@Cone
In broad sense, it's a valid use case to auto-refresh a subset of symbols updated at an external source. Like those proverbial Fidelity Select Sector funds: https://www.wealth-lab.com/Discussion/Anomalies-in-Fidelity-Select-Sector-funds-DataSet-6868
0
Cone8
 ( 5.88% )
- ago
#7
Let's not get confused. Sure, it's valid to create DataSets like this, just not to do it every 5 minutes and expect to use it in the Strategy Monitor.
0
- ago
#8
I don't understand what you mean by not a valid use case, I just gave a scenario/strategy of the use case for such a feature.

Would it be possible to re-start/kick-off a strategy in the strategy monitor through code once the list is updated?

Or can WealthLab handle a dataset of 7000 symbols or a large universe then running all those symbols in PreExecute to screen/filter the tradeable symbols or would that be too large a size/too slow?
0
- ago
#9
Restarting a strategy in the SM through code is not supported.
0
- ago
#10
Thanks for clarifying that @Eugene, so what is the recommended approach here for what I am trying to achieve, or is this just completely out of WL scope?
0
Cone8
 ( 5.88% )
- ago
#11
I'm not aware of anyone who has tried 7000 symbols (or even anyone who has a streaming subscription that would support it), but the S. Monitor can get through about 500 symbols in 15 to 20 seconds as I recall with Streaming Bar updates.

Definitely out of scope to change the design for a single use case, and, still there's no basis why creating DataSets are required for this use case. Why is it?
0
- ago
#12
Thank you for the response @Cone, maybe I am not explaining the use case very well.

Let's say I have a simple strategy that enters on the break of an inside bar.

I do NOT need to create DataSets but a single DataSet that is dynamically updated every 5 or 15 minutes then that strategy runs on the new set of stocks.

I have already built my own screener which has a socket connection streaming about 7k symbols. One of my screens includes screening for stocks with a certain volatility level for the past 15min lets say.

These stocks then become viable for the inside bar strategy above. So for the next 15 min I want to run that strategy only on the stocks that were a result of my volatility screener. So my idea was to set the strategy to run on a DataSet then dynamically update that DataSet every 15min but my understanding now is that it is not possible as when the strategy is registered through the strategy monitor it is only set to run on the symbols that were in the DataSet at the time of initiating the strategy in the strategy monitor which is unfortunate.



0
Glitch8
 ( 9.28% )
- ago
#13
Hmm it sounds like a job for a new WL8 "Client Extension" to be honest. It could run a designated Strategy periodically on a DataSet on a scheduled or some kind of event-based basis. It's fairly straightforward to create a Client Extension and we have an example of one in the WL8 Extensions demo project on Gitbub. The Extension could use the StrategyRunner class to run the Strategy.
0
- ago
#14
Thanks for the advice @Glitch. Is the StrategyRunner only for initiating backtests or it is possible to kick off a live strategy and stage or auto place orders? From the docs I am only able to make out the fact that it can kick off backtests.
0

Reply

Bookmark

Sort