private Security GetSecurity(AlorTable table, object[] values, AlorColumn codeColumn, AlorColumn boardColumn) { if (table == null) { throw new ArgumentNullException(nameof(table)); } if (values == null) { throw new ArgumentNullException(nameof(values)); } if (codeColumn == null) { throw new ArgumentNullException(nameof(codeColumn)); } if (boardColumn == null) { throw new ArgumentNullException(nameof(boardColumn)); } var secCode = table.GetValue <string>(values, codeColumn); var secBoard = ExchangeBoard.GetBoard(table.GetValue <string>(values, boardColumn)); var id = SecurityIdGenerator.GenerateId(secCode, secBoard); return(GetSecurity(id, name => { var security = EntityFactory.CreateSecurity(name); security.Board = secBoard; security.Code = secCode; return security; }, security => false)); }
private static void CloseTable(AlorTable table) { if (table == null) { throw new ArgumentNullException("table"); } if (table.MetaTable != null && table.MetaTable.ID != 0) { table.MetaTable.Close(table.MetaTable.ID); } }
private void OpenTable(AlorTable table, Action<int, object[]> handler, bool openTable = true) { if (table == null) throw new ArgumentNullException("table"); var slotTables = (ISlotTables)_slot.tables; if (slotTables == null) throw new ArgumentException(LocalizedStrings.Str3701); for (var i = 1; i < (slotTables.Count + 1); i++) { var metaTable = (SlotTable)slotTables.Item[i]; if (table.Name == metaTable.Name) { table.MetaTable = metaTable; break; } } var meta = table.MetaTable; if (meta == null) throw new ArgumentException(LocalizedStrings.Str3702Params.Put(table.Name)); if (openTable && handler == null) throw new ArgumentNullException("handler"); Action<int, int, object> safeHandler = (openIdLocal, rowIdLocal, fieldsLocal) => Async(() => { //RaiseNewDataExported(); //ProcessEvents(() => handler(openIdLocal, (object[])fieldsLocal)); }); table.Columns = ManagerColumns.GetColumnsBy(table.Type).ToList(); if (openTable) { meta.AddRow += (openId, rowId, fields) => safeHandler(openId, rowId, fields); meta.UpdateRow += (openId, rowId, fields) => safeHandler(openId, rowId, fields); //meta.Error += (openId, errorCode, errorDescription) => RaiseProcessDataError(new AlorException(errorDescription, (SFE)errorCode)); meta.Open(_slot.ID, meta.Name); if (meta.ID == 0) throw new ArgumentException(LocalizedStrings.Str3703Params.Put(table.Name), "table"); } else { meta.AddRow += OnQuote; meta.UpdateRow += OnQuote; } }
/// <summary> /// Создать подключение. /// </summary> /// <param name="slotId">Номер слота.</param> /// <param name="address">Адрес сервера.</param> /// <param name="login">Логин.</param> /// <param name="password">Пароль.</param> public AlorTrader(int slotId, string address, string login, string password) { if (address == null) { throw new ArgumentNullException("address"); } if (login.IsEmpty()) { throw new ArgumentNullException("login"); } if (password.IsEmpty()) { throw new ArgumentNullException("password"); } Address = address; Login = login; _password = password.To <SecureString>(); _slot = new Slot(); _slot.Open(slotId); _slot.Connected += SlotConnected; _slot.Disconnected += SlotDisconnected; _slot.Error += SlotError; SecuritiesTable = new AlorTable(AlorTableTypes.Security, "SECURITIES", RaiseProcessDataError); TradesTable = new AlorTable(AlorTableTypes.Trade, "ALL_TRADES", RaiseProcessDataError); OrdersTable = new AlorTable(AlorTableTypes.Order, "ORDERS", RaiseProcessDataError); StopOrdersTable = new AlorTable(AlorTableTypes.StopOrder, "STOPORDERS", RaiseProcessDataError); MyTradesTable = new AlorTable(AlorTableTypes.MyTrade, "TRADES", RaiseProcessDataError); QuotesTable = new Dictionary <int, AlorTable>(); PortfoliosTable = new AlorTable(AlorTableTypes.Portfolio, "TRDACC", RaiseProcessDataError); HoldingTable = new AlorTable(AlorTableTypes.Position, "HOLDING", RaiseProcessDataError); MoneyPositionTable = new AlorTable(AlorTableTypes.Money, "POSITIONS", RaiseProcessDataError); TimeTable = new AlorTable(AlorTableTypes.Time, "TESYSTIME", RaiseProcessDataError); AlorManagerColumns.InitMetadata(); ManagerColumns = new AlorManagerColumns(); Synchronized(); _slot.Synchronized += SlotSynchronized; }
/// <summary> /// Начать получать котировки (стакан) по инструменту. /// Значение котировок можно получить через метод <see cref="IConnector.GetMarketDepth"/>. /// </summary> /// <param name="security">Инструмент, по которому необходимо начать получать котировки.</param> protected override bool OnRegisterMarketDepth(Security security) { var quotesTable = new AlorTable(AlorTableTypes.Quote, "ORDERBOOK", RaiseProcessDataError); OpenTable(quotesTable, null, false); _orderBooks.SyncDo(d => { if (!d.ContainsValue(security)) { var id = quotesTable.MetaTable.OpenOrderbook(_slot.ID, security.Board.Code, security.Code); if (id < 1) { throw new InvalidOperationException(LocalizedStrings.Str3709Params.Put(security.Id)); } QuotesTable[id] = quotesTable; d.Add(id, security); } }); return(true); }
private static void CloseTable(AlorTable table) { if (table == null) throw new ArgumentNullException("table"); if (table.MetaTable != null && table.MetaTable.ID != 0) table.MetaTable.Close(table.MetaTable.ID); }
private Security GetSecurity(AlorTable table, object[] values, AlorColumn codeColumn, AlorColumn boardColumn) { if (table == null) throw new ArgumentNullException("table"); if (values == null) throw new ArgumentNullException("values"); if (codeColumn == null) throw new ArgumentNullException("codeColumn"); if (boardColumn == null) throw new ArgumentNullException("boardColumn"); var secCode = table.GetValue<string>(values, codeColumn); var secBoard = ExchangeBoard.GetBoard(table.GetValue<string>(values, boardColumn)); var id = SecurityIdGenerator.GenerateId(secCode, secBoard); return null; //return GetSecurity(id, name => //{ // var security = EntityFactory.CreateSecurity(name); // security.Board = secBoard; // security.Code = secCode; // return security; //}, security => false); }
/// <summary> /// Создать подключение. /// </summary> /// <param name="slotId">Номер слота.</param> /// <param name="address">Адрес сервера.</param> /// <param name="login">Логин.</param> /// <param name="password">Пароль.</param> public AlorTrader(int slotId, string address, string login, string password) { if (address == null) throw new ArgumentNullException("address"); if (login.IsEmpty()) throw new ArgumentNullException("login"); if (password.IsEmpty()) throw new ArgumentNullException("password"); Address = address; Login = login; _password = password.To<SecureString>(); _slot = new Slot(); _slot.Open(slotId); _slot.Connected += SlotConnected; _slot.Disconnected += SlotDisconnected; _slot.Error += SlotError; SecuritiesTable = new AlorTable(AlorTableTypes.Security, "SECURITIES", RaiseProcessDataError); TradesTable = new AlorTable(AlorTableTypes.Trade, "ALL_TRADES", RaiseProcessDataError); OrdersTable = new AlorTable(AlorTableTypes.Order, "ORDERS", RaiseProcessDataError); StopOrdersTable = new AlorTable(AlorTableTypes.StopOrder, "STOPORDERS", RaiseProcessDataError); MyTradesTable = new AlorTable(AlorTableTypes.MyTrade, "TRADES", RaiseProcessDataError); QuotesTable = new Dictionary<int, AlorTable>(); PortfoliosTable = new AlorTable(AlorTableTypes.Portfolio, "TRDACC", RaiseProcessDataError); HoldingTable = new AlorTable(AlorTableTypes.Position, "HOLDING", RaiseProcessDataError); MoneyPositionTable = new AlorTable(AlorTableTypes.Money, "POSITIONS", RaiseProcessDataError); TimeTable = new AlorTable(AlorTableTypes.Time, "TESYSTIME", RaiseProcessDataError); AlorManagerColumns.InitMetadata(); ManagerColumns = new AlorManagerColumns(); Synchronized(); _slot.Synchronized += SlotSynchronized; }
/// <summary> /// Начать получать котировки (стакан) по инструменту. /// Значение котировок можно получить через метод <see cref="IConnector.GetMarketDepth"/>. /// </summary> /// <param name="security">Инструмент, по которому необходимо начать получать котировки.</param> protected override bool OnRegisterMarketDepth(Security security) { var quotesTable = new AlorTable(AlorTableTypes.Quote, "ORDERBOOK", RaiseProcessDataError); OpenTable(quotesTable, null, false); _orderBooks.SyncDo(d => { if (!d.ContainsValue(security)) { var id = quotesTable.MetaTable.OpenOrderbook(_slot.ID, security.Board.Code, security.Code); if (id < 1) throw new InvalidOperationException(LocalizedStrings.Str3709Params.Put(security.Id)); QuotesTable[id] = quotesTable; d.Add(id, security); } }); return true; }
private void OpenTable(AlorTable table, Action <int, object[]> handler, bool openTable = true) { if (table == null) { throw new ArgumentNullException(nameof(table)); } var slotTables = (ISlotTables)_slot.tables; if (slotTables == null) { throw new ArgumentException(LocalizedStrings.Str3701); } for (var i = 1; i < (slotTables.Count + 1); i++) { var metaTable = (SlotTable)slotTables.Item[i]; if (table.Name == metaTable.Name) { table.MetaTable = metaTable; break; } } var meta = table.MetaTable; if (meta == null) { throw new ArgumentException(LocalizedStrings.Str3702Params.Put(table.Name)); } if (openTable && handler == null) { throw new ArgumentNullException(nameof(handler)); } Action <int, int, object> safeHandler = (openIdLocal, rowIdLocal, fieldsLocal) => Async(() => { RaiseNewDataExported(); ProcessEvents(() => handler(openIdLocal, (object[])fieldsLocal)); }); table.Columns = ManagerColumns.GetColumnsBy(table.Type).ToList(); if (openTable) { meta.AddRow += (openId, rowId, fields) => safeHandler(openId, rowId, fields); meta.UpdateRow += (openId, rowId, fields) => safeHandler(openId, rowId, fields); meta.Error += (openId, errorCode, errorDescription) => RaiseProcessDataError(new AlorException(errorDescription, (SFE)errorCode)); meta.Open(_slot.ID, meta.Name); if (meta.ID == 0) { throw new ArgumentException(LocalizedStrings.Str3703Params.Put(table.Name), nameof(table)); } } else { meta.AddRow += OnQuote; meta.UpdateRow += OnQuote; } }
/// <summary> /// добавляет все возможные столбцы по таблице /// </summary> /// <param name="table"></param> public void AddAllBy(AlorTable table) { AllAlorColumn.Where(column => column.TableType == table.Type).ForEach(Add); }
/// <summary> /// Удаляет все возможное столбцы по таблице /// </summary> /// <param name="table"></param> public void RemoveAllBy(AlorTable table) { AllAlorColumn.Where(column => column.TableType == table.Type).ForEach(Remove); }