Дюшес
|
Date: 9/18/2012
|
|
|
|
|
Привет!
А можно ли добавить следующие строки (или сделайте по-своему, если коряво), чтобы самому каждый раз не добавлять в новых версиях коннектора?
Оно все равно нужно будет.
<u>AlfaWrapper.cs:</u>
const string _securityFields = "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, volatility, theor_price";
<u>AlfaTrader.cs:</u>
private void OnProcessSecurities(string data)
{
var result = AlfaUtils.Filter(data, _securitySubscribers);
foreach (var p in result)
{
var pair = p;
ProcessEvents(() =>
{
foreach (var d in pair.Value)
{
var details = d;
if (details[1].IsEmpty())
{
continue;
}
var id = details[4] + "@" + details[5];
GetSecurity(id, name =>
{
this.AddInfoLog("Security create : {0}", name);
var security = EntityFactory.CreateSecurity(id);
security.ExtensionInfo = new Dictionary<object, object>();
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<decimal>();
security.MarginSell = details[8].To<decimal>();
security.MinLotSize = details[19].To<int>();
security.SetPaperNo(details[0].To<int>());
security.SetCurrency(details[6]);
security.SetPlaceCode(details[5]);
**security.Volatility = details[20].To<decimal>();
security.TheorPrice = details[21].To<decimal>();**
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("Стоимость шага цены равна нулю для {0}.", 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<int>());
return security;
}, security =>
{
this.AddInfoLog("Security update {0}.", security.Id);
using (security.BeginUpdate())
{
security.BestAsk = new Quote
{
Price = details[13].To<decimal>(),
Volume = details[14].To<decimal>(),
Security = security,
OrderDirection = OrderDirections.Sell
};
security.BestBid = new Quote
{
Price = details[15].To<decimal>(),
Volume = details[16].To<decimal>(),
Security = security,
OrderDirection = OrderDirections.Buy
};
security.LowPrice = details[17].To<decimal>();
security.HighPrice = details[18].To<decimal>();
security.SetOpenInteres(details[10].To<long>());
security.OpenPrice = details[11].To<decimal>();
security.ClosePrice = details[12].To<decimal>();
**security.Volatility = details[20].To<decimal>();
security.TheorPrice = details[21].To<decimal>();**
// TODO: Add missing fields
}
return true;
});
}
});
}
}
Дополнительный файл <u>StringExtensions.cs:</u>
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using StockSharp.Algo.Derivatives;
using StockSharp.BusinessEntities;
using Ecng.Common;
/// <summary>
/// Расширение класса string для получения дополнительной информации по опционам
/// </summary>
public static class StringExtensions
{
private static string GetFutures(string cod, int month, int year)
{
Dictionary<string, string> UnderlyingSecurity = new Dictionary<string, string>
{
{ "GZ", "GAZP" },
{ "RI", "RTSI" },
{ "GM", "GMKR" },
{ "Si", "Si" },
{ "SR", "SBER" },
{ "VB", "VTBR" },
{ "RS", "RTSSTD" },
{ "UR", "UR" },
{ "SV", "SILV" },
{ "PT", "PLT" },
{ "PD", "PLD" },
{ "Eu", "Eu" },
{ "ED", "ED" },
{ "BR", "BR" },
{ "AU", "AUDU" },
};
if(month > 12) month -= 12;
if(month <= 3)
month = 3;
else if(month <= 6)
month = 6;
else if(month <= 9)
month = 9;
else if(month <= 12)
month = 12;
try {
return UnderlyingSecurity[cod] + "-" + month + "." + (year + 10) + "@FORTS";
} catch {
return null;
}
}
/// <summary>
/// Получить дополнительные поля по опционам: Страйк, Тип опциона, Базовый актив
/// </summary>
public static Security GetOptionInfo(this string security)
{
const string call = "ABCDEFGHIJKL";
//const string put = "MNOPQRSTUVWX";
Regex regex = new Regex(@"^([A-z]{2})(\d+)([A-z])([A-z])(\d)\Z", 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<decimal>(),
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<int>())
};
}
return null;
}
}
|