private void btnSecurityDefinitionRequest_Click(object sender, EventArgs e) { _qf._contracts.Clear(); TT.SendMsg send = new TT.SendMsg(); send.ttSecurityDefinitionRequest(_gw, _product, QuickFix.SecurityType.FUTURE, null); }
/// <summary> /// /// </summary> /// <param name="MGT"></param> /// <param name="acct"></param> /// <param name="SecEx"></param> /// <param name="product"></param> /// <param name="secID"></param> /// <param name="tradesize"></param> /// <param name="side"></param> /// <param name="price"></param> /// <param name="gateway"></param> private void UpdatePosition( string MGT, string acct, string SecEx, string product, string secID, int tradesize, char side, decimal price, string gateway) { log.WriteLog("mainForm::UpdatePosition"); //added to filter by account if (isAccountFilterEnabled) { string watchedAccount = dsRisk.tblTrader.Rows.Find(MGT).Field<string>(dsRisk.tblTrader.AccountColumn); if (watchedAccount == null || watchedAccount != acct) { log.WriteList("Execution disregarded because account does not match"); return; } } //end account filter code int currentBuyPos = 0; int currentSellPos = 0; decimal currentBuyPrc = 0.00M; decimal currentSellPrc = 0.00M; int previousBuyPos = 0; int previousSellPos = 0; if (side == QuickFix.Fields.Side.SELL ) { currentSellPos = tradesize; currentSellPrc = price; } else if (side == QuickFix.Fields.Side.BUY) { currentBuyPos = tradesize; currentBuyPrc = price; } else { log.WriteList("NO BuySell info"); return; } try { if (dsRisk.tblPositions.Rows.Find(new object[] { MGT, SecEx, product, secID }) == null) { //TODO why cast to double?? dsRisk.tblPositions.AddtblPositionsRow(MGT, SecEx, product, secID, currentBuyPos, currentSellPos, (double)currentBuyPrc, (double)currentSellPrc, 0.00, 0.00, gateway, acct ); TT.SendMsg send = new TT.SendMsg(); send.ttSecurityDefinitionRequest(SecEx, product, secID); send.ttMarketDataRequest(SecEx, product, secID); } else { DataRow dr = dsRisk.tblPositions.Rows.Find(new object[] { MGT, SecEx, product, secID }); dr[dsRisk.tblPositions.AccountColumn] = acct; //existing buy/sell positions previousBuyPos = (int)dr[dsRisk.tblPositions.BuyPosColumn]; previousSellPos = (int)dr[dsRisk.tblPositions.SellPosColumn]; dr[dsRisk.tblPositions.BuyPosColumn] = previousBuyPos + currentBuyPos; dr[dsRisk.tblPositions.SellPosColumn] = previousSellPos + currentSellPos; decimal previousAvgBuyPrc = 0.00M; if ( dr[dsRisk.tblPositions.AvgBuyColumn] != null) previousAvgBuyPrc = (decimal )dr[dsRisk.tblPositions.AvgBuyColumn]; decimal previousAvgSellPrc = 0.00M; if ( dr[dsRisk.tblPositions.AvgSellColumn] != null) previousAvgSellPrc = (decimal )dr[dsRisk.tblPositions.AvgSellColumn]; dr[dsRisk.tblPositions.AvgBuyColumn] = ((previousBuyPos * previousAvgBuyPrc) + (currentBuyPos * currentBuyPrc)) / (previousBuyPos + currentBuyPos); dr[dsRisk.tblPositions.AvgSellColumn] = ((previousSellPos * previousAvgSellPrc) + (currentSellPos * currentSellPrc)) / (previousSellPos + currentSellPos); // using decimals negates the need to check for NaN? // if (dr[dsRisk.tblPositions.AvgBuyColumn].Equals(decimal. .NaN)) { dr[dsRisk.tblPositions.AvgBuyColumn] = 0.00; } // if (dr[dsRisk.tblPositions.AvgSellColumn].Equals(decimal .NaN)) { dr[dsRisk.tblPositions.AvgSellColumn] = 0.00; } dr.AcceptChanges(); } DataRow drPrc = dsRisk.tblSecurity.Rows.Find(new object[] { SecEx, product, secID }); if (drPrc != null) { decimal bid = (decimal )drPrc[dsRisk.tblSecurity.BidPriceColumn]; decimal ask = (decimal )drPrc[dsRisk.tblSecurity.AskPriceColumn]; CalcPnL(SecEx, product, secID, bid, ask); } } catch (Exception ex) { log.WriteList("Exception occured mainForm::UpdatePosition"); log.WriteLog(ex.ToString()); } }