public OandaAccountModel ToOandaAccountModel(OandaAccount oandaAccount) { if (oandaAccount == null) { return(new OandaAccountModel()); } return(new OandaAccountModel { OandaAccountId = oandaAccount.Id.ToString(), HasAccountCurrency = oandaAccount.HasAccountCurrency, HasAccountId = oandaAccount.HasAccountId, HasAccountName = oandaAccount.HasAccountName, HasBalance = oandaAccount.HasBalance, HasMarginAvail = oandaAccount.HasMarginAvail, HasMarginRate = oandaAccount.HasMarginRate, HasMarginUsed = oandaAccount.HasMarginUsed, HasOpenOrders = oandaAccount.HasOpenOrders, HasOpenTrades = oandaAccount.HasOpenTrades, HasRealizedPl = oandaAccount.HasRealizedPl, HasUnrealizedPl = oandaAccount.HasUnrealizedPl, accountCurrency = oandaAccount.accountCurrency, accountId = oandaAccount.accountId, accountName = oandaAccount.accountName, balance = oandaAccount.balance, marginAvail = oandaAccount.marginAvail, marginRate = oandaAccount.marginRate, marginUsed = oandaAccount.marginUsed, openOrders = oandaAccount.openOrders, openTrades = oandaAccount.openTrades, realizedPl = oandaAccount.realizedPl, unrealizedPl = oandaAccount.unrealizedPl, TransactionHistories = oandaAccount.TransactionHistories }); }
private string GetLastOrderId(string id) { string orderId = "0"; OandaAccount acct = ((OandaAccount)GetAccount(id)); if (acct.OrderList.Count > 0) { orderId = acct.OrderList[0].Id; } return(orderId); }
public override IAccount GetAccountDetails(string accountId) { OandaAccount accountInfo = null; accountInfo = GetAccount(accountId); if (accountInfo == null) { accountInfo = new OandaAccount(); accountInfo.Id = accountId; AccountInfoList.Add(accountInfo); } return(accountInfo); }
private OandaAccount GetAccount(string id) { OandaAccount rtnVal = null; foreach (OandaAccount act in AccountInfoList) { if (act.Id == id) { rtnVal = act; } } return(rtnVal); }
public override bool PlaceOrder(Order order, string accountId) { bool rtnVal = false; OandaAccount acct = null; try { order.OrderId = (Convert.ToInt32(GetLastOrderId(accountId)) + 1).ToString(); acct = ((OandaAccount)GetAccount(accountId)); if (order.OrderType == Constants.OrderAction.BUY) { if (acct.PositionList.Count == 0) { acct.PositionList.Add(new ForexPosition(order)); } else { foreach (Position pos in acct.PositionList) { if (pos.Symbol == order.Symbol) { pos.AddMoreStocks(order); } } } order.Status = "FILLED"; order.Count = order.Count; order.Price = order.Price; order.TradeId = (Convert.ToInt32(GetLastTradeId(accountId)) + 1).ToString(); order.DoneAt = DateTime.Now; // order.Status = "CANCELLED"; //order.PnL = ; //order.Brokerage = ; } if (order.OrderType == Constants.OrderAction.SELL) { } } catch (Exception ex) { throw ex; } return(rtnVal); }
public override bool PlaceOrder(Order order, string accountId) { bool rtnVal = false; OandaAccount acct = null; Position p; try { order.OrderId = (Convert.ToInt32(GetLastOrderId(accountId)) + 1).ToString(); acct = GetAccount(accountId); if (order.Side == Constants.OrderAction.BUY) { p = acct.GetForexPosition(order.Symbol); if (p == null) { acct.PositionList.Add(new ForexPosition(order)); } else { p.AddMoreStocks(order); } order.Status = "FILLED"; order.TradeId = (Convert.ToInt32(GetLastTradeId(accountId)) + 1).ToString(); order.DoneAt = DateTime.Now; rtnVal = true; } if (order.Side == Constants.OrderAction.SELL) { } } catch (Exception ex) { throw ex; } return(rtnVal); }
private string GetLastTradeId(string id) { OandaAccount acct = ((OandaAccount)GetAccount(id)); return(acct.LastTransactionId); }