Storing positions
Atom
11/7/2017
Johan Kirsten


Hi

I need to store my positions so that when my application starts up it can load the existing positions. The code I use is:

Code

var dataPath = @"Data\" + _connectorAccount.AccountName;
_entityRegistry = new CsvEntityRegistry(dataPath);
_storageRegistry = new StorageRegistry
{
DefaultDrive = new LocalMarketDataDrive(dataPath)
};

_connector.InitializeStorage(_entityRegistry, _storageRegistry);
_entityRegistry.Init();

_connector.StorageAdapter.DaysLoad = DateTime.Now.Subtract(_connectorAccount.StartTrading.Value);

_connector.StorageAdapter.Format = StorageFormats.Csv;
_connector.StorageAdapter.Load();


The problem is that when I connect to TWS, I get the following error message:

Message 'Connect,T(L)=2017/11/06 21:25:31.278,Error=At least one connection should be made.' caused processing error.

with inner exception message:

The given key was not present in the dictionary.

and inner exception stack trace:

at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Ecng.Collections.SynchronizedDictionary`2.get_Item(TKey key)
at StockSharp.Algo.Connector.ProcessConnectMessage(BaseConnectionMessage message)
at StockSharp.Algo.Connector.OnProcessMessage(Message message)



Support

Avatar
Date: 11/8/2017
Reply


Could you please send us small example for reproduce? support@stocksharp.com
Thanks:

Johan Kirsten

Avatar
Date: 11/9/2017
Reply


Hi

I think I found the problem. When I changed the code as follows, it worked:

Code

var adapter = _connector.Adapter.InnerAdapters.OfType<InteractiveBrokersMessageAdapter>().First();

_connector.InitializeStorage(_entityRegistry, _storageRegistry);

_connector.Adapter.InnerAdapters.Add(adapter);
Thanks: Support

Support

Avatar
Date: 11/9/2017
Reply


Yes, InitializeStorage will reset entire adapter settings. Including all inner adapters.
Thanks:


Attach files by dragging & dropping, , or pasting from the clipboard.

loading
clippy