← Zurück

Storing positions

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:


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.Dictionary2.get_Item(TKey key) at Ecng.Collections.SynchronizedDictionary2.get_Item(TKey key) at StockSharp.Algo.Connector.ProcessConnectMessage(BaseConnectionMessage message) at StockSharp.Algo.Connector.OnProcessMessage(Message message)

Kommentare (3)

Anmelden oder Konto erstellen, Melden Sie sich an oder registrieren Sie sich, um einen Kommentar zu hinterlassen

Support
Support

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

Johan Kirsten
Johan Kirsten Autor

Hi

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


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

            _connector.InitializeStorage(_entityRegistry, _storageRegistry);

            _connector.Adapter.InnerAdapters.Add(adapter);

Support
Support
Support

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