Ejemplo n.º 1
0
        public void onChanged(string rowID, O2GRow rowData)
        {
            O2GTableType type = rowData.TableType;

            switch (type)
            {
            case O2GTableType.Offers:
                O2GOfferTableRow offers = (O2GOfferTableRow)(rowData);
                break;

            case O2GTableType.Accounts:
                O2GAccountTableRow account = (O2GAccountTableRow)(rowData);
                break;

            case O2GTableType.Summary:
                O2GSummaryTableRow row = (O2GSummaryTableRow)(rowData);
                break;

            case O2GTableType.ClosedTrades:
                Console.WriteLine("CLOSED TRADES TRIGGERED FROM CHANGED TABLELISTENER!");
                O2GClosedTradeTableRow closed = (O2GClosedTradeTableRow)(rowData);

                break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Find valid account
        /// </summary>
        /// <param name="tableManager"></param>
        /// <returns>account</returns>
        private static O2GAccountTableRow GetAccount(O2GTableManager tableManager, string sAccountID)
        {
            bool bHasAccount                 = false;
            O2GAccountTableRow account       = null;
            O2GAccountsTable   accountsTable = (O2GAccountsTable)tableManager.getTable(O2GTableType.Accounts);

            for (int i = 0; i < accountsTable.Count; i++)
            {
                account = accountsTable.getRow(i);
                string sAccountKind = account.AccountKind;
                if (sAccountKind.Equals("32") || sAccountKind.Equals("36"))
                {
                    if (account.MarginCallFlag.Equals("N"))
                    {
                        if (string.IsNullOrEmpty(sAccountID) || sAccountID.Equals(account.AccountID))
                        {
                            bHasAccount = true;
                            break;
                        }
                    }
                }
            }
            if (!bHasAccount)
            {
                return(null);
            }
            else
            {
                return(account);
            }
        }
 public void onChanged(string sRowID, O2GRow rowData)
 {
     if (rowData.TableType == O2GTableType.Accounts)
     {
         O2GAccountTableRow account = (O2GAccountTableRow)rowData;
         Console.WriteLine("Balance: {0}, Equity: {1}", account.Balance, account.Equity);
     }
 }
Ejemplo n.º 4
0
 public void onChanged(string sRowID, O2GRow rowData)
 {
     if (rowData.TableType == O2GTableType.Accounts)
     {
         O2GAccountTableRow account = (O2GAccountTableRow)rowData;
         Console.WriteLine("Balance: {0}, Equity: {1}", account.Balance, account.Equity);
     }
     if (rowData.TableType == O2GTableType.Orders)
     {
         O2GOrderRow orderRow = (O2GOrderRow)rowData;
         PrintOrder("An order is changed", orderRow);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Print accounts and get the first account
        /// </summary>
        /// <param name="session"></param>
        /// <returns></returns>
        private static O2GAccountRow GetAccount(O2GTableManager tableManager)
        {
            O2GAccountsTable   accountsTable    = (O2GAccountsTable)tableManager.getTable(O2GTableType.Accounts);
            O2GTableIterator   accountsIterator = new O2GTableIterator();
            O2GAccountTableRow accountRow       = null;

            accountsTable.getNextRow(accountsIterator, out accountRow);
            while (accountRow != null)
            {
                Console.WriteLine("AccountID: {0}, Balance: {1}", accountRow.AccountID, accountRow.Balance);
                accountsTable.getNextRow(accountsIterator, out accountRow);
            }
            return(accountsTable.getRow(0));
        }
Ejemplo n.º 6
0
        // Account table changed event
        private void accountsTable_RowChanged(object sender, RowEventArgs e)
        {
            // O2GAccountTableRow designator
            O2GAccountTableRow accountTableRow = (O2GAccountTableRow)e.RowData;

            // If the account table row dows not equal null
            if (accountTableRow != null)
            {
                // Fill in any information changed from account table RowEventArg
                try
                {
                    // Day P/L
                    dayPL = accountTableRow.DayPL;

                    // Unrealized P/L
                    unrealPL = accountTableRow.GrossPL;
                    this.Invoke(new MethodInvoker(delegate { unrealBox.Text = "$" + Convert.ToString(unrealPL); }));
                    // Account Value
                    accountValue = accountTableRow.Balance;
                    this.Invoke(new MethodInvoker(delegate { accountValueBox.Text = "$" + Convert.ToString(accountValue); }));
                    // Available Funds
                    acctEq = accountTableRow.UsableMargin;
                    this.Invoke(new MethodInvoker(delegate { accountLevBox.Text = "$" + Convert.ToString(acctEq); }));
                    // Allocated Funds
                    acctAllocated = accountTableRow.UsedMargin;
                    this.Invoke(new MethodInvoker(delegate { allocatedFundsBox.Text = "$" + Convert.ToString(acctAllocated); }));
                    // Account type (to determine hedging privilages)

                    // Margin Level %
                    if (acctAllocated > 0)
                    {
                        marginLev = (acctEq / acctAllocated) * 100;
                        string marginLevString = Convert.ToString(marginLev);
                        int    index;
                        if (marginLevString.Contains("."))
                        {
                            index           = marginLevString.IndexOf(".") + 2;
                            marginLevString = marginLevString.Substring(0, index);
                        }
                        this.Invoke(new MethodInvoker(delegate { marginLevBox.Text = marginLevString; }));
                        this.Invoke(new MethodInvoker(delegate { marginLevBoxTop.Text = marginLevString + "%"; }));
                    }
                }
                catch (Exception accountError)
                {
                    Console.WriteLine(accountError);
                }
            }
        }
Ejemplo n.º 7
0
        public void onAdded(string rowID, O2GRow rowData)
        {
            O2GTableType type = rowData.TableType;

            switch (type)
            {
            case O2GTableType.Offers:
                O2GOfferTableRow offers = (O2GOfferTableRow)(rowData);
                break;

            case O2GTableType.Accounts:
                O2GAccountTableRow account = (O2GAccountTableRow)(rowData);
                break;

            case O2GTableType.Trades:
                break;
            }
        }
Ejemplo n.º 8
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.º 9
0
        // Account table changed event
        private void accountsTable_RowChanged(object sender, RowEventArgs e)
        {
            // O2GAccountTableRow designator
            O2GAccountTableRow accountTableRow = (O2GAccountTableRow)e.RowData;

            // If the account table row dows not equal null
            if (accountTableRow != null)
            {
                // Fill in any information changed from account table RowEventArg
                try
                {
                    // Day P/L
                    dayPL = accountTableRow.DayPL;
                    this.Invoke(new MethodInvoker(delegate { netPL.Text = "$" + Convert.ToString(dayPL); }));
                    // Unrealized P/L
                    unrealPL = accountTableRow.GrossPL;
                    this.Invoke(new MethodInvoker(delegate { unrealBox.Text = "$" + Convert.ToString(unrealPL); }));
                    // Account Value
                    accountValue = accountTableRow.Balance;
                    this.Invoke(new MethodInvoker(delegate { accountValueBox.Text = "$" + Convert.ToString(accountValue); }));
                    // Available Funds
                    availLev = accountTableRow.UsableMargin;
                    this.Invoke(new MethodInvoker(delegate { accountLevBox.Text = "$" + Convert.ToString(availLev); }));
                    // Allocated Funds
                    acctAllocated = accountTableRow.UsedMargin;
                    this.Invoke(new MethodInvoker(delegate { allocatedFundsBox.Text = "$" + Convert.ToString(acctAllocated); }));
                    if (sAccountID == null)
                    {
                        sAccountID = accountTableRow.AccountID;
                        Console.WriteLine(sAccountID);
                    }
                }
                catch (Exception accountError)
                {
                    Console.WriteLine(accountError);
                }
            }
        }
Ejemplo n.º 10
0
        public void onChanged(string rowID, O2GRow rowData)
        {
            O2GTableType type = rowData.TableType;

            switch (type)
            {
            case O2GTableType.Offers:
                O2GOfferTableRow offers = (O2GOfferTableRow)(rowData);
                break;

            case O2GTableType.Accounts:
                O2GAccountTableRow account = (O2GAccountTableRow)(rowData);
                break;

            case O2GTableType.Trades:
                O2GTradeTableRow trade = (O2GTradeTableRow)(rowData);
                break;

            case O2GTableType.Summary:
                O2GSummaryTableRow row = (O2GSummaryTableRow)(rowData);
                break;
            }
        }
Ejemplo n.º 11
0
        public Accounts(MainForm CurrentForm, O2GTableManager mTblMgr)
        {
            CreateTable();

            CurrentForm.PopulateTable(AccountsTable);


            while (mTblMgr.getStatus() != O2GTableManagerStatus.TablesLoaded && mTblMgr.getStatus() != O2GTableManagerStatus.TablesLoadFailed)
            {
                Thread.Sleep(50);
            }
            O2GAccountsTable   table    = (O2GAccountsTable)mTblMgr.getTable(O2GTableType.Accounts);
            AccountsListener   listener = new AccountsListener();
            O2GAccountTableRow row      = null;

            for (int i = 0; i < table.Count; i++)
            {
                DataRow CurrentRow = AccountsTable.NewRow();
                AccountsTable.Rows.Add(CurrentRow);
            }

            CurrentForm.GetTableData(table, listener, row, mTblMgr);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Print estimates trading commissions
        /// </summary>
        private static void printEstimatedTradingCommissions(O2GSession session, O2GOfferTableRow offer, O2GAccountTableRow account, int iAmount, string sBuySell)
        {
            //wait until commissions related information will be loaded
            O2GCommissionsProvider commissionProvider = session.getCommissionsProvider();

            while (commissionProvider.getStatus() == O2GCommissionStatus.CommissionStatusLoading)
            {
                System.Threading.Thread.Sleep(1000);
            }

            if (commissionProvider.getStatus() != O2GCommissionStatus.CommissionStatusReady)
            {
                throw new Exception("Could not calculate the estimated commissions.");
            }

            //calculate commissions
            Console.WriteLine("Commission for open the position is {0}.", commissionProvider.calcOpenCommission(offer, account, iAmount, sBuySell, 0));
            Console.WriteLine("Commission for close the position is {0}.", commissionProvider.calcCloseCommission(offer, account, iAmount, sBuySell, 0));
            Console.WriteLine("Total commission for open and close the position is {0}.", commissionProvider.calcTotalCommission(offer, account, iAmount, sBuySell, 0, 0));
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            O2GSession session = null;

            try
            {
                LoginParams  loginParams  = new LoginParams(ConfigurationManager.AppSettings);
                SampleParams sampleParams = new SampleParams(ConfigurationManager.AppSettings);

                PrintSampleParams("CalculateTradingCommissions", loginParams, sampleParams);

                session = O2GTransport.createSession();
                session.useTableManager(O2GTableManagerMode.Yes, null);
                statusListener = new SessionStatusListener(session);
                session.subscribeSessionStatus(statusListener);
                statusListener.Reset();
                session.login(loginParams.Login, loginParams.Password, loginParams.URL, loginParams.Connection);
                if (statusListener.WaitEvents() && statusListener.Connected)
                {
                    O2GTableManager       tableManager  = session.getTableManager();
                    O2GTableManagerStatus managerStatus = tableManager.getStatus();
                    while (managerStatus == O2GTableManagerStatus.TablesLoading)
                    {
                        Thread.Sleep(50);
                        managerStatus = tableManager.getStatus();
                    }

                    if (managerStatus == O2GTableManagerStatus.TablesLoadFailed)
                    {
                        throw new Exception("Cannot refresh all tables of table manager");
                    }
                    O2GAccountTableRow account = GetAccount(tableManager, sampleParams.AccountID);
                    if (account == null)
                    {
                        throw new Exception(string.IsNullOrEmpty(sampleParams.AccountID) ? "No valid accounts" : string.Format("The account '{0}' is not valid", sampleParams.AccountID));
                    }

                    O2GOfferTableRow offer = GetOffer(tableManager, sampleParams.Instrument);
                    if (offer == null)
                    {
                        throw new Exception(string.Format("The instrument '{0}' is not valid", sampleParams.Instrument));
                    }

                    O2GLoginRules loginRules = session.getLoginRules();
                    if (loginRules == null)
                    {
                        throw new Exception("Cannot get login rules");
                    }

                    O2GTradingSettingsProvider tradingSettingsProvider = loginRules.getTradingSettingsProvider();
                    int iBaseUnitSize = tradingSettingsProvider.getBaseUnitSize(sampleParams.Instrument, account);
                    int iAmount       = iBaseUnitSize * sampleParams.Lots;

                    printEstimatedTradingCommissions(session, offer, account, iAmount, sampleParams.BuySell);
                    Console.WriteLine("Done!");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e.ToString());
            }
            finally
            {
                if (session != null)
                {
                    if (statusListener.Connected)
                    {
                        statusListener.Reset();
                        session.logout();
                        statusListener.WaitEvents();
                    }
                    session.unsubscribeSessionStatus(statusListener);
                    session.Dispose();
                }
            }
        }
Ejemplo n.º 14
0
 public void onChanged(string rowID, O2GRow rowData)
 {
     O2GAccountTableRow trade = (O2GAccountTableRow)rowData;
 }