Exemple #1
0
 private void cbAccountSubscription_CheckedChanged(object sender, EventArgs e)
 {
     if (cbAccountSubscription.CheckState == CheckState.Checked)
     {
         try
         {
             if (_currentAccount != null)
             {
                 _accountBalanceSubscription = new AccountBalanceSubscription(this);
                 if (_igStreamApiClient != null)
                 {
                     _accountsStk = _igStreamApiClient.subscribeToAccountDetailsKey(_currentAccount,
                                                                                    _accountBalanceSubscription);
                     AppendActivityMessage("AccountDetails : Successfully Subscribed");
                 }
             }
         }
         catch (Exception ex)
         {
             AppendStreamingDataMessage(ex.Message);
         }
     }
     else
     {
         if ((_accountsStk != null) && (_igStreamApiClient != null))
         {
             _igStreamApiClient.UnsubscribeTableKey(_accountsStk);
             AppendActivityMessage("AccountDetails : Unsubscribe");
         }
     }
 }
Exemple #2
0
        public DemoDotNetClientForm()
        {
            InitializeComponent();

            _accountIds  = new Dictionary <string, string>();
            _accountsStk = new SubscribedTableKey();

            EnableCommandButtons(false);

            _watchlists       = new List <Watchlist>();
            _watchlistMarkets = new List <WatchlistMarket>();
            _orders           = new List <WorkingOrder>();
            _positions        = new List <OpenPosition>();

            cbPositions.Enabled      = false;
            cbOrders.Enabled         = false;
            cbWatchlistItems.Enabled = false;

            _igRestApiClient   = new IgRestApiClient();
            _igStreamApiClient = new IGStreamingApiClient();

            _APIKey = "8d341413c2eae2c35bb5b47a594ef08ae18cb3b7"; // *** TODO ENTER YOUR API KEY HERE ***
            passwordTextbox.Text   = "Kotik0483";                 // *** TODO Enter your password here ***
            identifierTextbox.Text = "ksbitlsoftdemo";            // *** TODO Enter your user name here ***
        }
Exemple #3
0
        // <Summary>
        // Lightstreamer Subscribe to L1 Prices...
        // </Summary>
        private void SubscribeToCharts(string[] chartEpics)
        {
            try
            {
                if (igStreamApiClient != null)
                {
                    ChartMarketData.Clear();
                    foreach (var epic in chartEpics)
                    {
                        IgPublicApiData.ChartModel ccd = new IgPublicApiData.ChartModel();
                        ccd.ChartEpic = epic;
                        ChartMarketData.Add(ccd);

                        AddStatusMessage("Subscribing to Chart Data (CandleStick ): " + ccd.ChartEpic);
                    }

                    _chartSubscribedTableKey = igStreamApiClient.SubscribeToChartCandleData(chartEpics, ChartScale.OneMinute, _chartSubscription);

                }
            }
            catch (Exception ex)
            {
                AddStatusMessage("Exception when trying to subscribe to Chart Candle Data: " + ex.Message);
            }
        }
Exemple #4
0
 private void cbTradeSubscription_CheckedChanged(object sender, EventArgs e)
 {
     try
     {
         if (_igStreamApiClient != null)
         {
             if (cbTradeSubscription.CheckState == CheckState.Checked)
             {
                 _tradeConfirmsSubscription = new TradeConfirmsSubscription(this);
                 _tradeSubscriptionStk      = _igStreamApiClient.subscribeToTradeSubscription(_currentAccount,
                                                                                              _tradeConfirmsSubscription);
                 AppendActivityMessage("TradeSubscription : Subscribe");
             }
             else
             {
                 if (_tradeSubscriptionStk != null)
                 {
                     _igStreamApiClient.UnsubscribeTableKey(_tradeSubscriptionStk);
                     AppendActivityMessage("TradeSubscription : Unsubscribe");
                 }
             }
         }
     }
     catch (Exception ex)
     {
         AppendStreamingDataMessage(ex.Message);
     }
 }
 public void Unsubscribe()
 {
     if (NotificaionTableRef != null)
     {
         m_lsClient.UnsubscribeTable(NotificaionTableRef);
         NotificaionTableRef = null;
     }
 }
Exemple #6
0
        void IStreamingListener.Start(int phase)
        {
            var text = _groupOrItemName.ToUpper();

            if (_listener != null)
            {
                _listener.MessageReceived -= ListenerMessageReceived;
                ((IStreamingListener)this).Stop();
            }

            var fieldList = _messageConverter.GetFieldList();
            var text2     = _channel.ToUpper();

            _listener = new TableListener <TDto>(_logger, _adapterSet.ToUpper(), text2, text, phase, _serializer);
            _listener.MessageReceived += ListenerMessageReceived;

            _logger.Debug(string.Format("Subscribing to group:{0}, schema {1}, dataAdapter {2}, mode {3}, snapshot {4}",
                                        text,
                                        fieldList,
                                        text2,
                                        _mode.ToUpper(),
                                        _snapshot));

            var schema          = fieldList;
            var mode            = _mode.ToUpper();
            var snapshot        = _snapshot;
            var simpleTableInfo = new SimpleTableInfo(text, mode, schema, snapshot)
            {
                DataAdapter = text2
            };

            var       gate = new ManualResetEvent(false);
            Exception ex   = null;

            new Thread(delegate()
            {
                try
                {
                    _subscribedTableKey = _lightstreamer.SubscribeTable(simpleTableInfo, _listener, false);
                    _logger.Debug(string.Format("Subscribed to table with key: {0}", _subscribedTableKey));
                }
                catch (Exception e)
                {
                    ex = e;
                }
                gate.Set();
            }).Start();

            if (ex != null)
            {
                _logger.Error(ex);
                throw ex;
            }
            if (!gate.WaitOne(Settings.DefaultTimeoutMs + 1000))
            {
                _logger.Error(string.Format("Listener taking longer than {0}ms to start: {1}.", Settings.DefaultTimeoutMs, base.GetType().Name));
            }
        }
 public void Stop()
 {
     if (tableKey != null)
     {
         this.client.UnsubscribeTable(tableKey);
     }
     tableKey = null;
     this.client.CloseConnection();
 }
Exemple #8
0
 private void UnsubscribeFromOrders()
 {
     if ((igStreamApiClient != null) && (_orderPricesSubscriptionTableKey != null) && (LoggedIn))
     {
         igStreamApiClient.UnsubscribeTableKey(_orderPricesSubscriptionTableKey);
         _orderPricesSubscriptionTableKey = null;
         UpdateOrdersMessage("Unsubscribed from OrderPrices");
     }
 }
 public void UnsubscribeFromBrowsePrices()
 {
     if ((igStreamApiClient != null) && (_browseSubscriptionTableKey != null) && (LoggedIn))
     {
         igStreamApiClient.UnsubscribeTableKey(_browseSubscriptionTableKey);
         _browseSubscriptionTableKey = null;
         AddStatusMessage("Unsubscribed from Browse Node Prices");
     }
 }
 public void Stop(SubscribedTableKey tableKey)
 {
     if (tableKey != null)
     {
         client.UnsubscribeTable(tableKey);
     }
     tableKey = null;
     client.CloseConnection();
 }
Exemple #11
0
 public void Unsubscribe()
 {
     if (_tradeSubscriptionStk != null)
     {
         _igStreamApiClient.UnsubscribeTradeSubscription(_tradeSubscriptionStk);
         _tradeSubscriptionStk = null;
         Log.Instance.WriteEntry("TradeSubscription : Unsubscribe");
     }
 }
 private void UnsubscribefromTradeSubscription()
 {
     if ((_tradeSubscriptionStk != null) && (igStreamApiClient != null))
     {
         igStreamApiClient.UnsubscribeTableKey(_tradeSubscriptionStk);
         _tradeSubscriptionStk = null;
         UpdateDebugMessage("Successfully unsubscribed from Trade Subscription");
     }
 }
Exemple #13
0
        public async Task Subscribe()
        {
            try
            {
                if (_igStreamApiClient != null)
                {
                    if (_tradeSubscriptionStk == null)
                    {
                        _tradeSubscriptionStk = _igStreamApiClient.SubscribeToPositions(this);
                        Log.Instance.WriteEntry("TradeSubscription : Subscribe");
                    }
                    if (Config.ReplayEnabled)
                    {
                        await Task.Delay(0);

                        return;
                    }
                    var response = await _igRestApiClient.getOTCOpenPositionsV2();

                    foreach (var pos in response.Response.positions)
                    {
                        var ptfPos = GetPosition(pos.market.epic);
                        if (ptfPos != null)
                        {
                            var trade = new Trade(DateTime.Parse(pos.market.updateTime), pos.market.epic,
                                                  pos.position.direction == "BUY" ? SIGNAL_CODE.BUY : SIGNAL_CODE.SELL, (int)pos.position.size.Value,
                                                  pos.position.direction == "BUY" ? pos.market.offer.Value : pos.market.bid.Value);
                            trade.Id               = pos.position.dealId;
                            trade.Reference        = "RECOVER_" + pos.position.dealId;
                            trade.ConfirmationTime = trade.TradingTime;
                            ReplayPositionUpdateInfo updateInfo = new ReplayPositionUpdateInfo(DateTime.Parse(pos.market.updateTime), pos.market.epic,
                                                                                               pos.position.dealId, trade.Reference, "OPEN", "ACCEPTED", (int)pos.position.size.Value,
                                                                                               pos.position.direction == "BUY" ? pos.market.offer.Value : pos.market.bid.Value,
                                                                                               pos.position.direction == "BUY" ? SIGNAL_CODE.BUY : SIGNAL_CODE.SELL);
                            _trades.Add(trade);
                            ptfPos.AddIncomingTrade(trade);
                            ptfPos.OnUpdate(updateInfo);
                        }
                        else
                        {
                            Log.Instance.WriteEntry("Trade subscription error: mktdata: " + pos.market.epic + ", direction: " + pos.position.direction + ", size: " + pos.position.size.Value +
                                                    ", dealid:" + pos.position.dealId, System.Diagnostics.EventLogEntryType.Error);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Instance.WriteEntry("Portfolio subscription error: " + ex.Message, System.Diagnostics.EventLogEntryType.Error);
                if (Portfolio.Instance.ShutDownFunc != null)
                {
                    Log.Instance.WriteEntry("Terminating...", System.Diagnostics.EventLogEntryType.Error);
                    Portfolio.Instance.ShutDownFunc();
                }
            }
        }
        private void UnsubscribeFromAccountDetailsSubscription()
        {
            if ((_accountBalanceStk != null) && (igStreamApiClient != null))
            {
                igStreamApiClient.UnsubscribeTableKey(_accountBalanceStk);
                _accountBalanceStk = null;

                UpdateDebugMessage("Successfully unsubscribed from Account Balance Subscription");
            }
        }
Exemple #15
0
        private void UnsubscribeFromCharts()
        {
            if ((igStreamApiClient != null) && (_chartSubscribedTableKey != null) && (LoggedIn))
            {
                igStreamApiClient.UnsubscribeTableKey(_chartSubscribedTableKey);
                _chartSubscribedTableKey = null;

                AddStatusMessage("WatchlistsViewModel : Unsubscribing from candle data from charts");
            }
        }
        public void AddSubcribe(string[] items, string[] fields)
        {
            SimpleTableInfo tableInfo = new ExtendedTableInfo(
                items, "MERGE", fields, true);

            tableInfo.DataAdapter = this.adapter_name;

            tableKey = client.SubscribeTable(tableInfo,
                                             new StocklistHandyTableListener(listener), false);
        }
Exemple #17
0
        private void UnsubscribeFromWatchlistInstruments()
        {
            if ((igStreamApiClient != null) && (_watchlistL1PricesSubscribedTableKey != null) && (LoggedIn))
            {
                igStreamApiClient.UnsubscribeTableKey(_watchlistL1PricesSubscribedTableKey);
                _watchlistL1PricesSubscribedTableKey = null;

                UpdateWatchlistsMessage("WatchlistsViewModel : Unsubscribing from L1 Prices for Watchlists");
            }
        }
Exemple #18
0
        private void UnsubscribeFromPositions()
        {
            if ((igStreamApiClient != null) && (_l1PositionPricesTableKey != null) && (LoggedIn))
            {
                igStreamApiClient.UnsubscribeTableKey(_l1PositionPricesTableKey);
                _l1PositionPricesTableKey = null;

                UpdatePositionMessage("PositionViewModel : Unsubscribing from Positions");
            }
        }
Exemple #19
0
        /// <summary>
        /// account details subscription
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="tableListener"></param>

        public void subscribeToAccountDetails(string accountId, IHandyTableListener tableListener, string[] fields)
        {
            ExtendedTableInfo extTableInfo = new ExtendedTableInfo(
                new string[] { "ACCOUNT:" + accountId },
                "MERGE",
                fields,
                true
                );
            SubscribedTableKey tableKey = lsClient.SubscribeTable(extTableInfo, tableListener, false);
        }
 public static void Stop(SubscribedTableKey tableKey)
 {
     lock (mutex)
     {
         if (client != null)
         {
             client.Stop(tableKey);
         }
         client = null;
     }
 }
Exemple #21
0
        void IStreamingListener.Start(int phase)
        {
            string groupOrItemName = _groupOrItemName.ToUpper();

            if (_listener != null)
            {
                _listener.MessageReceived -= ListenerMessageReceived;
                ((IStreamingListener)this).Stop();
            }

            string schema  = _messageConverter.GetFieldList();
            string channel = _channel.ToUpper();

            _listener = new TableListener <TDto>(_adapterSet.ToUpper(), channel, groupOrItemName, phase, _serializer);
            _listener.MessageReceived += ListenerMessageReceived;


            Logger.Debug(string.Format("Subscribing to group:{0}, schema {1}, dataAdapter {2}, mode {3}, snapshot {4}", groupOrItemName, schema, channel, _mode.ToUpper(), _snapshot));

            var simpleTableInfo = new SimpleTableInfo(
                groupOrItemName,
                schema: schema,
                mode: _mode.ToUpper(), snap: _snapshot)
            {
                DataAdapter = channel
            };
            var       gate = new ManualResetEvent(false);
            Exception ex   = null;

            new Thread(() =>
            {
                try
                {
                    _subscribedTableKey = _lsClient.SubscribeTable(simpleTableInfo, _listener, false);
                    Logger.Debug(string.Format("Subscribed to table with key: {0}", _subscribedTableKey));
                }
                catch (Exception exInner)
                {
                    ex = exInner;
                }
                gate.Set();
            }).Start();
            if (ex != null)
            {
                Logger.Error(ex);
                throw ex;
            }

            if (!gate.WaitOne(LightstreamerDefaults.DEFAULT_TIMEOUT_MS + 1000))
            {
                Logger.Error(string.Format("Listener taking longer than {0}ms to start: {1}.",
                                           LightstreamerDefaults.DEFAULT_TIMEOUT_MS, GetType().Name));
            }
        }
 public void UnsubscribeTableKey(SubscribedTableKey stk)
 {
     try
     {
         if (lsClient != null)
         {
             lsClient.UnsubscribeTable(stk);
         }
     }
     catch (Exception)
     {
     }
 }
 public void SubscribeToBrowsePrices(string[] epics)
 {
     try
     {
         // Subscribe to L1 price updates for the instruments contained in this browse node...
         _browseSubscriptionTableKey = igStreamApiClient.SubscribeToMarketDetails(epics, _l1BrowsePricesSubscription);
         AddStatusMessage("Subscribed Successfully to instruments contained within this browse node.");
     }
     catch (Exception ex)
     {
         AddStatusMessage("Could not subscribe to browse instruments : " + ex.Message);
     }
 }
 public static SubscribedTableKey Startup(ILightstreamerListener listener, string[] items)
 {
     lock (mutex)
     {
         if (client == null)
         {
             Debug.Log("Loading Lightstreamer Singleton");
             client = new LightstreamerClient();
             client.Start(pushServerHost);
         }
         SubscribedTableKey tableKey = client.AppendListener(listener, items, fields);
         return(tableKey);
     }
 }
 public void SubscribeToTradeSubscription()
 {
     try
     {
         if (CurrentAccountId != null)
         {
             _tradeSubscriptionStk = igStreamApiClient.SubscribeToTradeSubscription(CurrentAccountId, _tradeSubscription);
             UpdateDebugMessage("Lightstreamer - Subscribing to CONFIRMS, Working order updates and open position updates");
         }
     }
     catch (Exception ex)
     {
         UpdateDebugMessage("ApplicationViewModel - SubscribeToTradeSubscription" + ex.Message);
     }
 }
 public void SubscribeToAccountDetails()
 {
     try
     {
         if (CurrentAccountId != null)
         {
             _accountBalanceStk = igStreamApiClient.SubscribeToAccountDetails(CurrentAccountId, _accountBalanceSubscription);
             UpdateDebugMessage("Lightstreamer - Subscribing to Account Details");
         }
     }
     catch (Exception ex)
     {
         UpdateDebugMessage("ApplicationViewModel - SubscribeToAccountDetails" + ex.Message);
     }
 }
Exemple #27
0
 public void SubscribeToL1PositionPrices(string[] positionSubs)
 {
     try
     {
         if (igStreamApiClient != null)
         {
             _l1PositionPricesTableKey = igStreamApiClient.subscribeToMarketDetails(positionSubs, _l1PricesSubscription);
             UpdatePositionMessage("Successfully subscribed to positions");
         }
     }
     catch (Exception ex)
     {
         UpdatePositionMessage("Problem subscribing to positions: " + ex.Message);
     }
 }
Exemple #28
0
 // <Summary>
 // Lightstreamer Subscribe to L1 Prices...
 // </Summary>
 private void SubscribeL1WatchlistPrices(string[] watchlistItems)
 {
     try
     {
         if (igStreamApiClient != null)
         {
             _watchlistL1PricesSubscribedTableKey = igStreamApiClient.subscribeToMarketDetails(watchlistItems, _l1PricesSubscription);
             UpdateWatchlistsMessage("Successfully subscribed to Watchlist : " + Watchlists[WatchlistIndex].WatchlistName);
         }
     }
     catch (Exception ex)
     {
         UpdateWatchlistsMessage("Exception when trying to subscribe to Watchlist l1 prices: " + ex.Message);
     }
 }
Exemple #29
0
        public PositionsViewModel()
        {
            InitialiseViewModel();

            _positions = new ObservableCollection <IgPublicApiData.PositionModel>();

            // Initialise LS subscriptions
            _l1PricesSubscription = new L1PricesSubscription(this);

            // initialise the LS SubscriptionTableKeys
            _l1PositionPricesTableKey = new SubscribedTableKey();

            // Important to initialise to null.
            _l1PositionPricesTableKey = null;
        }
Exemple #30
0
        public WatchlistsViewModel()
        {
            _watchlists       = new ObservableCollection <IgPublicApiData.WatchlistModel>();
            _watchlistMarkets = new ObservableCollection <IgPublicApiData.WatchlistMarketModel>();

            // Initialise to first index in datagrid.
            WatchlistIndex       = 0;
            WatchlistMarketIndex = 0;

            WireCommands();

            _l1PricesSubscription = new L1PricesSubscription(this);

            _watchlistL1PricesSubscribedTableKey = new SubscribedTableKey();
            _watchlistL1PricesSubscribedTableKey = null;
        }
Exemple #31
0
        /// <summary>
        /// Opens a connection, performs a table subscription and unsubscription
        /// and closes the connection after some time.
        /// </summary>
        /// <param name="args">Should specify the host name of the Server, the port number
        /// and optionally the "extended", "multiple" and "command" flags.
        /// </param>
        /// <throws>Exception Thrown in case of any error.</throws>
        public static void Main(string[] args) {

            LSClient.SetLoggerProvider(new Log4NetLoggerProviderWrapper());

            string pushServerHost = args[0];
            int pushServerPort = Int32.Parse(args[1]);

            ArrayList opts = new ArrayList();
            for (int i = 2; i < args.Length; i++) {
                opts.Add(args[i]);
            }
            bool extended = opts.Contains("extended");
            bool multiple = opts.Contains("multiple");
            bool command = opts.Contains("command");

            Thread.Sleep(2000);

            ConnectionInfo connInfo= new ConnectionInfo();
            connInfo.PushServerUrl= "http://" + pushServerHost + ":" + pushServerPort;
            connInfo.Adapter= "DEMO";

            LSClient myClient = new LSClient();
            myClient.OpenConnection(connInfo, new TestConnectionListener());
        
            Thread.Sleep(5000);

            ArrayList refs = new ArrayList();
            SubscribedTableKey[] tableRefs;

            if (!command) {
                if (extended) {
                    ExtendedTableInfo tableInfo= new ExtendedTableInfo(
                        new string[] { "item1", "item2", "item3" },
                        "MERGE",
                        new string[] { "last_price", "time", "pct_change" },
                        true
                        );

                    tableInfo.DataAdapter = "QUOTE_ADAPTER";
                
                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestTableListenerForExtended(),
                        false
                        );
                
                    tableRefs = new SubscribedTableKey[] { tableRef };

                } else if (multiple) {
                    ExtendedTableInfo tableInfo= new ExtendedTableInfo(
                        new string[] { "item1", "item2", "item3" },
                        "MERGE",
                        new string[] { "last_price", "time", "pct_change" },
                        true
                        );

                    tableInfo.DataAdapter = "QUOTE_ADAPTER";

                    tableRefs = myClient.SubscribeItems(
                        tableInfo,
                        new TestTableListenerForMultiple()
                        );

                } else {
                    // Group and Schema names have to be manageable by
                    // the LiteralBasedProvider used for the StockListDemo
                    string groupName = "item1 item2 item3";
                    string schemaName = "last_price time pct_change";

                    SimpleTableInfo tableInfo= new SimpleTableInfo(
                        groupName, 
                        "MERGE", 
                        schemaName, 
                        true
                        );

                    tableInfo.DataAdapter = "QUOTE_ADAPTER";

                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestTableListenerForSimple(),
                        false
                        );

                    tableRefs = new SubscribedTableKey[] { tableRef };
                }
            } else {
                if (extended) {
                    ExtendedTableInfo tableInfo = new ExtendedTableInfo(
                        new String[] { "portfolio1" },
                        "COMMAND",
                        new String[] { "key", "command", "qty" },
                        true
                        );

                    tableInfo.DataAdapter = "PORTFOLIO_ADAPTER";

                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestPortfolioListenerForExtended(),
                        true
                        );

                    tableRefs = new SubscribedTableKey[] { tableRef };

                } else {
                    // Group and Schema names have to be manageable by
                    // the LiteralBasedProvider used for the StockListDemo
                    String groupName = "portfolio1";
                    String schemaName = "key command qty";

                    SimpleTableInfo tableInfo = new SimpleTableInfo(
                        groupName,
                        "COMMAND",
                        schemaName,
                        true
                        );

                    tableInfo.DataAdapter = "PORTFOLIO_ADAPTER";

                    SubscribedTableKey tableRef = myClient.SubscribeTable(
                        tableInfo,
                        new TestPortfolioListenerForSimple(),
                        true
                        );

                    tableRefs = new SubscribedTableKey[] { tableRef };
                }
            }

            for (int j = 0; j < tableRefs.Length; j++) {
                refs.Add(tableRefs[j]);
            }

            Thread.Sleep(20000);

            SubscribedTableKey[] allTableRefs = new SubscribedTableKey[refs.Count];
            for (int i= 0; i < refs.Count; i++) allTableRefs[i]= (SubscribedTableKey) refs[i];
            myClient.UnsubscribeTables(allTableRefs);

            Thread.Sleep(5000);
        
            myClient.CloseConnection();
        
            Thread.Sleep(2000);
            Environment.Exit(0);
        }