public bool SellHoldingFromAccount(int Quantity, string Ticker, ITradeHandlerInterface TradeHandler, string ProcessCode = "Manual") { //first check that the quantity does not exceed the quantity of the security on the account IMoney GAA = GetGAAFromHolding(Quantity, Ticker); //calculate revenue from the current ticker Quote HoldingTicker = ImperaturGlobal.Quotes.Where(q => q.Symbol.Equals(Ticker)).First(); IMoney oRevenue = GetRevenueFromHoldingSell(Quantity, Ticker); ITradeInterface Trade = TradeHandler.GetTrade(Ticker, Quantity, DateTime.Now, oRevenue); //minus for sell try { AddTransaction( CreateTransaction( Trade.TradeAmount, GetHouseAccountFromCache().First(), this.Identifier, TransactionType.Sell, Trade, ProcessCode ) ); } catch (Exception ex) { ImperaturGlobal.GetLog().Error(string.Format("Couldn't create transaction for sell on account {0}", this.Identifier), ex); LastErrorMessage = ex.Message; return(false); } return(true); }
public bool AddHoldingToAccount(int Quantity, string Symbol, ITradeHandlerInterface TradeHandler, string ProcessCode = "Manual") { ITradeInterface Trade = TradeHandler.GetTrade(Symbol, Quantity); try { AddTransaction( CreateTransaction( Trade.TradeAmount, this.Identifier, GetHouseAccountFromCache().First(), TransactionType.Buy, Trade, ProcessCode ) ); } catch (Exception ex) { ImperaturGlobal.GetLog().Error(string.Format("Couldn't add transaction to account {0}", this.Identifier), ex); LastErrorMessage = ex.Message; return(false); } return(true); }
public Simulator(ILimitOrderBook limitOrderBook, IDataFeed dataCommunicationsModule, ITradeInterface orderCommunicationsModule) { _limitOrderBook = limitOrderBook; _dataCommunicationsModule = dataCommunicationsModule; _orderCommunicationsModule = orderCommunicationsModule; _orderCommunicationsModule.OnOrder += _orderCommunicationsModule_OnOrder; _orderCommunicationsModule.OnOrderCancellation += _orderCommunicationsModule_OnOrderCancellation; }
public Transaction(IMoney _DebitAmount, IMoney _CreditAmount, Guid _DebitAccount, Guid _CreditAccount, TransactionType _TransactionType, ITradeInterface _SecurtiesTrade, DateTime _TransactionDate, string _ProcessCode = "Manual") { this._DebitAmount = _DebitAmount; this._CreditAmount = _CreditAmount; this._DebitAccount = _DebitAccount; this._CreditAccount = _CreditAccount; this._TransactionType = _TransactionType; this._SecuritiesTrade = _SecurtiesTrade; this._TransactionDate = _TransactionDate; this._ProcessCode = _ProcessCode; if (!_DebitAmount.Amount.Equals(_CreditAmount.Amount)) { throw new Exception("Amount is not equal"); } }
public ITradeInterface GetTrade(string Symbol, decimal Quantity, DateTime TradeDateTime, IMoney Revenue) { Quote oHoldingTicker = GetQuote(Symbol); IMoney TradeAmount = oHoldingTicker.LastTradePrice.Multiply(Quantity); Security NewSecurity = new Security() { Price = oHoldingTicker.LastTradePrice, Symbol = Symbol }; ITradeInterface oNewTrade = ImperaturGlobal.Kernel.Get <ITradeInterface>( new Ninject.Parameters.ConstructorArgument("m_oQuantity", Quantity), new Ninject.Parameters.ConstructorArgument("m_oSecurity", NewSecurity), new Ninject.Parameters.ConstructorArgument("m_oTradeAmount", TradeAmount), new Ninject.Parameters.ConstructorArgument("m_oTradeDateTime", TradeDateTime), new Ninject.Parameters.ConstructorArgument("m_oRevenue", Revenue) ); return(oNewTrade); }
private ITransactionInterface CreateTransaction(IMoney NewTransaction, Guid DebitAccount, Guid CreditAccount, TransactionType TransactionType, ITradeInterface SecurtiesTrade, string ProcessCode = "Manual") { return(ImperaturGlobal.Kernel.Get <ITransactionInterface>( new Ninject.Parameters.ConstructorArgument("_DebitAmount", NewTransaction), new Ninject.Parameters.ConstructorArgument("_CreditAmount", NewTransaction), new Ninject.Parameters.ConstructorArgument("_DebitAccount", DebitAccount), new Ninject.Parameters.ConstructorArgument("_CreditAccount", CreditAccount), new Ninject.Parameters.ConstructorArgument("_TransactionType", TransactionType), new Ninject.Parameters.ConstructorArgument("_SecurtiesTrade", SecurtiesTrade ?? (object)null), new Ninject.Parameters.ConstructorArgument("_ProcessCode", ProcessCode) )); }