Exemple #1
0
 public void OnMessageAdded(O2GMessageRow message)
 {
     for (int i = 0; i < mMonitors.Count; i++)
     {
         mMonitors[i].OnMessageAdded(message);
     }
 }
        public void onAdded(string sRowID, O2GRow rowData)
        {
            O2GTableType type = rowData.TableType;

            switch (type)
            {
            case O2GTableType.Orders:
                O2GOrderRow orderRow = (O2GOrderRow)rowData;
                if (mBatchOrderMonitor != null && mRequestIDs.Contains(orderRow.RequestID))
                {
                    Console.WriteLine("The order has been added. Order ID: {0}, Rate: {1}, Time In Force: {2}",
                                      orderRow.OrderID,
                                      orderRow.Rate,
                                      orderRow.TimeInForce);
                    mBatchOrderMonitor.OnOrderAdded(orderRow);
                }
                break;

            case O2GTableType.Trades:
                O2GTradeRow tradeRow = (O2GTradeRow)rowData;
                if (mBatchOrderMonitor != null)
                {
                    mBatchOrderMonitor.OnTradeAdded(tradeRow);
                    if (mBatchOrderMonitor.IsBatchExecuted())
                    {
                        PrintResult();
                        mResponseListener.StopWaiting();
                    }
                }
                break;

            case O2GTableType.ClosedTrades:
                O2GClosedTradeRow closedTradeRow = (O2GClosedTradeRow)rowData;
                if (mBatchOrderMonitor != null)
                {
                    mBatchOrderMonitor.OnClosedTradeAdded(closedTradeRow);
                    if (mBatchOrderMonitor.IsBatchExecuted())
                    {
                        PrintResult();
                        mResponseListener.StopWaiting();
                    }
                }
                break;

            case O2GTableType.Messages:
                O2GMessageRow messageRow = (O2GMessageRow)rowData;
                if (mBatchOrderMonitor != null)
                {
                    mBatchOrderMonitor.OnMessageAdded(messageRow);
                    if (mBatchOrderMonitor.IsBatchExecuted())
                    {
                        PrintResult();
                        mResponseListener.StopWaiting();
                    }
                }
                break;
            }
        }
 /// <summary>
 /// Process reject message as result of order execution
 /// </summary>
 public void OnMessageAdded(O2GMessageRow messageRow)
 {
     if (mState == OrderState.OrderRejected ||
         mState == OrderState.OrderExecuting)
     {
         bool IsRejectMessage = CheckAndStoreMessage(messageRow);
         if (mState == OrderState.OrderRejected && IsRejectMessage)
         {
             SetResult(true);
         }
     }
 }
        private bool CheckAndStoreMessage(O2GMessageRow message)
        {
            string sFeature = message.Feature;

            if (MessageFeature.MarketCondition.Equals(sFeature))
            {
                string sText   = message.Text;
                int    findPos = sText.IndexOf(mOrder.OrderID);
                if (findPos > -1)
                {
                    mRejectMessage = sText;
                    return(true);
                }
            }
            return(false);
        }
Exemple #5
0
        public void onAdded(string sRowID, O2GRow rowData)
        {
            O2GTableType type = rowData.TableType;

            switch (type)
            {
            case O2GTableType.Orders:
                O2GOrderRow orderRow = (O2GOrderRow)rowData;
                if (mRequestID.Equals(orderRow.RequestID))
                {
                    mOrderID = orderRow.OrderID;
                    PrintOrder("New order is added", orderRow);
                }
                break;

            case O2GTableType.Trades:
                O2GTradeRow tradeRow = (O2GTradeRow)rowData;
                Console.WriteLine("Position is opened: TradeID='{0}', TradeIDOrigin='{1}'",
                                  tradeRow.TradeID, tradeRow.TradeIDOrigin);
                break;

            case O2GTableType.ClosedTrades:
                O2GClosedTradeRow closedTradeRow = (O2GClosedTradeRow)rowData;
                Console.WriteLine("Position is closed: TradeID='{0}'",
                                  closedTradeRow.TradeID);
                break;

            case O2GTableType.Messages:
                O2GMessageRow messageRow = (O2GMessageRow)rowData;
                string        text       = messageRow.Text;
                int           findPos    = text.IndexOf(mOrderID);
                if (findPos >= 0)
                {
                    Console.WriteLine("Feature='{0}', Message='{1}'",
                                      messageRow.Feature, text);
                }
                break;
            }
        }
 private bool CheckAndStoreMessage(O2GMessageRow message)
 {
     string sFeature = message.Feature;
     if (MessageFeature.MarketCondition.Equals(sFeature))
     {
         string sText = message.Text;
         int findPos = sText.IndexOf(mOrder.OrderID);
         if (findPos > -1)
         {
             mRejectMessage = sText;
             return true;
         }
     }
     return false;
 }
 /// <summary>
 /// Process reject message as result of order execution
 /// </summary>
 public void OnMessageAdded(O2GMessageRow messageRow)
 {
     if (mState == OrderState.OrderRejected ||
         mState == OrderState.OrderExecuting)
     {
         bool IsRejectMessage = CheckAndStoreMessage(messageRow);
         if (mState == OrderState.OrderRejected && IsRejectMessage)
             SetResult(true);
     }
 }
        public void onTablesUpdates(O2GResponse data)
        {
            O2GResponseReaderFactory factory = mSession.getResponseReaderFactory();

            if (factory != null)
            {
                O2GTablesUpdatesReader reader = factory.createTablesUpdatesReader(data);
                for (int ii = 0; ii < reader.Count; ii++)
                {
                    switch (reader.getUpdateTable(ii))
                    {
                    case O2GTableType.Accounts:
                        O2GAccountRow account = reader.getAccountRow(ii);
                        //Show balance updates
                        Console.WriteLine("Balance: {0}", account.Balance);
                        break;

                    case O2GTableType.Orders:
                        O2GOrderRow order = reader.getOrderRow(ii);
                        switch (reader.getUpdateType(ii))
                        {
                        case O2GTableUpdateType.Insert:
                            if (mBatchOrderMonitor != null)
                            {
                                Console.WriteLine("The order has been added. Order ID: {0}, Rate: {1}, Time In Force: {2}",
                                                  order.OrderID,
                                                  order.Rate,
                                                  order.TimeInForce);
                                mBatchOrderMonitor.OnOrderAdded(order);
                            }
                            break;

                        case O2GTableUpdateType.Delete:
                            if (mBatchOrderMonitor != null)
                            {
                                Console.WriteLine("The order has been deleted. Order ID: {0}", order.OrderID);
                                mBatchOrderMonitor.OnOrderDeleted(order);
                                if (mBatchOrderMonitor.IsBatchExecuted())
                                {
                                    PrintResult();
                                    mSyncResponseEvent.Set();
                                }
                            }
                            break;
                        }
                        break;

                    case O2GTableType.Trades:
                        O2GTradeRow trade = reader.getTradeRow(ii);
                        if (reader.getUpdateType(ii) == O2GTableUpdateType.Insert)
                        {
                            if (mBatchOrderMonitor != null)
                            {
                                mBatchOrderMonitor.OnTradeAdded(trade);
                                if (mBatchOrderMonitor.IsBatchExecuted())
                                {
                                    PrintResult();
                                    mSyncResponseEvent.Set();
                                }
                            }
                        }
                        break;

                    case O2GTableType.ClosedTrades:
                        O2GClosedTradeRow closedTrade = reader.getClosedTradeRow(ii);
                        if (reader.getUpdateType(ii) == O2GTableUpdateType.Insert)
                        {
                            if (mBatchOrderMonitor != null)
                            {
                                mBatchOrderMonitor.OnClosedTradeAdded(closedTrade);
                                if (mBatchOrderMonitor.IsBatchExecuted())
                                {
                                    PrintResult();
                                    mSyncResponseEvent.Set();
                                }
                            }
                        }
                        break;

                    case O2GTableType.Messages:
                        O2GMessageRow message = reader.getMessageRow(ii);
                        if (reader.getUpdateType(ii) == O2GTableUpdateType.Insert)
                        {
                            if (mBatchOrderMonitor != null)
                            {
                                mBatchOrderMonitor.OnMessageAdded(message);
                                if (mBatchOrderMonitor.IsBatchExecuted())
                                {
                                    PrintResult();
                                    mSyncResponseEvent.Set();
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }
Exemple #9
0
        public void onAdded(string sRowID, O2GRow rowData)
        {
            O2GTableType type = rowData.TableType;

            switch (type)
            {
            case O2GTableType.Orders:
                O2GOrderRow orderRow = (O2GOrderRow)rowData;
                if (mRequestID.Equals(orderRow.RequestID))
                {
                    if ((OrderMonitorNetting.IsClosingOrder(orderRow) || OrderMonitorNetting.IsOpeningOrder(orderRow)) &&
                        mOrderMonitor == null)
                    {
                        Console.WriteLine("The order has been added. Order ID: {0}, Rate: {1}, Time In Force: {2}",
                                          orderRow.OrderID,
                                          orderRow.Rate,
                                          orderRow.TimeInForce);
                        O2GTradeRow trade    = null;
                        string      sTradeID = orderRow.TradeID;
                        if (mTradesTable != null)
                        {
                            for (int j = 0; j < mTradesTable.Count; j++)
                            {
                                if (sTradeID.Equals(mTradesTable.getRow(j).TradeID))
                                {
                                    trade = mTradesTable.getRow(j);
                                    break;
                                }
                            }
                        }
                        if (trade == null)
                        {
                            mOrderMonitor = new OrderMonitorNetting(orderRow);
                        }
                        else
                        {
                            mOrderMonitor = new OrderMonitorNetting(orderRow, trade.Amount);
                        }
                    }
                }
                break;

            case O2GTableType.Trades:
                O2GTradeRow tradeRow = (O2GTradeRow)rowData;
                if (mOrderMonitor != null)
                {
                    mOrderMonitor.OnTradeAdded(tradeRow);
                    if (mOrderMonitor.IsOrderCompleted)
                    {
                        PrintResult();
                        mResponseListener.StopWaiting();
                    }
                }
                break;

            case O2GTableType.ClosedTrades:
                O2GClosedTradeRow closedTradeRow = (O2GClosedTradeRow)rowData;
                if (mOrderMonitor != null)
                {
                    mOrderMonitor.OnClosedTradeAdded(closedTradeRow);
                    if (mOrderMonitor.IsOrderCompleted)
                    {
                        PrintResult();
                        mResponseListener.StopWaiting();
                    }
                }
                break;

            case O2GTableType.Messages:
                O2GMessageRow messageRow = (O2GMessageRow)rowData;
                if (mOrderMonitor != null)
                {
                    mOrderMonitor.OnMessageAdded(messageRow);
                    if (mOrderMonitor.IsOrderCompleted)
                    {
                        PrintResult();
                        mResponseListener.StopWaiting();
                    }
                }
                break;
            }
        }
        public void onTablesUpdates(O2GResponse response)
        {
            O2GResponseReaderFactory factory = mSession.getResponseReaderFactory();

            if (factory != null)
            {
                O2GTablesUpdatesReader reader = factory.createTablesUpdatesReader(response);
                for (int ii = 0; ii < reader.Count; ii++)
                {
                    switch (reader.getUpdateTable(ii))
                    {
                    case O2GTableType.Accounts:
                        O2GAccountRow account = reader.getAccountRow(ii);
                        // Show balance updates
                        Console.WriteLine("Balance: {0}", account.Balance);
                        break;

                    case O2GTableType.Orders:
                        O2GOrderRow order = reader.getOrderRow(ii);
                        switch (reader.getUpdateType(ii))
                        {
                        case O2GTableUpdateType.Insert:
                            if (mRequestID.Equals(order.RequestID))
                            {
                                mOrderID = order.OrderID;
                                printOrder("New order is added", order);
                            }
                            break;

                        case O2GTableUpdateType.Update:
                            printOrder("An order is changed", order);
                            break;

                        case O2GTableUpdateType.Delete:
                            if (mRequestID.Equals(order.RequestID))
                            {
                                string sStatus = order.Status;
                                if (sStatus.Equals("R"))
                                {
                                    printOrder("An order has been rejected", order);
                                }
                                else
                                {
                                    printOrder("An order is going to be removed", order);
                                }
                                mSyncResponseEvent.Set();
                            }
                            break;
                        }
                        break;

                    case O2GTableType.Trades:
                        O2GTradeRow trade = reader.getTradeRow(ii);
                        if (reader.getUpdateType(ii) == O2GTableUpdateType.Insert)
                        {
                            Console.WriteLine("Position is opened: TradeID='{0}', TradeIDOrigin='{1}'",
                                              trade.TradeID, trade.TradeIDOrigin);
                        }
                        break;

                    case O2GTableType.ClosedTrades:
                        O2GClosedTradeRow closedTrade = reader.getClosedTradeRow(ii);
                        if (reader.getUpdateType(ii) == O2GTableUpdateType.Insert)
                        {
                            Console.WriteLine("Position is closed: TradeID='{0}'",
                                              closedTrade.TradeID);
                        }
                        break;

                    case O2GTableType.Messages:
                        O2GMessageRow message = reader.getMessageRow(ii);
                        if (reader.getUpdateType(ii) == O2GTableUpdateType.Insert)
                        {
                            string text    = message.Text;
                            int    findPos = text.IndexOf(mOrderID);
                            if (findPos >= 0)
                            {
                                Console.WriteLine("Feature='{0}', Message='{1}'",
                                                  message.Feature, text);
                            }
                        }
                        break;
                    }
                }
            }
        }
Exemple #11
0
        public void onTablesUpdates(O2GResponse data)
        {
            O2GResponseReaderFactory factory = mSession.getResponseReaderFactory();

            if (factory != null)
            {
                O2GTablesUpdatesReader reader = factory.createTablesUpdatesReader(data);
                for (int ii = 0; ii < reader.Count; ii++)
                {
                    switch (reader.getUpdateTable(ii))
                    {
                    case O2GTableType.Accounts:
                        O2GAccountRow account = reader.getAccountRow(ii);
                        //Show balance updates
                        Console.WriteLine("Balance: {0}", account.Balance);
                        break;

                    case O2GTableType.Orders:
                        O2GOrderRow order = reader.getOrderRow(ii);
                        switch (reader.getUpdateType(ii))
                        {
                        case O2GTableUpdateType.Insert:
                            if ((OrderMonitorNetting.IsClosingOrder(order) || OrderMonitorNetting.IsOpeningOrder(order)) &&
                                mOrderMonitor == null)
                            {
                                Console.WriteLine("The order has been added. Order ID: {0}, Rate: {1}, Time In Force: {2}",
                                                  order.OrderID,
                                                  order.Rate,
                                                  order.TimeInForce);
                                O2GTradeRow tradeRow = null;
                                string      sTradeID = order.TradeID;
                                if (mTradesTable != null)
                                {
                                    for (int j = 0; j < mTradesTable.Count; j++)
                                    {
                                        if (sTradeID.Equals(mTradesTable.getRow(j).TradeID))
                                        {
                                            tradeRow = mTradesTable.getRow(j);
                                            break;
                                        }
                                    }
                                }
                                if (tradeRow == null)
                                {
                                    mOrderMonitor = new OrderMonitorNetting(order);
                                }
                                else
                                {
                                    mOrderMonitor = new OrderMonitorNetting(order, tradeRow.Amount);
                                }
                            }
                            break;

                        case O2GTableUpdateType.Delete:
                            if (mOrderMonitor != null)
                            {
                                Console.WriteLine("The order has been deleted. Order ID: {0}", order.OrderID);
                                mOrderMonitor.OnOrderDeleted(order);
                                if (mOrderMonitor.IsOrderCompleted)
                                {
                                    PrintResult();
                                    mSyncResponseEvent.Set();
                                }
                            }
                            break;
                        }
                        break;

                    case O2GTableType.Trades:
                        O2GTradeRow trade = reader.getTradeRow(ii);
                        switch (reader.getUpdateType(ii))
                        {
                        case O2GTableUpdateType.Insert:
                            if (mOrderMonitor != null)
                            {
                                mOrderMonitor.OnTradeAdded(trade);
                                if (mOrderMonitor.IsOrderCompleted)
                                {
                                    PrintResult();
                                    mSyncResponseEvent.Set();
                                }
                            }
                            break;

                        case O2GTableUpdateType.Update:
                            if (mOrderMonitor != null)
                            {
                                mOrderMonitor.OnTradeUpdated(trade);
                                if (mOrderMonitor.IsOrderCompleted)
                                {
                                    PrintResult();
                                    mSyncResponseEvent.Set();
                                }
                            }
                            break;
                        }
                        break;

                    case O2GTableType.ClosedTrades:
                        O2GClosedTradeRow closedTrade = reader.getClosedTradeRow(ii);
                        if (reader.getUpdateType(ii) == O2GTableUpdateType.Insert)
                        {
                            if (mOrderMonitor != null)
                            {
                                mOrderMonitor.OnClosedTradeAdded(closedTrade);
                                if (mOrderMonitor.IsOrderCompleted)
                                {
                                    PrintResult();
                                    mSyncResponseEvent.Set();
                                }
                            }
                        }
                        break;

                    case O2GTableType.Messages:
                        O2GMessageRow message = reader.getMessageRow(ii);
                        if (reader.getUpdateType(ii) == O2GTableUpdateType.Insert)
                        {
                            if (mOrderMonitor != null)
                            {
                                mOrderMonitor.OnMessageAdded(message);
                                if (mOrderMonitor.IsOrderCompleted)
                                {
                                    PrintResult();
                                    mSyncResponseEvent.Set();
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }
 public void OnMessageAdded(O2GMessageRow message)
 {
     for (int i = 0; i < mMonitors.Count; i++)
         mMonitors[i].OnMessageAdded(message);
 }