コード例 #1
0
        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;
            }
        }
コード例 #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 (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;
                    }
                }
            }
        }