Esempio n. 1
0
File: TestBase.cs Progetto: ifzz/FDK
 public void Cleanup()
 {
     Cleanup(this.dataFeed);
     this.dataFeed = null;
     Cleanup(this.dataTrade);
     this.dataTrade = null;
 }
Esempio n. 2
0
 internal TradeRecord(DataTrade dataTrade, FxOrder fxOrder)
 {
     this.DataTrade        = dataTrade;
     this.OrderId          = fxOrder.OrderId;
     this.ClientOrderId    = fxOrder.ClientOrderId;
     this.Symbol           = fxOrder.Symbol;
     this.Price            = fxOrder.Price;
     this.StopLoss         = fxOrder.StopLoss;
     this.TakeProfit       = fxOrder.TakeProfit;
     this.InitialVolume    = fxOrder.InitialVolume;
     this.Volume           = fxOrder.Volume ?? 0;
     this.StopPrice        = fxOrder.StopPrice;
     this.MaxVisibleVolume = fxOrder.MaxVisibleVolume;
     this.Commission       = fxOrder.Commission;
     this.Swap             = fxOrder.Swap;
     this.Profit           = fxOrder.Profit;
     this.InitialType      = (TradeRecordType)fxOrder.InitialType;
     this.Type             = (TradeRecordType)fxOrder.Type;
     this.Side             = fxOrder.Side;
     this.Comment          = fxOrder.Comment;
     this.Tag   = fxOrder.Tag;
     this.Magic = fxOrder.Magic;
     this.IsReducedOpenCommission  = fxOrder.IsReducedOpenCommission;
     this.IsReducedCloseCommission = fxOrder.IsReducedCloseCommission;
     this.ImmediateOrCancel        = fxOrder.ImmediateOrCancel;
     this.MarketWithSlippage       = fxOrder.MarketWithSlippage;
     this.Expiration = fxOrder.Expiration;
     this.Created    = fxOrder.Created;
     this.Modified   = fxOrder.Modified;
 }
Esempio n. 3
0
        public void StartTrade()
        {
            if (this.dataClient != null)
                throw new InvalidOperationException("Start method can be called only once.");

            var connectionString = this.Builder.ToString();
            var trade = new DataTrade(connectionString);
            trade.AccountInfo += this.OnAccountInfo;
            this.dataClient = trade;
            this.dataClient.Start();
        }
Esempio n. 4
0
 public void Cleanup()
 {
     if (this.dataTrade != null)
     {
         if (this.dataTrade.IsStarted)
         {
             this.dataTrade.Stop();
         }
         this.dataTrade.Dispose();
         this.dataTrade = null;
     }
 }
Esempio n. 5
0
        public void StartTrade()
        {
            if (this.dataClient != null)
            {
                throw new InvalidOperationException("Start method can be called only once.");
            }

            var connectionString = this.Builder.ToString();
            var trade            = new DataTrade(connectionString);

            trade.AccountInfo += this.OnAccountInfo;
            this.dataClient    = trade;
            this.dataClient.Start();
        }
Esempio n. 6
0
File: Program.cs Progetto: ifzz/FDK
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("Usage: AccountInfo.exe address login password");
                return;
            }

            try
            {
                if (!Directory.Exists(LogPath))
                    Directory.CreateDirectory(LogPath);

                string address = args[0];
                string login = args[1];
                string password = args[2];

                // Create data trade interface
                var trade = new DataTrade { SynchOperationTimeout = 30000 };

                // Create connection string
                FixConnectionStringBuilder builder = CreateBuilder(address, login, password);
                var connectionString = builder.ToString();

                // Initialize data trade interface
                trade.Initialize(connectionString);

                // Subscribe to data trade events
                trade.Logon += OnLogon;
                trade.Logout += OnLogout;
                trade.AccountInfo += OnAccountInfo;

                // Start data trade
                trade.Start();
                Console.WriteLine("DataTrade started!");
                Console.WriteLine("Please wait for login status...");

                // Wait for exit
                Console.ReadKey();

                // Stop data trade
                trade.Stop();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Esempio n. 7
0
        public void TestDataTradeIsolation()
        {
            const string address = "tpdemo.fxopen.com";
            const string username = "******";
            const string password = "******";

            EnsureDirectoriesCreated();

            // Create builder
            var builder = new FixConnectionStringBuilder
            {
                TargetCompId = "EXECUTOR",
                ProtocolVersion = FixProtocolVersion.TheLatestVersion.ToString(),
                SecureConnection = true,
                Port = 5004,
                //ExcludeMessagesFromLogs = "W",
                DecodeLogFixMessages = true,

                Address = address,
                Username = username,
                Password = password,

                FixLogDirectory = LogPath,
                FixEventsFileName = string.Format("{0}.trade.events.log", username),
                FixMessagesFileName = string.Format("{0}.trade.messages.log", username)
            };
            var trade = new DataTrade
            {
                SynchOperationTimeout = 30000
            };
            var connectionString = builder.ToString();
            trade.Initialize(connectionString);
            trade.Logon += OnLogon;
            trade.Start();
            var timeoutInMilliseconds = trade.SynchOperationTimeout;
            if (!_syncEvent.WaitOne(timeoutInMilliseconds))
            {
                throw new TimeoutException("Timeout of logon waiting has been reached");
            }
            RunExample(trade);

            trade.Dispose();
        }
Esempio n. 8
0
File: Snapshot.cs Progetto: ifzz/FDK
        internal Snapshot(DataTrade trade, DataFeed feed, StateCalculator calculator, object synchronizer, AutoResetEvent syncEvent)
        {
            this.synchronizer = synchronizer;
            this.syncEvent = syncEvent;
            this.calculator = calculator;

            this.Quotes = new Dictionary<string, Quote>();

            trade.Logon += this.OnTradeLogon;
            trade.SessionInfo += this.OnTradeSession;
            trade.AccountInfo += this.OnAccountInfo;
            trade.Logout += this.OnTradeLogout;

            feed.Logon += this.OnFeedLogon;
            feed.Logout += this.OnFeedLogout;
            feed.SymbolInfo += this.OnFeedSymbolInfo;
            feed.SessionInfo += this.OnFeedSessionInfo;

            calculator.StateInfoChanged += this.OnFinancialInfoChanged;
        }
Esempio n. 9
0
        public void Connect(string address, string username, string password, string logPath)
        {
            EnsureDirectoriesCreated(logPath);

            // Create builder
            SetupBuilder(address, username, password, logPath);
            Trade = new DataTrade
            {
                SynchOperationTimeout = 300000
            };
            var connectionString = Builder.ToString();
            Trade.Initialize(connectionString);
            Trade.Logon += OnLogon;
            Trade.Start();
            var timeoutInMilliseconds = Trade.SynchOperationTimeout;
            if (!_syncEvent.WaitOne(timeoutInMilliseconds))
            {
                throw new TimeoutException("Timeout of logon waiting has been reached");
            }
        }
Esempio n. 10
0
 internal TradeRecord(DataTrade dataTrade, FxOrder fxOrder)
 {
     this.DataTrade = dataTrade;
     this.OrderId = fxOrder.OrderId;
     this.ClientOrderId = fxOrder.ClientOrderId;
     this.Symbol = fxOrder.Symbol;
     this.Price = fxOrder.Price;
     this.StopLoss = fxOrder.StopLoss;
     this.TakeProfit = fxOrder.TakeProfit;
     this.InitialVolume = fxOrder.InitialVolume;
     this.Volume = fxOrder.Volume;
     this.Commission = fxOrder.Commission;
     this.Swap = fxOrder.Swap;
     this.Profit = fxOrder.Profit;
     this.Type = (TradeRecordType)fxOrder.Type;
     this.Side = fxOrder.Side;
     this.Comment = fxOrder.Comment;
     this.Expiration = fxOrder.Expiration;
     this.Created = fxOrder.Created;
     this.Modified = fxOrder.Modified;
 }
Esempio n. 11
0
        void CloseBy(ConnectionStringBuilder builder)
        {
            var connectionString = builder.ToString();
            using (this.dataTrade = new DataTrade(connectionString))
            {

                this.dataTrade.Logon += OnLogon;
                this.dataTrade.AccountInfo += DataTrade_AccountInfo;
                this.dataTrade.Start();

                bool status = this.logonEvent.WaitOne(LogonWaitingTimeout);
                status &= this.accountInfoEvent.WaitOne(LogonWaitingTimeout);
                Assert.IsTrue(status, "Timeout of logon event");

                TradeRecord order1 = this.dataTrade.Server.SendOrderEx("EURUSD", TradeCommand.Market, TradeRecordSide.Buy, 0, 10000, null, null, null, "comment", 1000000);
                TradeRecord order2 = this.dataTrade.Server.SendOrderEx("EURUSD", TradeCommand.Market, TradeRecordSide.Sell, 0, 10000, null, null, null, "comment", 1000000);

                Assert.IsTrue( dataTrade.Server.CloseByPositions(order1.OrderId, order2.OrderId) );
                var iter = this.dataTrade.Server.GetTradeTransactionReports(TimeDirection.Backward, false, DateTime.UtcNow.AddMinutes(-5), DateTime.UtcNow.AddMinutes(5));
                TradeTransactionReport tradeReport1 = iter.Item;
                iter.Next();
                TradeTransactionReport tradeReport2 = iter.Item;

                //Assert.IsTrue(tradeReport1.PositionById == order1.OrderId);
                Assert.IsTrue(tradeReport2.PositionById == order2.OrderId);


                this.dataTrade.Logon -= this.OnLogon;
                this.dataTrade.AccountInfo -= DataTrade_AccountInfo;
                this.dataTrade.Stop();
            }
        }
Esempio n. 12
0
        void TradeReports(ConnectionStringBuilder builder, TestContext testContext)
        {
            var connectionString = builder.ToString();
            this.dataTrade = new DataTrade(connectionString);

            this.dataTrade.Logon += this.OnLogon;
            this.dataTrade.Start();

            var status = this.logonEvent.WaitOne(LogonWaitingTimeout);
            Assert.IsTrue(status, "Timeout of logon event");
            
            //Test Limit order
            var order = this.dataTrade.Server.SendOrderEx(testContext.Symbol, TradeCommand.Limit, TradeRecordSide.Buy, testContext.VeryLowPrice, testContext.Volume, null, null, DateTime.UtcNow.AddHours(1), testContext.Comment, 1000000);
            Assert.IsTrue(order.Price == testContext.VeryLowPrice, "Invalid order price = {0}", order.Price);
            order.Delete();

            Reports.TradeTransactionReport tradeReport = this.dataTrade.Server.GetTradeTransactionReports(TimeDirection.Backward, false, DateTime.UtcNow.AddMinutes(-5), DateTime.UtcNow.AddMinutes(5)).Item;
            Assert.IsTrue(tradeReport.TradeRecordType == order.Type);
            Assert.IsTrue(tradeReport.Price == order.Price);

            //Test stop order
            order = this.dataTrade.Server.SendOrderEx(testContext.Symbol, TradeCommand.Stop, TradeRecordSide.Buy, testContext.VeryHighPrice, testContext.Volume, null, null, DateTime.UtcNow.AddHours(1), testContext.Comment, 1000000);
            Assert.IsTrue(order.Price == testContext.VeryHighPrice, "Invalid order price = {0}", order.Price);
            order.Delete();

            tradeReport = this.dataTrade.Server.GetTradeTransactionReports(TimeDirection.Backward, false, DateTime.UtcNow.AddMinutes(-5), DateTime.UtcNow.AddMinutes(5)).Item;
            Assert.IsTrue(tradeReport.TradeRecordType == order.Type);
            Assert.IsTrue(tradeReport.StopPrice == order.Price);


            this.dataTrade.Logon -= this.OnLogon;
            this.dataTrade.Stop();
            this.dataTrade.Dispose();
        }
Esempio n. 13
0
        void ModifyPosition(ConnectionStringBuilder builder)
        {
            var connectionString = builder.ToString();
            this.dataTrade = new DataTrade(connectionString);

            this.dataTrade.Logon += OnLogon;
            this.dataTrade.AccountInfo += DataTrade_AccountInfo;
            this.dataTrade.Start();

            bool status = this.logonEvent.WaitOne(LogonWaitingTimeout);
            status &= this.accountInfoEvent.WaitOne(LogonWaitingTimeout);
            
            Assert.IsTrue(status, "Timeout of logon event");

            var start = DateTime.UtcNow;
            TradeRecord order = this.dataTrade.Server.SendOrderEx("EURUSD", TradeCommand.Market, TradeRecordSide.Buy, 0, 10000, null, null, null, "comment", 1000000);
            DateTime end = DateTime.UtcNow;
            TimeSpan interval = (end - start);
            Console.WriteLine("Interval = {0}", interval);

            var modified = order.Modify(null, 1.0, null, null);

            order.Close();

            this.dataTrade.Logon -= this.OnLogon;
            this.dataTrade.AccountInfo -= DataTrade_AccountInfo;
            this.dataTrade.Stop();
            this.dataTrade.Dispose();
        }
Esempio n. 14
0
 internal TradeRecord(DataTrade dataTrade)
 {
     this.DataTrade = dataTrade;
 }
Esempio n. 15
0
 void CreateAndDestroy(ConnectionStringBuilder builder)
 {
     var connectionString = builder.ToString();
     this.dataTrade = new DataTrade(connectionString);
     this.dataTrade.Dispose();
 }
Esempio n. 16
0
        void SendMarketOrder(ConnectionStringBuilder builder)
        {
            var connectionString = builder.ToString();
            this.dataTrade = new DataTrade(connectionString);

            this.dataTrade.Logon += this.OnLogon;
            this.dataTrade.Start();

            var status = this.logonEvent.WaitOne(LogonWaitingTimeout);
            Assert.IsTrue(status, "Timeout of logon event");
            var order = this.dataTrade.Server.SendOrderEx("EURUSD", TradeCommand.Market, TradeRecordSide.Buy, 1.1, 10000, 0, 0, null, "comment", 1000000);
            Assert.IsTrue(order.Price > 0, "Invalid order price = {0}", order.Price);
            this.dataTrade.Logon -= this.OnLogon;
            this.dataTrade.Stop();
            this.dataTrade.Dispose();
        }
Esempio n. 17
0
File: Example.cs Progetto: ifzz/FDK
        public void Dispose()
        {
            if (this.Trade == null)
                return;

            this.Trade.Stop();
            this.Trade.Dispose();
            this.Trade = null;
        }
Esempio n. 18
0
 private static void RunExample(DataTrade trade)
 {
     var records = trade.Server.GetTradeRecords();
 }
Esempio n. 19
0
        void ModifyLimitOrder(ConnectionStringBuilder builder)
        {
            var connectionString = builder.ToString();
            this.dataTrade = new DataTrade(connectionString);

            this.dataTrade.Logon += this.OnLogon;
            this.dataTrade.Start();

            var status = this.logonEvent.WaitOne(LogonWaitingTimeout);
            Assert.IsTrue(status, "Timeout of logon event");

            //const double activationPrice = 1.1;
            //const double newActivationPrice = 1.0;
            //const double newStopLoss = 0.8;
            //const double newTakeProfit = 1.3;
            var newExpirationTime = DateTime.UtcNow.AddHours(1);

            var order = this.dataTrade.Server.SendOrderEx("EURUSD", TradeCommand.Limit, TradeRecordSide.Buy, 1.1, 10000, null, null, null, "comment", 1000000);
/*
            //this.ModifyLimitOrder(order, activationPrice, null, null, null, null);
            this.ModifyLimitOrder(order, activationPrice, null, null, null, newExpirationTime);

            //this.ModifyLimitOrder(order, activationPrice, null, null, newTakeProfit, null);
            this.ModifyLimitOrder(order, activationPrice, null, null, newTakeProfit, newExpirationTime);


            //this.ModifyLimitOrder(order, activationPrice, null, newStopLoss, null, null);
            this.ModifyLimitOrder(order, activationPrice, null, newStopLoss, null, newExpirationTime);

            //this.ModifyLimitOrder(order, activationPrice, null, newStopLoss, newTakeProfit, null);
            this.ModifyLimitOrder(order, activationPrice, null, newStopLoss, newTakeProfit, newExpirationTime);



            //this.ModifyLimitOrder(order, activationPrice, newActivationPrice, null, null, null);
            this.ModifyLimitOrder(order, activationPrice, newActivationPrice, null, null, newExpirationTime);

            //this.ModifyLimitOrder(order, activationPrice, newActivationPrice, null, newTakeProfit, null);
            this.ModifyLimitOrder(order, activationPrice, newActivationPrice, null, newTakeProfit, newExpirationTime);

            //this.ModifyLimitOrder(order, activationPrice, newActivationPrice, newStopLoss, null, null);
            this.ModifyLimitOrder(order, activationPrice, newActivationPrice, newStopLoss, null, newExpirationTime);

            //this.ModifyLimitOrder(order, activationPrice, newActivationPrice, newStopLoss, newTakeProfit, null);
            this.ModifyLimitOrder(order, activationPrice, newActivationPrice, newStopLoss, newTakeProfit, newExpirationTime);
            */
            order.Delete();

            this.dataTrade.Logon -= this.OnLogon;
            this.dataTrade.Stop();
            this.dataTrade.Dispose();
        }
Esempio n. 20
0
 internal TradeRecord(DataTrade dataTrade)
 {
     this.DataTrade = dataTrade;
 }
Esempio n. 21
0
        public void StateInfoChanged()
        {
            string connectionString = Configuration.ConnectionBuilders(AccountType.Gross, Configuration.ConnectionType.Feed).First().ToString();
            this.dataFeed = new DataFeed(connectionString);
            this.dataFeed.Logon += this.OnFeedLogon;

            connectionString = Configuration.ConnectionBuilders(AccountType.Gross, Configuration.ConnectionType.Trade).First().ToString();
            this.dataTrade = new DataTrade(connectionString);
            this.dataTrade.Logon += this.OnTradeLogon;

            StateCalculator stateCalculator = new StateCalculator(dataTrade, dataFeed);
            stateCalculator.StateInfoChanged += StateCalculator_StateInfoChanged;

            this.dataFeed.Start();
            this.dataTrade.Start();
            var status = this.feedLogonEvent.WaitOne(LogonWaitingTimeout);
            Assert.IsTrue(status, "Timeout of feed logon event");
            status = this.tradeLogonEvent.WaitOne(LogonWaitingTimeout);
            Assert.IsTrue(status, "Timeout of trade logon event");

            status = this.stateInfoEvent.WaitOne(LogonWaitingTimeout*10000);

            this.dataFeed.Stop();
            this.dataTrade.Stop();
            this.dataFeed.Logon -= this.OnFeedLogon;
            this.dataTrade.Logon -= this.OnTradeLogon;
        }