Storing positions
Atom
07.11.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:

Код

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

Фотография
Дата: 08.11.2017
Ответить


Could you please send us small example for reproduce? support@stocksharp.com
Спасибо:

Johan Kirsten

Фотография
Дата: 09.11.2017
Ответить


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

Фотография
Дата: 09.11.2017
Ответить


Yes, InitializeStorage will reset entire adapter settings. Including all inner adapters.
Спасибо:


Добавить файлы через драг-н-дроп, , или вставить из буфера обмена.

loading
clippy