- ago
I am trying to set a commission value for backtesting in a custom MarketDetails instance from an extension I created. I get a NullReferenceException on that set statement. I do not understand why. Any help is much appreciated.

Offending statement
CODE:
MarketManager.SetCommission(wlMarketDetails, wlMarket.GetBackTextCommission());

The "wlMarketDetails" is the instance I created and filled with custom info. The "wlMarket.GetBackTextCommission()" statement (custom method) returns the commission as a percentage of traded value.

Exception details:
CODE:
System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object. Source=WealthLab.Core StackTrace: at WealthLab.Core.MarketManager.RemoveRepository(Object , Object , Object ) This exception was originally thrown at this call stack: WealthLab.Core.MarketManager.RemoveRepository(object, object, object)
0
460
Solved
6 Replies

Reply

Bookmark

Sort
- ago
#1
Glitch will correct me on this but I don't think you're supposed to modify these properties in custom code.
0
- ago
#2
I am using the system from India and I need a custom market details instance to use. The MarketManager reference - https://www.wealth-lab.com/Support/ApiReference/MarketManager says that it can be done.
QUOTE:
The MarketManager is intended to be used primarily by developers of custom Historical Data Provider adapters. These adapters may need to install new markets (MarketDetail instances) into the MarketManager, or new symbols (SymbolInfo instances).
0
- ago
#3
You can define custom commission on a Market or Symbol basis via Tools menu > Markets & Symbols. The latter has priority over a Market's commission amount.
0
- ago
#4
Thanks Eugene. That is one way of doing it.

However, I have my own broker adapter and am fetching the details from my broker. I would prefer setting it dynamically from the data I fetch from my broker rather than doing it in the WealthLab UI.

For your reference, here is the complete code snippet for the context
CODE:
var existingWlMarketDetails = MarketManager.FindMarket(wlMarket.Name); var wlMarketDetails = existingWlMarketDetails ?? new MarketDetails(); // Update properties wlMarketDetails.Name = wlMarket.Name; wlMarketDetails.SecurityType = wlMarket.SecurityType; wlMarketDetails.BenchmarkSymbol = wlMarket.BenchmarkSymbol; wlMarketDetails.Currency = "INR"; wlMarketDetails.BaseTimeZone = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time").Id; wlMarketDetails.QuantityDecimals = wlMarket.Exchange.QuantityDecimals; wlMarketDetails.DisplayDecimals = wlMarket.Exchange.PriceDecimals; // Add/update if (existingWlMarketDetails != null) {    MarketManager.UpdateMarket(wlMarketDetails); } else {    MarketManager.AddMarket(wlMarketDetails, false); } // Set commission try {    MarketManager.SetCommission(wlMarketDetails, wlMarket.GetBackTextCommission()); } catch { }
0
- ago
#5
Try to call this method in the first place before making any other MM calls:
CODE:
MarketManager.Initialize();
0
Best Answer
- ago
#6
That resolved the issue.

Thank you very much, Eugene!
1

Reply

Bookmark

Sort