﻿<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/css' href='https://stocksharp.com/css/style.css'?>
<?xml-stylesheet type='text/css' href='https://stocksharp.com/css/bbeditor.css'?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="html">Опционы в Альфа-Директ</title>
  <id>~/topic/2892/optsiony-v-alfa-direkt/</id>
  <rights type="text">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  <updated>2026-06-19T03:19:55Z</updated>
  <logo>https://stocksharp.com/images/logo.png</logo>
  <link href="https://stocksharp.com/handlers/atom.ashx?category=topic&amp;id=2892" rel="self" type="application/rss+xml" />
  <entry>
    <id>https://stocksharp.com/posts/m/21438/</id>
    <title type="text">Дюшес: Спасибо! Код добавил, спасибо. </title>
    <published>2012-09-19T15:50:23Z</published>
    <updated>2012-09-19T15:50:23Z</updated>
    <author>
      <name>Sergey Masyura</name>
      <uri>https://stocksharp.com/users/701/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="@message(21425)" rel="nofollow" target="_blank"&gt;Дюшес&lt;/a&gt;:&lt;/strong&gt;
Спасибо!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Код добавил, спасибо.&lt;/p&gt;
</content>
    <rights type="html">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  </entry>
  <entry>
    <id>https://stocksharp.com/posts/m/21425/</id>
    <title type="text">Спасибо! </title>
    <published>2012-09-18T15:02:52Z</published>
    <updated>2012-09-18T15:02:52Z</updated>
    <author>
      <name>Дюшес</name>
      <uri>https://stocksharp.com/users/6407/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <content type="html">&lt;p&gt;Спасибо!&lt;/p&gt;
</content>
    <rights type="html">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  </entry>
  <entry>
    <id>https://stocksharp.com/posts/m/21424/</id>
    <title type="text">Дюшес: Привет! А можно ли добавить следующие строки (или сделайте по-своему, если коряво), чтобы сам...</title>
    <published>2012-09-18T14:12:25Z</published>
    <updated>2012-09-18T14:12:25Z</updated>
    <author>
      <name>Sergey Masyura</name>
      <uri>https://stocksharp.com/users/701/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="@message(21423)" rel="nofollow" target="_blank"&gt;Дюшес&lt;/a&gt;:&lt;/strong&gt;
Привет!&lt;/p&gt;
&lt;p&gt;А можно ли добавить следующие строки (или сделайте по-своему, если коряво), чтобы самому каждый раз не добавлять в новых версиях коннектора?
Оно все равно нужно будет.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Спасибо. Добавлю на этой неделе.&lt;/p&gt;
</content>
    <rights type="html">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  </entry>
  <entry>
    <id>https://stocksharp.com/posts/m/21423/</id>
    <title type="text">Привет! А можно ли добавить следующие строки (или сделайте по-своему, если коряво), чтобы самому каж...</title>
    <published>2012-09-18T13:54:15Z</published>
    <updated>2012-09-18T13:54:15Z</updated>
    <author>
      <name>Дюшес</name>
      <uri>https://stocksharp.com/users/6407/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <content type="html">&lt;p&gt;Привет!&lt;/p&gt;
&lt;p&gt;А можно ли добавить следующие строки (или сделайте по-своему, если коряво), чтобы самому каждый раз не добавлять в новых версиях коннектора?
Оно все равно нужно будет.&lt;/p&gt;
&lt;p&gt;&amp;lt;u&amp;gt;AlfaWrapper.cs:&amp;lt;/u&amp;gt;&lt;/p&gt;
&lt;div class="spoiler"&gt;&lt;p&gt;const string _securityFields = &amp;quot;paper_no, ANSI_name, mat_date, status, p_code, place_code, curr_code, go_buy, go_sell, board_code, open_pos_qty, open_price, close_price, sell, sell_qty, buy, buy_qty, min_deal, max_deal, lot_size, &lt;strong&gt;volatility, theor_price&lt;/strong&gt;&amp;quot;;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&amp;lt;u&amp;gt;AlfaTrader.cs:&amp;lt;/u&amp;gt;&lt;/p&gt;
&lt;details&gt;&lt;summary&gt;private void OnProcessSecurities(string data)
{
var result = AlfaUtils.Filter(data, _securitySubscribers);&lt;/summary&gt;
&lt;pre&gt;&lt;code&gt;foreach (var p in result)
{
    var pair = p; 

    ProcessEvents(() =&amp;gt;
    {
        foreach (var d in pair.Value)
        {
            var details = d;

            if (details[1].IsEmpty())
            {
                continue;
            }

            var id = details[4] + &amp;quot;@&amp;quot; + details[5];

            GetSecurity(id, name =&amp;gt;
            {
                this.AddInfoLog(&amp;quot;Security create : {0}&amp;quot;, name);

                var security = EntityFactory.CreateSecurity(id);
                security.ExtensionInfo = new Dictionary&amp;lt;object, object&amp;gt;();

                security.Name = details[1];
                security.ShortName = details[1];
                security.ExpiryDate = DateTime.Parse(details[2]);
                security.Code = details[4];
                security.State = AlfaUtils.SecurityStateFromAlfa(details[3]);

                // TODO: this must be done the in the AD task.
                var exCode = Wrapper.GetExchangeCode(details[5]);

                security.Exchange = AlfaUtils.ExchangeCodeToExchange(exCode);
                security.MarginBuy = details[7].To&amp;lt;decimal&amp;gt;();
                security.MarginSell = details[8].To&amp;lt;decimal&amp;gt;();
                security.MinLotSize = details[19].To&amp;lt;int&amp;gt;();

                security.SetPaperNo(details[0].To&amp;lt;int&amp;gt;());
                security.SetCurrency(details[6]);
                security.SetPlaceCode(details[5]);

                **security.Volatility = details[20].To&amp;lt;decimal&amp;gt;();
                security.TheorPrice = details[21].To&amp;lt;decimal&amp;gt;();**

                decimal priceStep, priceStepCost;

                // TODO: this must be done the in the AD task.
                Wrapper.GetPriceStepInfo(security, out priceStep, out priceStepCost);

                security.MinStepSize = priceStep;

                if (priceStepCost == 0)
                {
                    security.MinStepPrice = priceStep;
                    //this.AddWarningLog(&amp;quot;Стоимость шага цены равна нулю для {0}.&amp;quot;, security.Name);
                }
                else
                {
                    security.MinStepPrice = priceStepCost;
                }

                security.Type = AlfaUtils.BoardCodeToSecurityType(details[9]);

                **if(security.Type == SecurityTypes.Option)
                {
                    var sec = security.Code.GetOptionInfo();

                    security.OptionType = sec.OptionType;
                    security.Strike = sec.Strike;
                    security.UnderlyingSecurityId = sec.UnderlyingSecurityId;
                }**

                AddNativeSecurityId(security, details[0].To&amp;lt;int&amp;gt;());

                return security;
             }, security =&amp;gt;
             {
                this.AddInfoLog(&amp;quot;Security update {0}.&amp;quot;, security.Id);

                using (security.BeginUpdate())
                {
                    security.BestAsk = new Quote
                    {
                        Price = details[13].To&amp;lt;decimal&amp;gt;(),
                        Volume = details[14].To&amp;lt;decimal&amp;gt;(),
                        Security = security,
                        OrderDirection = OrderDirections.Sell
                    };

                    security.BestBid = new Quote
                    {
                        Price = details[15].To&amp;lt;decimal&amp;gt;(),
                        Volume = details[16].To&amp;lt;decimal&amp;gt;(),
                        Security = security,
                        OrderDirection = OrderDirections.Buy
                    };

                    security.LowPrice = details[17].To&amp;lt;decimal&amp;gt;();
                    security.HighPrice = details[18].To&amp;lt;decimal&amp;gt;();
                    security.SetOpenInteres(details[10].To&amp;lt;long&amp;gt;());
                    security.OpenPrice = details[11].To&amp;lt;decimal&amp;gt;();
                    security.ClosePrice = details[12].To&amp;lt;decimal&amp;gt;();

                    **security.Volatility = details[20].To&amp;lt;decimal&amp;gt;();
                    security.TheorPrice = details[21].To&amp;lt;decimal&amp;gt;();**
                            
                    // TODO: Add missing fields
                }

                return true;
            });
        }
    });
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;/details&gt;
&lt;p&gt;Дополнительный файл &amp;lt;u&amp;gt;StringExtensions.cs:&amp;lt;/u&amp;gt;&lt;/p&gt;
&lt;div class="spoiler"&gt;
&lt;pre&gt;&lt;code class="language-csharp"&gt;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;

using StockSharp.Algo.Derivatives;
using StockSharp.BusinessEntities;

using Ecng.Common;

/// &amp;lt;summary&amp;gt;
/// Расширение класса string для получения дополнительной информации по опционам
/// &amp;lt;/summary&amp;gt;
public static class StringExtensions
{
    private static string GetFutures(string cod, int month, int year)
    {
        Dictionary&amp;lt;string, string&amp;gt; UnderlyingSecurity = new Dictionary&amp;lt;string, string&amp;gt;
        {
            { &amp;quot;GZ&amp;quot;, &amp;quot;GAZP&amp;quot;   },
            { &amp;quot;RI&amp;quot;, &amp;quot;RTSI&amp;quot;   },
            { &amp;quot;GM&amp;quot;, &amp;quot;GMKR&amp;quot;   },
            { &amp;quot;Si&amp;quot;, &amp;quot;Si&amp;quot;     },
            { &amp;quot;SR&amp;quot;, &amp;quot;SBER&amp;quot;   },
            { &amp;quot;VB&amp;quot;, &amp;quot;VTBR&amp;quot;   },
            { &amp;quot;RS&amp;quot;, &amp;quot;RTSSTD&amp;quot; },
            { &amp;quot;UR&amp;quot;, &amp;quot;UR&amp;quot;     },
            { &amp;quot;SV&amp;quot;, &amp;quot;SILV&amp;quot;   },
            { &amp;quot;PT&amp;quot;, &amp;quot;PLT&amp;quot;    },
            { &amp;quot;PD&amp;quot;, &amp;quot;PLD&amp;quot;    },
            { &amp;quot;Eu&amp;quot;, &amp;quot;Eu&amp;quot;     },
            { &amp;quot;ED&amp;quot;, &amp;quot;ED&amp;quot;     },
            { &amp;quot;BR&amp;quot;, &amp;quot;BR&amp;quot;     },
            { &amp;quot;AU&amp;quot;, &amp;quot;AUDU&amp;quot;   },
        };

        if(month &amp;gt; 12) month -= 12;

        if(month &amp;lt;= 3)
          month = 3;
        else if(month &amp;lt;= 6)
          month = 6;
        else if(month &amp;lt;= 9)
          month = 9;
        else if(month &amp;lt;= 12)
          month = 12;

        try {
          return UnderlyingSecurity[cod] + &amp;quot;-&amp;quot; + month + &amp;quot;.&amp;quot; + (year + 10) + &amp;quot;@FORTS&amp;quot;;
        } catch {
          return null;
        }
    }

    /// &amp;lt;summary&amp;gt;
    /// Получить дополнительные поля по опционам: Страйк, Тип опциона, Базовый актив
    /// &amp;lt;/summary&amp;gt;
    public static Security GetOptionInfo(this string security)
    {
        const string call = &amp;quot;ABCDEFGHIJKL&amp;quot;;
        //const string put  = &amp;quot;MNOPQRSTUVWX&amp;quot;;

        Regex regex = new Regex(@&amp;quot;^([A-z]{2})(\d+)([A-z])([A-z])(\d)\Z&amp;quot;, RegexOptions.Compiled | RegexOptions.IgnoreCase);

        MatchCollection matches = regex.Matches(security);

        if(matches.Count == 1)
        {
            GroupCollection groups = matches[0].Groups;

            return new Security
                       {
                         Strike = groups[2].Value.To&amp;lt;decimal&amp;gt;(),
                         OptionType = (call.Contains(groups[4].Value.ToUpper()) ? OptionTypes.Call : OptionTypes.Put),
                         UnderlyingSecurityId = GetFutures(groups[1].Value.ToUpper(),
                                                            (int)Convert.ToChar(groups[4].Value.ToUpper()) - 64,
                                                            groups[5].Value.To&amp;lt;int&amp;gt;())
                       };
        }

        return null;
    }
}

&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
    <rights type="html">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  </entry>
  <entry>
    <id>https://stocksharp.com/posts/m/20966/</id>
    <title type="text">Нас интересует </title>
    <published>2012-08-22T21:09:55Z</published>
    <updated>2012-08-22T21:09:55Z</updated>
    <author>
      <name>969</name>
      <uri>https://stocksharp.com/users/628/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <content type="html">&lt;p&gt;Нас интересует&lt;/p&gt;
</content>
    <rights type="html">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  </entry>
  <entry>
    <id>https://stocksharp.com/posts/m/20573/</id>
    <title type="text">А я юзаю опционы как обычные инструменты ) По коду все также получить можно, считаю, что до выхода 4...</title>
    <published>2012-07-27T10:53:44Z</published>
    <updated>2012-07-27T10:53:44Z</updated>
    <author>
      <name>OvcharenkoVI</name>
      <uri>https://stocksharp.com/users/390/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <content type="html">&lt;p&gt;А я юзаю опционы как обычные инструменты ) По коду все также получить можно, считаю, что до выхода 4.0 смысла нет )&lt;/p&gt;
</content>
    <rights type="html">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  </entry>
  <entry>
    <id>https://stocksharp.com/posts/m/20515/</id>
    <title type="text">ra81: Какая именно поддержка планируется? На моем коннекторе таки дельтанейтральные стратегии заводи...</title>
    <published>2012-07-25T06:42:26Z</published>
    <updated>2012-07-25T06:42:26Z</updated>
    <author>
      <name>Sergey Masyura</name>
      <uri>https://stocksharp.com/users/701/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <content type="html">&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="@message(20514)" rel="nofollow" target="_blank"&gt;ra81&lt;/a&gt;:&lt;/strong&gt;
Какая именно поддержка планируется? На моем коннекторе таки дельтанейтральные стратегии заводили. Хватало.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Планируется посмотреть, что же собственно не хватает - какие поля у бумаг не заполняются, корректно ли обновляется информация. Судя по активности, пока что никому не надо [laugh]&lt;/p&gt;
</content>
    <rights type="html">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  </entry>
  <entry>
    <id>https://stocksharp.com/posts/m/20514/</id>
    <title type="text">Какая именно поддержка планируется? На моем коннекторе таки дельтанейтральные стратегии заводили. Хв...</title>
    <published>2012-07-25T05:07:42Z</published>
    <updated>2012-07-25T05:07:42Z</updated>
    <author>
      <name>ra81</name>
      <uri>https://stocksharp.com/users/16581/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <content type="html">&lt;p&gt;Какая именно поддержка планируется? На моем коннекторе таки дельтанейтральные стратегии заводили. Хватало.&lt;/p&gt;
</content>
    <rights type="html">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  </entry>
  <entry>
    <id>https://stocksharp.com/posts/m/20510/</id>
    <title type="text">В Альфа-коннекторе на данный момент отсутствует поддержка опционов. Поэтому небольшой опрос - кому-н...</title>
    <published>2012-07-24T18:56:35Z</published>
    <updated>2012-07-24T18:56:35Z</updated>
    <author>
      <name>Sergey Masyura</name>
      <uri>https://stocksharp.com/users/701/</uri>
      <email>info@stocksharp.com</email>
    </author>
    <content type="html">&lt;p&gt;В Альфа-коннекторе на данный момент отсутствует поддержка опционов. Поэтому небольшой опрос - кому-нибудь требуется? Если наберется около 10 желающих, запланирую в таски.&lt;/p&gt;
</content>
    <rights type="html">Copyright @ StockSharp Platform LLC 2010 - 2025</rights>
  </entry>
</feed>