/// <summary> /// Calculate current opened position of bot. /// /// Call from: /// /// Plaza2Connector\CuserDealsPosBox.RefreshBotPos /// Plaza2Connector\CuserDealsPosBox.CalcCurrentPos /// TradingLib\CalcCurrentPos /// </summary> public void CalcCurrentPos() { decimal openedAmount; AvPos = CalcAvPosHist(ListOpeningPosChanges, out openedAmount); //if no stock best price zero - calc is incorrect if (!m_userDealsPosBox.UserDealsPosBoxClient.IsStockOnline) { return; //out } //KAA 2016-Aug-05 VMCurrent_Points = Mult * (GetBestPrice() - AvPos); VMCurrent_Steps = VMCurrent_Points / m_minStep; //VMCurrent_RUB_clean = _vmCalc.GetVMCurrent_RUB_clean(openedAmount); //VMCurrent_RUB_clean = VMCurrent_Steps * m_stepPrice * openedAmount; VMCurrent_RUB_clean = VMCalc.GetVMCurrent_RUB_clean(this, openedAmount); VMCurrent_RUB = VMCurrent_RUB_clean - Fee; }
/// <summary> /// Close position. Call when position fully closed or postion /// has changed the sign (in that case we close /// position and open it again in UserDealsPosBox). /// /// Call from /// /// -Plaza2Connector\UserDealsPosBox.CalculateBotsPos /// /// </summary> /// <param name="dtClose"></param> /// <param name="replIdClosed"></param> public void Close(DateTime dtClose, long replIdClosed) { // //replaced 2018-06-16 //DtClose = dtClose; //ReplIdClosed = replIdClosed; SetDtCloseReplIdClose(dtClose, replIdClosed); decimal openedAmount; decimal closedAmount; decimal openedCost = CalcAvPosHist(ListOpeningPosChanges, out openedAmount); decimal closedCost = CalcAvPosHist(ListClosingPosChanges, out closedAmount); mx.WaitOne(); //TODO check if we need VMClosed_Points = Mult * (closedCost - openedCost); //calc points of profit Fee_Stock = CalcTotalFeeHist(); //calc fee from stock Fee = m_userDealsPosBox.BrokerFeeCoef * Fee_Stock; //calc broker dealing fee,calc using stock fee mult by Coef if (m_minStep > 0) { VMClosed_Steps = VMClosed_Points / m_minStep; //calc steps of profit //VMClosed_RUB_clean = VMClosed_Steps * m_stepPrice * openedAmount; //clean profit in RUB no fee VMClosed_RUB_clean = VMCalc.GetVMClosed_RUB_clean(this, openedAmount); VMClosed_RUB = VMClosed_RUB_clean - Fee; //profit in rub with broker dealing CloseAmount = closedAmount; PriceOpen = openedCost; PriceClose = closedCost; VMClosed_RUB_user = VMClosed_RUB; Fee_Total = Fee; } mx.ReleaseMutex(); }