public string FilterTrades(string username, string clientid, string acctcode, string symbol, string sectype, string time, string exchange, string side) { try { TradeFilter filter = new TradeFilter(); filter.AcctCode = acctcode; int iClientId = 0; if (int.TryParse(clientid, out iClientId)) { filter.ClientId = iClientId; } filter.Exchange = exchange; filter.SecType = sectype; filter.Side = side; filter.Symbol = symbol; filter.Time = time; Trade[] trades = new IBTradingService().FilterTrades(username, filter); if (trades != null) { trades.ToCSV(); } return(string.Empty); } catch (Exception ex) { _Logger.Error(ex); throw ex; } }
public string GetAllOpenOrders(string username) { try { Order[] orders = new IBTradingService().GetAllOpenOrders(username); if (orders != null) { return(orders.ToCSV()); } return(string.Empty); } catch (Exception ex) { _Logger.Error(ex); throw ex; } }
public string GetAccountSummary(string username) { try { AccountSummary[] summary = new IBTradingService().GetAccountSummary(username); if (summary != null) { return(summary.ToCSV()); } return(string.Empty); } catch (Exception ex) { _Logger.Error(ex); throw ex; } }
public string GetPositions(string username) { try { Position[] positions = new IBTradingService().GetPositions(username); if (positions != null) { return(positions.ToCSV()); } return(string.Empty); } catch (Exception ex) { _Logger.Error(ex); throw ex; } }
public string GetAllTrades(string username) { try { Trade[] trades = new IBTradingService().GetAllTrades(username); if (trades != null) { return(trades.ToCSV()); } return(string.Empty); } catch (Exception ex) { _Logger.Error(ex); throw ex; } }
static void ConnectServiceTest() { IBTradingService service = new IBTradingService(); string username = "******"; string account = "127.0.0.1"; if (service.CreateUser(username, account, "127.0.0.1", 4002)) { var summary = service.GetAccountSummary(username); var properties = summary[0].GetType().GetProperties(); foreach (var property in properties) { Console.WriteLine(string.Format("{0}:{1}", property.Name, property.GetValue(summary[0]))); } var simpleOrder = new Skywolf.Contracts.DataContracts.Trading.SimpleOrder() { UserName = "******", Action = Skywolf.Contracts.DataContracts.Trading.TradeAction.SELL, Currency = "USD", Folder = "Index", Quantity = 20000, SecurityType = Skywolf.Contracts.DataContracts.Trading.TradeSecurityType.FX, Strategy = "SmartBeta", Fund = "FX", Symbol = "EUR" }; try { int result = service.PlaceSimpleOrder(simpleOrder); Console.WriteLine(string.Format("OrderId is {0}", result)); } catch (Exception ex) { Console.WriteLine(string.Format("Error is {0}", ex.Message)); } } Console.Read(); }
public string GetOpenOrder(string username, string orderId) { try { int iOrderId = 0; int.TryParse(orderId, out iOrderId); Order order = new IBTradingService().GetOpenOrder(username, iOrderId); if (order != null) { return(new Order[] { order }.ToCSV()); } return(string.Empty); } catch (Exception ex) { _Logger.Error(ex); throw ex; } }
public string PlaceSimpleOrder(string username, string orderid, string securitytype, string symbol, string currency, string quantity, string ordertype, string action, string limitprice, string stopprice, string fund, string strategy, string folder) { try { SimpleOrder order = null; int iOrderId = 0; int.TryParse(orderid, out iOrderId); double dQuantity = double.Parse(quantity); double dLmtPrice = 0; double.TryParse(limitprice, out dLmtPrice); double dStpPrice = 0; double.TryParse(stopprice, out dStpPrice); switch (ordertype) { case "MKT": order = new SimpleMarketOrder(); break; case "LMT": order = new SimpleLimitOrder(); (order as SimpleLimitOrder).LimitPrice = dLmtPrice; break; case "STP": order = new SimpleStopOrder(); (order as SimpleStopOrder).StopPrice = dStpPrice; break; } switch (action) { case "BUY": order.Action = TradeAction.BUY; break; case "SELL": order.Action = TradeAction.SELL; break; } order.Currency = currency; order.OrderId = iOrderId; order.Quantity = dQuantity; switch (securitytype) { case "FX": order.SecurityType = TradeSecurityType.FX; break; case "STK": order.SecurityType = TradeSecurityType.Stock; break; } order.Symbol = symbol; order.UserName = username; if (!string.IsNullOrEmpty(fund)) { order.Fund = fund; } if (!string.IsNullOrEmpty(strategy)) { order.Strategy = strategy; } if (!string.IsNullOrEmpty(folder)) { order.Folder = folder; } int retOrderId = new IBTradingService().PlaceSimpleOrder(order); return(retOrderId.ToString()); } catch (Exception ex) { _Logger.Error(ex); throw ex; } }