Example #1
0
        //private static Timer _timer2 =
        //    new Timer(CheckSubs, null, 1000, 1000);

        //private static void CheckSubs(object state)
        //{
        //    var brokenSubs = Level2List.Where(x => x.Level2Data.Count == 0).ToList();
        //    foreach (var sub in brokenSubs)
        //    {
        //        TXmlConnector.ConnectorSendCommand(
        //            ConnectorCommands.SubUnsubCommand("subscribe", "quotes", sub.Board, sub.Seccode));
        //    }
        //}
        private static void ClearSubs(object state)
        {
            var            windows = _dispatcher.Invoke(() => Application.Current.Windows);
            List <IAnchor> list    = new List <IAnchor>();

            foreach (Window window in windows)
            {
                var context = _dispatcher.Invoke(() => window.DataContext);
                if (context is IAnchor)
                {
                    list.Add((IAnchor)context);
                }
            }

            Level2Subscription[] arr = new Level2Subscription[Level2List.Count];
            Level2List.CopyTo(arr, 0);
            foreach (var level2Subscription in arr)
            {
                var sub = list.Count(c => c.Board == level2Subscription.Board &&
                                     c.Seccode == level2Subscription.Seccode);
                if (sub == 0)
                {
                    TXmlConnector.ConnectorSendCommand(
                        ConnectorCommands.SubUnsubCommand("unsubscribe", "quotes", level2Subscription.Board, level2Subscription.Seccode));
                    var subscription = level2Subscription;
                    Level2List.TryTake(out subscription);
                }
            }
        }
Example #2
0
        private void ChartWindow_OnClosing(object sender, CancelEventArgs e)
        {
            var cmd = ConnectorCommands.SubUnbubTics("unsubscribe_ticks", _board, _seccode, "1", "true");

            TXmlConnector.ConnectorSendCommand(cmd);
            TXmlConnector.SendNewTicks -= TicksToCandles;
        }
Example #3
0
        public void GetInfo()
        {
            string cmd;

            if (!MainWindowViewModel.IsConnected || CurrentClient == null)
            {
                return;
            }
            //if mct - request mct portfolio
            if (ShowPortfolioMCT)
            {
                cmd = $"<command id=\"get_portfolio_mct\" client=\"{CurrentClient.Id}\" />";
                TXmlConnector.ConnectorSendCommand(cmd);
            }
            else
            {
                cmd = $"<command id=\"get_united_portfolio\" client=\"{CurrentClient.Id}\" />";
                var res         = TXmlConnector.ConnectorSendCommand(cmd);
                var orderResult = (OrderResult) new XmlSerializer(typeof(OrderResult)).Deserialize(new StringReader(res));
                //check if getting united portfolio is possible
                if (orderResult.Success == "false")
                {
                    //if impossible - get mct portfolio for this session
                    ShowPortfolioMCT = true;
                    cmd = $"<command id=\"get_portfolio_mct\" client=\"{CurrentClient.Id}\" />";
                    TXmlConnector.ConnectorSendCommand(cmd);
                }
            }
        }
Example #4
0
        //History request
        private void GetHistory()
        {
            UpdateWindowArgs(new ChartArgs(SelectedTimeframe, DaysBack, ToggleTrendlines));
            int count = 0;

            //Max candles per day for each period
            switch (_periodId)
            {
            case 1:
                count = 600;
                break;

            case 2:
                count = 120;
                break;

            case 3:
                count = 40;
                break;

            case 4:
                count = 10;
                break;

            case 5:
                count = 1;
                break;
            }

            TXmlConnector.ConnectorSendCommand(
                $"<command id=\"gethistorydata\"><security><board>{Board}</board><seccode>{Seccode}</seccode></security><period>{_periodId}</period><count>{count + _daysBack * count}</count><reset>true</reset></command>");

            TXmlConnector.SendNewCandles += ProcessCandles;
        }
Example #5
0
        //private static Timer _timer2 = new Timer(CheckSubs, null, 1000, 1000);

        //private static void CheckSubs(object state)
        //{
        //    var brokenSubs = TickList.Where(x => x.Ticks.Count == 0).ToList();
        //    foreach (var sub in brokenSubs)
        //    {
        //        sub.Tradeno = 1;
        //    }
        //    TXmlConnector.ConnectorSendCommand(ReturnTickSubsXml());
        //    foreach (var sub in brokenSubs)
        //    {
        //        sub.Tradeno = 0;
        //    }
        //}

        private static void ClearSubs(object state)
        {
            var            windows = _dispatcher.Invoke(() => Application.Current.Windows);
            List <IAnchor> list    = new List <IAnchor>();

            foreach (Window window in windows)
            {
                var context = _dispatcher.Invoke(() => window.DataContext);
                if (context is IAnchor)
                {
                    list.Add((IAnchor)context);
                }
            }

            TickSubscription[] arr = new TickSubscription[TickList.Count];
            TickList.CopyTo(arr, 0);
            foreach (var tickSubscription in arr)
            {
                var sub = list.Count(c => c.Board == tickSubscription.Board &&
                                     c.Seccode == tickSubscription.Seccode);
                if (sub == 0)
                {
                    var subscription = tickSubscription;
                    TickList.TryTake(out subscription);
                    TXmlConnector.ConnectorSendCommand(ReturnTickSubsXml());
                }
            }
        }
Example #6
0
        private void CancelOrderAction()
        {
            var cmd =
                $"<command id=\"cancelorder\"><transactionid>{SelectedOrder.Transactionid}</transactionid></command>";

            TXmlConnector.ConnectorSendCommand($"<command id=\"cancelorder\"><transactionid>{SelectedOrder.Transactionid}</transactionid></command>");
        }
Example #7
0
 //Closing event. Uninitialize dll, disconnect, close all windows.
 public void OnWindowClosing(object sender, CancelEventArgs e)
 {
     //if (Status == "Status: Disconnected")
     //{
     //
     //    return;
     //}
     //e.Cancel = true;if (_isConnected)
     IsShuttingDown = true;
     Connection.Stop(new TimeSpan(0, 0, 0, 100));
     SecVm = null;
     foreach (Window window in Application.Current.Windows)
     {
         if (window.GetType() != typeof(MainWindow) && window.GetType().Namespace.Split('.')[0] != "Microsoft")
         {
             //var context = window.DataContext as IWindow;
             //if (context != null)
             //    context.IsManuallyClosed = false
             if (window is IRememberPlacement)
             {
                 ((IRememberPlacement)window).IsManuallyClosed = false;
             }
             window.Close();
         }
     }
     TXmlConnector.ConnectorSendCommand("<command id=\"disconnect\"/>");
     Application.Current.Shutdown();
     //TXmlConnector.ConnectorUnInitialize();
 }
Example #8
0
 private void SendOrders()
 {
     Task.Run(() =>
     {
         var result = string.Empty;
         foreach (var order in Orders)
         {
             if (!order.Mkt)
             {
                 result = TXmlConnector.ConnectorSendCommand(
                     $"<command id=\"neworder\"><security><board>{order.Board}</board><seccode>{order.Seccode}</seccode></security><client>{order.Client}</client><union>{order.Union}</union><price>{order.Price}</price><quantity>{order.Size}</quantity><buysell>{order.BuySell}</buysell></command>");
             }
             else
             {
                 result = TXmlConnector.ConnectorSendCommand("<command id=\"neworder\"><security><board>" + order.Board +
                                                             "</board><seccode>" + order.Seccode +
                                                             "</seccode></security><client>" + order.Client +
                                                             "</client><union>" + order.Union + "</union><quantity>" +
                                                             order.Size + "</quantity><buysell>" + order.BuySell +
                                                             "</buysell><bymarket/>" + "</command>");
             }
         }
     });
     SaveToFile();
 }
Example #9
0
        private void GetHistory()
        {
            int count = 0;

            switch (_periodId)
            {
            case 1:
                count = 600;
                break;

            case 2:
                count = 120;
                break;

            case 3:
                count = 40;
                break;

            case 4:
                count = 10;
                break;
            }
            TXmlConnector.ConnectorSendCommand(
                $"<command id=\"gethistorydata\"><security><board>{_board}</board><seccode>{_seccode}</seccode></security><period>{_periodId}</period><count>{count + _daysBack * count}</count><reset>true</reset></command>");

            TXmlConnector.SendNewCandles += ProcessCandles;
        }
        public AllTradesCandlestickViewModel(string board, string seccode, List <DataForCandlestick> data)
        {
            Closing = new Command(arg => WindowClosing());
            Title   = $"Size selector {seccode}: {string.Join(", ", data.Select(item => item.Quantity))}";
            Seccode = seccode;
            TXmlConnector.ConnectorSendCommand(
                $"<command id=\"gethistorydata\"><security><board>{board}</board><seccode>{seccode}</seccode></security><period>2</period><count>120</count><reset>true</reset></command>");

            TXmlConnector.SendNewCandles += ProcessCandles;

            foreach (var dataForCandlestick in data)
            {
                foreach (var tradeItem in dataForCandlestick.Data)
                {
                    if (tradeItem.Buysell == "B")
                    {
                        BuySeries.Append(DateTime.Parse(tradeItem.Time), tradeItem.Price);
                    }
                    else
                    {
                        SellSeries.Append(DateTime.Parse(tradeItem.Time), tradeItem.Price);
                    }
                }
            }
        }
        public UnitedPortfolioViewModel()
        {
            ConfirmCommand = new Command(arg => Refresh());
            var cmd = $"<command id=\"get_united_portfolio\" client=\"{ClientInfo.Id}\" />";

            TXmlConnector.SendNewUnitedPortfolio += XmlConnector_OnSendUnitesPortfolio;
            TXmlConnector.ConnectorSendCommand(cmd);
        }
Example #12
0
        private void DetailsEvent(object sender, DataGridRowDetailsEventArgs e)
        {
            var news = (Inside_MMA.Models.News)e.Row.Item;

            //if (news.NewsBody == null)
            TXmlConnector.ConnectorSendCommand(
                $"<command id=\"get_news_body\" news_id=\"{news.Id}\"/>");
        }
Example #13
0
        public void OnWindowClosing(object sender, CancelEventArgs e)
        {
            var vm = ((VisiFireChart)sender).DataContext as VisiFireChartViewModel;

            _subscriptions.RemoveAll(item => item.Board == vm._board && item.Seccode == vm._seccode);
            TXmlConnector.ConnectorSendCommand(ConnectorCommands.SubscribeTicks(SecurityForTicks.ReturnSecuritiesXml(_subscriptions)));
            TXmlConnector.SendNewTicks -= vm.TicksToCandles;
        }
Example #14
0
 public static void UnsubAll()
 {
     foreach (var subscription in Level2List)
     {
         TXmlConnector.ConnectorSendCommand(
             ConnectorCommands.SubUnsubCommand("unsubscribe", "quotes", subscription.Board, subscription.Seccode));
         var level2Subscription = subscription;
         Level2List.TryTake(out level2Subscription);
     }
 }
Example #15
0
 public static void RefreshSub(string board, string seccode)
 {
     Task.Run(() => {
         var sub = TickList.FirstOrDefault(x => x.Board == board && x.Seccode == seccode);
         _dispatcher.Invoke(() => sub.TradeItems.Clear());
         sub.Sorted  = false;
         sub.Tradeno = 1;
         TXmlConnector.ConnectorSendCommand(ReturnTickSubsXml());
         sub.Tradeno = 0;
     });
 }
Example #16
0
        // отключение коннектора от сервера Транзак
        public static void Transaq_Disconnect()
        {
            DisconnectingReflect();
            string cmd = "<command id=\"disconnect\"/>";

            log.WriteLog("SendCommand: " + cmd);
            TXmlConnector.statusDisconnected.Reset();
            string res = TXmlConnector.ConnectorSendCommand(cmd);

            log.WriteLog("ServerReply: " + res);
        }
Example #17
0
        private async void PlaceOrder(object param)
        {
            var client    = ClientSelector.GetClient(Board);
            var usecredit = UseCredit ? "<usecredit/>" : "";
            var res1      = TXmlConnector.ConnectorSendCommand("<command id=\"neworder\"><security><board>" + Board +
                                                               "</board><seccode>" + Seccode +
                                                               "</seccode></security><client>" + client[0] + "</client>" +
                                                               "<union>" + client[1] + "</union>" +
                                                               "<quantity>" + Size + "</quantity>" +
                                                               "<buysell>" + param + "</buysell>" +
                                                               "<bymarket/>" + usecredit + "</command>");

            OpenTradingWindows();
            var res2         = string.Empty;
            var orderResult1 = (OrderResult)_serializer.Deserialize(new StringReader(res1));

            if (StopType == "Stop spread")
            {
                var direction       = param.ToString() == "B" ? "S" : "B";
                var activationPrice = direction == "B" ? _bestBuy + StoporderSpread : _bestSell - StoporderSpread;
                res2 = TXmlConnector.ConnectorSendCommand(
                    $"<command id=\"newstoporder\"><security><board>{Board}</board><seccode>{Seccode}</seccode></security><client>{client[0]}</client><union>{client[1]}</union><buysell>{direction}</buysell><stoploss><activationprice>{activationPrice}</activationprice><bymarket/><quantity>{Size}</quantity>{usecredit}</stoploss></command>");
            }
            if (StopType == "Manual stop")
            {
                var direction       = param.ToString() == "B" ? "S" : "B";
                var activationPrice = direction == "B" ? BuyPrice : SellPrice;
                res2 = TXmlConnector.ConnectorSendCommand(
                    $"<command id=\"newstoporder\"><security><board>{Board}</board><seccode>{Seccode}</seccode></security><client>{client[0]}</client><union>{client[1]}</union><buysell>{direction}</buysell><stoploss><activationprice>{activationPrice}</activationprice><bymarket/><quantity>{Size}</quantity>{usecredit}</stoploss></command>");
            }
            if (orderResult1.Success == "true")
            {
                await Dialog.ShowMessageAsync(this, "Message", $"Success. Transaction ID - {orderResult1.TransactionId}");
            }
            else
            {
                await Dialog.ShowMessageAsync(this, "Warning", orderResult1.Message);
            }
            if (res2.IsNullOrEmpty())
            {
                return;
            }
            var orderResult2 = (OrderResult)_serializer.Deserialize(new StringReader(res2));

            if (orderResult2.Success == "true")
            {
                await Dialog.ShowMessageAsync(this, "Message", $"Success. Transaction ID - {orderResult2.TransactionId}");
            }
            else
            {
                await Dialog.ShowMessageAsync(this, "Warning", orderResult2.Message);
            }
        }
Example #18
0
        public static void EditStoporder(string id, double price)
        {
            var editedStoporder = _stoporders.First(s => s.Transactionid == id);

            TXmlConnector.ConnectorSendCommand(
                $"<command id=\"cancelstoporder\"><transactionid>{editedStoporder.Transactionid}</transactionid></command>");
            var res = TXmlConnector.ConnectorSendCommand(ConnectorCommands.NewStopLoss(editedStoporder.Board,
                                                                                       editedStoporder.Seccode, editedStoporder.Client,
                                                                                       ClientSelector.GetClient(editedStoporder.Board)[1], editedStoporder.Buysell,
                                                                                       price.ToString(), editedStoporder.Stoploss[0].Orderprice ?? "",
                                                                                       editedStoporder.Stoploss[0].Quantity, editedStoporder.Stoploss[0].IsByMarket,
                                                                                       editedStoporder.Stoploss[0].Usecredit != "no"));
        }
Example #19
0
        private Candle[] _candleArray;                                  // это массив свечек
        public ChartWindow(string board, string seccode, int timeframe) //окно загружается.
        {
            _board     = board;
            _seccode   = seccode;
            _timeframe = timeframe;
            TXmlConnector.SendNewTicks += TicksToCandles;
            var cmd = ConnectorCommands.SubUnbubTics("subscribe_ticks", board, seccode, "1", "true");

            TXmlConnector.ConnectorSendCommand(cmd);
            InitializeComponent();
            // вызываем метод для создания чарта
            CreateChart();
        }
Example #20
0
        public static void EditOrder(string id, double price)
        {
            var editedOrder = _orders.First(o => o.Transactionid == id);
            var useCredit   = editedOrder.Board != "FUT" ? "<usecredit/>" : "";

            TXmlConnector.ConnectorSendCommand(
                $"<command id=\"cancelorder\"><transactionid>{id}</transactionid></command>");
            var res = TXmlConnector.ConnectorSendCommand("<command id=\"neworder\"><security><board>" + editedOrder.Board +
                                                         "</board><seccode>" + editedOrder.Seccode +
                                                         "</seccode></security><client>" + editedOrder.Client + "</client><union>" + editedOrder.Union + "</union><price>" + price + "</price><quantity>" +
                                                         editedOrder.Quantity + "</quantity><buysell>" + editedOrder.Buysell +
                                                         "</buysell>" + useCredit + "</command>");
        }
        private void Refresh()
        {
            //var cmd = IsClientChecked
            //    ? $"<command id=\"get_united_portfolio\" client=\"{UnionOrClient}\" />"
            //    : $"<command id=\"get_united_portfolio\" union=\"{UnionOrClient}\" />";

            UnitedPortfolioDataGridRows.Clear();
            UnitedPortfolioSecurityDataGridRowses.Clear();
            AssetDataGridRowses.Clear();
            MoneyDataGridRowses.Clear();
            ValuePartDataGridRowses.Clear();

            TXmlConnector.SendNewUnitedPortfolio += XmlConnector_OnSendUnitesPortfolio;
            TXmlConnector.ConnectorSendCommand($"<command id=\"get_united_portfolio\" client=\"{ClientInfo.Id}\" />");
        }
Example #22
0
 public void CancelAllStopordersMethod()
 {
     Task.Run(() => {
         var orders = ClientStoporders.ToArray();
         foreach (var order in orders)
         {
             if (order.Status != "matched")
             {
                 TXmlConnector.ConnectorSendCommand(
                     $"<command id=\"cancelstoporder\"><transactionid>{order.Transactionid}</transactionid></command>");
             }
             Thread.Sleep(250);
         }
     });
 }
Example #23
0
        private static void AddTick(string board, string seccode)
        {
            var sub = TickList.FirstOrDefault(x => x.Board == board && x.Seccode == seccode);

            if (sub == null)
            {
                sub = new TickSubscription
                {
                    Board   = board,
                    Seccode = seccode,
                    Tradeno = 1
                };
                TickList.Add(sub);
                TXmlConnector.ConnectorSendCommand(ReturnTickSubsXml());
                sub.Tradeno = 0;
            }
        }
Example #24
0
 public static void WatchlistSub(List <Security> list)
 {
     foreach (var sec in list)
     {
         if (!TickList.Select(t => t.Seccode).Contains(sec.Seccode))
         {
             TickList.Add(new TickSubscription {
                 Board = sec.Board, Seccode = sec.Seccode, Tradeno = 1
             });
         }
     }
     TXmlConnector.ConnectorSendCommand(ReturnTickSubsXml());
     foreach (var subscription in TickList)
     {
         subscription.Tradeno = 0;
     }
 }
Example #25
0
        public static ObservableCollection <Level2Item> AddLevel2Subscribtion(string board, string seccode)
        {
            var subscription = Level2List.FirstOrDefault(x => x.Board == board && x.Seccode == seccode);

            if (subscription == null)
            {
                subscription = new Level2Subscription
                {
                    Board   = board,
                    Seccode = seccode
                };
                Level2List.Add(subscription);
                TXmlConnector.ConnectorSendCommand(
                    ConnectorCommands.SubUnsubCommand("subscribe", "quotes", subscription.Board, subscription.Seccode));
            }
            return(subscription.Level2Data);
        }
Example #26
0
        public VisiFireChartViewModel(string board, string seccode)
        {
            _board   = board;
            _seccode = seccode;
            TXmlConnector.SendNewTicks += TicksToCandles;
            var sub = new SecurityForTicks {
                Board = board, Seccode = seccode, Tradeno = "1"
            };

            _subscriptions.Add(new SecurityForTicks {
                Board = board, Seccode = seccode, Tradeno = "1"
            });
            var cmd = ConnectorCommands.SubscribeTicks(SecurityForTicks.ReturnSecuritiesXml(_subscriptions));

            TXmlConnector.ConnectorSendCommand(cmd);
            _subscriptions.Last().Tradeno = "0";
        }
Example #27
0
        private async void Confirm_OnClick(object sender, RoutedEventArgs e)
        {
            var result = TXmlConnector.ConnectorSendCommand(
                $"<command id=\"change_pass\" oldpass=\"{OldPass.Password}\" newpass=\"{NewPass.Password}\"/>");

            if (result == "<result success=\"true\"/>")
            {
                await this.ShowMessageAsync("Result", "Password successfully changed");

                Close();
            }

            else
            {
                await this.ShowMessageAsync("Result", result);
            }
        }
Example #28
0
        public async void ShiftLeftClickStopOrder()
        {
            if (SelectedData == null)
            {
                return;
            }
            var price      = SelectedData.Price;
            var buysell    = SelectedData.BuySell == "buy" ? "S" : "B";
            var clientInfo = ClientSelector.GetClient(Board);
            var clientId   = clientInfo == null ? "-" : clientInfo[0];
            var size       = Level2Settings.Default.Size;
            var res        = await Dialog.ShowMessageAsync(this, "Stoporder", $"{Board} {Seccode}\r\nActivation price: {price}\r\nSize: {size}\r\nType: {buysell}\r\nClient: {clientId}",
                                                           MessageDialogStyle.AffirmativeAndNegative);

            if (res == MessageDialogResult.Negative)
            {
                return;
            }
            var str = TXmlConnector.ConnectorSendCommand($"<command id=\"newstoporder\"><security><board>{Board}</board><seccode>{Seccode}</seccode></security><client>{clientInfo[0]}</client><union>{clientInfo[1]}</union><buysell>{buysell}</buysell><stoploss><activationprice>{price}</activationprice><bymarket/><quantity>{size}</quantity>{UseCreditString}</stoploss></command>");
        }
Example #29
0
        ///////////////////////////////////////////////////////////////////////
        /// TRANSAQ METHODS
        ///////////////////////////////////////////////////////////////////////

        public static void Transaq_Connect()
        {
            ConnectingReflect();
            // формирование текста команды
            string cmd = "<command id=\"connect\">";

            cmd = cmd + "<login>" + sLogin + "</login>";
            cmd = cmd + "<password>" + sPassword + "</password>";
            cmd = cmd + "<host>" + sTransaqServerIP + "</host>";
            cmd = cmd + "<port>" + sTransaqServerPort + "</port>";
            cmd = cmd + "<rqdelay>100</rqdelay>";
            cmd = cmd + "<session_timeout>" + session_timeout.ToString() + "</session_timeout> ";
            cmd = cmd + "<request_timeout>" + request_timeout.ToString() + "</request_timeout>";
            cmd = cmd + "</command>";

            // отправка команды
            log.WriteLog("Transaq_Connect:::ServerRequest " + cmd);
            TXmlConnector.statusDisconnected.Reset();
            string res = TXmlConnector.ConnectorSendCommand(cmd);

            log.WriteLog("Transaq_Connect:::ServerReply " + res);
        }
Example #30
0
        private async void Confirm()
        {
            var client = ClientSelector.GetClient(Board);

            if (IsSmartStoporder && !CheckStoplossPrice())
            {
                return;
            }
            string stoploss   = $"<stoploss>{StopLossActivationPriceString}{StopLossOrderPrice}{_stopLossByMarketString}{StopLossQuantity}{_stopLossUseCreditString}{StopLossGuardTime}</stoploss>";
            string takeprofit = $"<takeprofit>{TakeProfitActivationPrice}{TakeProfitQuantity}{_takeProfitUseCreditString}{TakeProfitGuardTime}{TakeProfitCorrection}{TakeProfitSpread}<bymarket/></takeprofit>";

            if (stoploss == "<stoploss></stoploss>")
            {
                stoploss = string.Empty;
            }
            if (takeprofit == "<takeprofit><bymarket/></takeprofit>")
            {
                takeprofit = string.Empty;
            }
            var cmd =
                $"<command id=\"newstoporder\"><security>{BoardString}{SeccodeString}</security><client>{client[0]}</client><union>{client[1]}</union>{BuySell}{stoploss}{takeprofit}</command>";
            var orderResult = (OrderResult)_serializer.Deserialize(new StringReader(TXmlConnector.ConnectorSendCommand(cmd)));

            if (orderResult.Success == "true")
            {
                await Dialog.ShowMessageAsync(this, "Message", $"Success. Transaction ID - {orderResult.TransactionId}");

                OpenTradingWindows();
                if (!KeepOpen)
                {
                    Close();
                }
            }
            else
            {
                await Dialog.ShowMessageAsync(this, "Warning", orderResult.Message);
            }
        }