﻿<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/css' href='https://stocksharp.ru/css/style.css'?>
<?xml-stylesheet type='text/css' href='https://stocksharp.ru/css/bbeditor.css'?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="html">Storing positions</title>
  <id>~/topic/8796/storing-positions/</id>
  <rights type="text">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  <updated>2026-06-14T20:58:33Z</updated>
  <logo>https://stocksharp.ru/images/logo.png</logo>
  <link href="https://stocksharp.ru/handlers/atom.ashx?category=topic&amp;id=8796" rel="self" type="application/rss+xml" />
  <entry>
    <id>https://stocksharp.ru/posts/m/41515/</id>
    <title type="text">Hi I need to store my positions so that when my application starts up it can load the existing posit...</title>
    <published>2017-11-06T22:27:33Z</published>
    <updated>2017-11-06T22:27:33Z</updated>
    <author>
      <name>Johan Kirsten</name>
      <uri>https://stocksharp.ru/users/99551/</uri>
      <email>info@stocksharp.ru</email>
    </author>
    <content type="html">&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I need to store my positions so that when my application starts up it can load the existing positions. The code I use is:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
var dataPath = @&amp;quot;Data\&amp;quot; + _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();

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The problem is that when I connect to TWS, I get the following error message:&lt;/p&gt;
&lt;p&gt;Message 'Connect,T(L)=2017/11/06 21:25:31.278,Error=At least one connection should be made.' caused processing error.&lt;/p&gt;
&lt;p&gt;with inner exception message:&lt;/p&gt;
&lt;p&gt;The given key was not present in the dictionary.&lt;/p&gt;
&lt;p&gt;and inner exception stack trace:&lt;/p&gt;
&lt;p&gt;at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary&lt;code&gt;2.get_Item(TKey key) at Ecng.Collections.SynchronizedDictionary&lt;/code&gt;2.get_Item(TKey key)
at StockSharp.Algo.Connector.ProcessConnectMessage(BaseConnectionMessage message)
at StockSharp.Algo.Connector.OnProcessMessage(Message message)&lt;/p&gt;
</content>
    <rights type="html">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  </entry>
</feed>