public void Cleanup() { Cleanup(this.dataFeed); this.dataFeed = null; Cleanup(this.dataTrade); this.dataTrade = null; }
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; }
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(); }
public void Cleanup() { if (this.dataTrade != null) { if (this.dataTrade.IsStarted) { this.dataTrade.Stop(); } this.dataTrade.Dispose(); this.dataTrade = null; } }
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(); }
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); } }
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(); }
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; }
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"); } }
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; }
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(); } }
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(); }
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(); }
internal TradeRecord(DataTrade dataTrade) { this.DataTrade = dataTrade; }
void CreateAndDestroy(ConnectionStringBuilder builder) { var connectionString = builder.ToString(); this.dataTrade = new DataTrade(connectionString); this.dataTrade.Dispose(); }
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(); }
public void Dispose() { if (this.Trade == null) return; this.Trade.Stop(); this.Trade.Dispose(); this.Trade = null; }
private static void RunExample(DataTrade trade) { var records = trade.Server.GetTradeRecords(); }
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(); }
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; }