public MonitorPosInst(string isin, CBotPos bp, string stFormat) { Id = isin; Amount = bp.Amount; AvPos = bp.AvPos; //string stFormat = "0.0"; AvPosString = AvPos.ToString(stFormat); VMCurrent_Points = bp.VMCurrent_Points; VMCurrent_RUB = bp.VMCurrent_RUB; VMCurrent_Steps = bp.VMCurrent_Steps; }
public void Recalc(CRawOrdersLogStruct ol, CLogger logger) { decimal oldAmount = Amount; Amount = (ol.Dir == (sbyte)OrderDirection.Buy) ? Amount + ol.Amount : Amount - ol.Amount; if (Amount != 0) { //new del has same dir as pos if ((oldAmount >= 0 && ol.Dir == (sbyte)OrderDirection.Buy) || (oldAmount <= 0 && ol.Dir == (sbyte)OrderDirection.Sell)) { AvPos = (AvPos * Math.Abs(oldAmount) + ol.Deal_Price * ol.Amount) / (Math.Abs(oldAmount) + ol.Amount); } else //new dir has another direction and more than pos if ((Math.Abs(ol.Amount) > Math.Abs(oldAmount))) { AvPos = ol.Deal_Price; } } else { AvPos = 0; } logger.Log("Amount=" + Amount + " AvPos=" + AvPos.ToString("0.0") + " | oldAmount=" + oldAmount + " | ol.Price=" + ol.Deal_Price + " ol.Amount=" + ol.Amount + " ol.Dir=" + ol.Dir + " ol.Id_ord=" + ol.Id_ord); }