Ejemplo n.º 1
0
 public void onChanged(string sRowID, O2GRow rowData)
 {
     if (rowData.TableType == O2GTableType.Accounts)
     {
         O2GAccountTableRow account = (O2GAccountTableRow)rowData;
         Console.WriteLine("The balance has been changed. AccountID={0}, Balance = {1}, Equity: {2}", account.AccountID, account.Balance, account.Equity);
     }
     else if (rowData.TableType == O2GTableType.Trades)
     {
         if (mOrderMonitor != null)
         {
             mOrderMonitor.OnTradeUpdated((O2GTradeRow)rowData);
             if (mOrderMonitor.IsOrderCompleted)
             {
                 PrintResult();
                 mResponseListener.StopWaiting();
             }
         }
     }
 }
Ejemplo n.º 2
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;
                    }
                }
            }
        }