Configurar Time In Force para At Best Market Order (O2GO, CS)

From FxCodeBaseWiki
Jump to: navigation, search

El ejemplo muestra cómo poner el Tiempo En Fuerza (TIF) para una En La Mejor orden de mercado. Hay son tres posible valores: GTC, IOC, y FOK. En este ejemplo tres órdenes con los tres posibles valores de TIF son creadas. La diferencia en el ejecución de los órdenes no son muestran en este ejemplo porque el TIF ha un impacto en el órdenes ejecución sólo en caso ha no suficiente liquidez llena el entero orden, y lo imposible similar la falta de liquidez en este ejemplo.

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

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

        static void Main(string[] args)
        {
            try
            {
                if (args.Length < 2)
                {
                    Console.WriteLine("usage: sample.TIF.exe user password");
                    return;
                }
                
                //create an o2go object and log in                
                mCore = new FXCore.CoreAut();
                mDesk = (FXCore.TradeDeskAut)mCore.CreateTradeDesk("trader");
                FXCore.TradingSettingsProviderAut tradingSettings = (FXCore.TradingSettingsProviderAut)mDesk.TradingSettingsProvider;
                mDesk.Login(args[0], args[1], "http://www.fxcorporate.com", "Demo");
                
                //collect all required information
                FXCore.TableAut acct = (FXCore.TableAut)mDesk.FindMainTable("accounts");
                FXCore.TableAut offer = (FXCore.TableAut)mDesk.FindMainTable("offers");

                string instrument = (string)offer.CellValue(1, "Instrument");
                string account_id = (string)acct.CellValue(1, "AccountID");
                int amount = tradingSettings.GetMinQuantity(instrument, account_id);               

                //open trades
                object trade_order_id1, trade_order_id2, trade_order_id3, di;
                
                //open a GTC trade
                mDesk.OpenTrade3(account_id, instrument, true, amount, 0, null, 0, mDesk.SL_NONE, 0, 0, 0, 0, mDesk.TIF_GTC, out trade_order_id1, out di);

                //open an IOC trade
                mDesk.OpenTrade3(account_id, instrument, true, amount, 0, null, 0, mDesk.SL_NONE, 0, 0, 0, 0, mDesk.TIF_IOC, out trade_order_id2, out di);

                //open an FOK trade
                mDesk.OpenTrade3(account_id, instrument, true, amount, 0, null, 0, mDesk.SL_NONE, 0, 0, 0, 0, mDesk.TIF_FOK, out trade_order_id3, out di);

                //wait until the trades appear in the table, but not more than 5 seconds                
                string trade_id1 = WaitTrade((string)trade_order_id1);
                string trade_id2 = WaitTrade((string)trade_order_id2);
                string trade_id3 = WaitTrade((string)trade_order_id3);

                Console.WriteLine("A trade opened by the GTC market order is {0}.", trade_id1);
                Console.WriteLine("A trade opened by the IOC market order is {0}.", trade_id2);
                Console.WriteLine("A trade opened by the FOK market order is {0}.", trade_id3);

            }
            catch (Exception e)
            {
                Console.WriteLine("{0}", e.ToString());
            }

             //finalizing
             mDesk.Logout();
        }

        /// <summary>
        /// Waits for a trade opened by the order during a 5 second timeout.
        /// Returns the identifier of the trade or null.
        /// </summary>        
        static string WaitTrade(string trade_order_id)
        {            
            string trade_id = null;
            long start_time = DateTime.Now.Ticks;
            FXCore.TableAut trades = (FXCore.TableAut)mDesk.FindMainTable("trades");
            while (trade_id == null)
            {                
                if ((DateTime.Now.Ticks - start_time) > 50000000)
                {
                    Console.WriteLine("5 second timeout to wait for the trade expired");
                    return null;
                }

                try
                {
                    FXCore.RowAut row = (FXCore.RowAut)trades.FindRow("OpenOrderID", (string)trade_order_id, 0);
                    trade_id = (string)row.CellValue("TradeID");
                }
                catch (Exception)
                {
                    //the trade is not found
                    Thread.Sleep(250);
                }
            }
            return trade_id;
        }
    }

Este Artículo en Otros Idiomas

Language: English  • español