Get All Tiers of Margin (O2GO, CS)

From FxCodeBaseWiki
Jump to: navigation, search

The example shows how to get all tiers of margin (Liquidation, Maintenance and Entry margin requirements)for a certain account/offer. The sample prints values for all offers and all accounts.

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace Sample.MMR
{
    class Program
    {
        static FXCore.CoreAut mCore;
        static FXCore.TradeDeskAut mDesk;

        static void Main(string[] args)
        {
            try
            {
                if (args.Length < 2)
                {
                    Console.WriteLine("usage: sample.MMR.exe user password");
                    return;
                }

                //create an o2go object and log in                
                mCore = new FXCore.CoreAut();
                mDesk = (FXCore.TradeDeskAut)mCore.CreateTradeDesk("trader");
                mDesk.Login(args[0], args[1], "http://www.fxcorporate.com", "Demo");

                //enumerate all accounts and offers, for each pair offer + account show the MMR value
                FXCore.TableAut accounts = (FXCore.TableAut)mDesk.FindMainTable("accounts");
                FXCore.TableAut offers = (FXCore.TableAut)mDesk.FindMainTable("offers");
                FXCore.TradingSettingsProviderAut tradingSettings = (FXCore.TradingSettingsProviderAut)mDesk.TradingSettingsProvider;

                foreach (FXCore.RowAut account in (FXCore.RowsEnumAut)accounts.Rows)
                {
                    string account_id = (string)account.CellValue("AccountID");
                    Console.WriteLine("====Account {0}====", account_id);

                    object mmr, emr, lmr;
                    foreach (FXCore.RowAut offer in (FXCore.RowsEnumAut)offers.Rows)
                    {
                        string instrument = (string)offer.CellValue("Instrument");
                        bool threeLevelMargin = tradingSettings.GetMargins(instrument, account_id, out mmr, out emr, out lmr);

                        if (threeLevelMargin)
                            Console.WriteLine("Three level margin, {0}: MMR = {1}; EMR = {2}; LMR = {3}", instrument, mmr, emr, lmr);
                        else
                            Console.WriteLine("Single level margin, {0}: MMR = {1}; EMR = {2}; LMR = {3}", instrument, mmr, emr, lmr);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("{0}", e.ToString());
            }

            //finalizing
            mDesk.Logout();
        }
    }
}

This Article in Other Languages

Language: English  • español