I am creating a custom adapters library (C# Library) for Indian markets. Behind the scenes, I communicate with an Indian broker's REST API. I hence need to configure certain configs like API Key, API Secret etc.
The question I have is:
I am creating multiple adapters - HistoricData, StreamingData, Broker, etc.- that use the same backend REST API. Where should I configure the parameters for such a common configuration?
If I attach these config parameters to every adapter, the user will have to enter them multiple times in the WealthLab UI. How can I declare a single configuration set that multiple adapters can use?
If I create Parameter instances for common configuration values, store them globally, and for each adapter, simply call Parameters.AddRange(...). Will this work? I mean if the user modifies a config value in one adapter's config in the WealthLab UI, will it also update the value of the config for another linked adapter automatically?
The question I have is:
I am creating multiple adapters - HistoricData, StreamingData, Broker, etc.- that use the same backend REST API. Where should I configure the parameters for such a common configuration?
If I attach these config parameters to every adapter, the user will have to enter them multiple times in the WealthLab UI. How can I declare a single configuration set that multiple adapters can use?
If I create Parameter instances for common configuration values, store them globally, and for each adapter, simply call Parameters.AddRange(...). Will this work? I mean if the user modifies a config value in one adapter's config in the WealthLab UI, will it also update the value of the config for another linked adapter automatically?
Rename
I use this pattern in my similar extensions:
- Create a "Connection" object that is derived from Configurable and has the parameters your adapters need.
- Use a singleton pattern to expose one instance of the Connection object that is easy to access.
- Make sure the historical, streaming, broker classes use the same ConfigKey as the "Connection" object.
- I use singleton pattern to expose instances of these classes too.
- In the adapter classes ProcessConfig methods, I call a method in the "Connection" object that syncs the parameters across all 3 adapter classes.
Example (code taken from TradeStation extension under development)
Connection object code:
Streaming adapter code (similar code for Historical and Broker adapters):
- Create a "Connection" object that is derived from Configurable and has the parameters your adapters need.
- Use a singleton pattern to expose one instance of the Connection object that is easy to access.
- Make sure the historical, streaming, broker classes use the same ConfigKey as the "Connection" object.
- I use singleton pattern to expose instances of these classes too.
- In the adapter classes ProcessConfig methods, I call a method in the "Connection" object that syncs the parameters across all 3 adapter classes.
Example (code taken from TradeStation extension under development)
Connection object code:
CODE:
public class TradeStationConnection : Configurable { //constructor public TradeStationConnection() { _webClient = new WLWebClient(); } //instance public static TradeStationConnection Instance { get { if (_instance == null) _instance = new TradeStationConnection(); return _instance; } } //parameters public override void GenerateParameters() { AddParameter("Use Simulator Account?", ParameterType.Boolean, false); } //connected? public bool IsConnected { get; set; } = false; //Use Sim account? public bool UseSim => Parameters[0].AsBoolean; //URL prefix public string UrlPrefix => UseSim ? "<a href="https://sim-api.tradestation.com/v3/" target="_blank">https://sim-api.tradestation.com/v3/</a>" : "<a href="https://api.tradestation.com/v3/" target="_blank">https://api.tradestation.com/v3/</a>"; //connect public void Connect() { //perform connection code to connect to TS... IsConnected = true; } //Config type - parameter list public override ConfigurableType ConfigurableType => ConfigurableType.ParameterList; //Name public override string Name => "TradeStation"; //config key public override string ConfigKey => "TradeStation"; //broker, historical, streaming, call this when their parameters change public void ParametersChanged(ParameterList pl) { bool oldSim = UseSim; Parameters = pl.Clone(); if (TradeStationBroker.Instance != null) TradeStationBroker.Instance.Parameters.AssignValues(pl); if (TradeStationStreaming.Instance != null) TradeStationStreaming.Instance.Parameters.AssignValues(pl); if (TradeStationHistorical.Instance != null) TradeStationHistorical.Instance.Parameters.AssignValues(pl); SaveConfig(); }
Streaming adapter code (similar code for Historical and Broker adapters):
CODE:
//constructor public TradeStationStreaming() { Instance = this; } //Instance public static TradeStationStreaming Instance { get; set; } //parameters public override void GenerateParameters() { Parameters = TradeStationConnection.Instance.Parameters.Clone(); } //Name public override string Name => "TradeStation"; //description public override string Description => "Provides streaming market data from TradeStation."; //URL public override string URL => "<a href="https://www.tradestation.com/" target="_blank">https://www.tradestation.com/</a>"; //Glyph public override string GlyphResource => "WealthLab.TradeStation.Glyphs.TradeStation.png"; //uses parameter list public override ConfigurableType ConfigurableType => ConfigurableType.ParameterList; //have Connection instance processes the config public override void ProcessConfig() { base.ProcessConfig(); TradeStationConnection.Instance.ParametersChanged(Parameters); } //config key public override string ConfigKey => "TradeStation";
Your Response
Post
Edit Post
Login is required