private void button5_Click(object sender, EventArgs e) { string serverTime = stiApp.GetServerTime(); SterlingLib.structSTIPositionUpdate positionStruct = stiPos.GetPositionInfoStruct("XOP", "E", Globals.account); }
/*private void stiEvents_OnSTIOrderUpdateXML(ref string orderUpdateInfo) * { * XmlSerializer xs = new XmlSerializer(typeof(SterlingLib.structSTIOrderUpdate)); * SterlingLib.structSTIOrderUpdate structTrade = (SterlingLib.structSTIOrderUpdate)xs.Deserialize(new StringReader(orderUpdateInfo)); * //MessageBox.Show("Picked Up"); * * * * }*/ private void stiEvents_OnSTIOrderUpdateXML(ref string orderUpdateInfo) { XmlSerializer xs = new XmlSerializer(typeof(SterlingLib.structSTIOrderUpdate)); SterlingLib.structSTIOrderUpdate structTrade = (SterlingLib.structSTIOrderUpdate)xs.Deserialize(new StringReader(orderUpdateInfo)); //MessageBox.Show("Picked Up"); if (autoProfitOn && Globals.profitTakeMethod == "3-Block") { if (structTrade.nOrderStatus == 13) { if (structTrade.nPriceType == 7 || structTrade.nPriceType == 8) { Form rangePicker = new RangePicker() { TopMost = true, TopLevel = true, StartPosition = FormStartPosition.CenterScreen }; int rangeMultiple = 1; DialogResult result = rangePicker.ShowDialog(); rangePicker.Activate(); rangePicker.TopMost = true; rangePicker.Focus(); rangePicker.BringToFront(); if (result == DialogResult.Yes) { rangeMultiple = 2; } if (result == DialogResult.No) { rangeMultiple = 3; } if (result == DialogResult.OK) { rangeMultiple = 4; } if (rangeMultiple == 1) { return; //Exit if no value chosen } string positionSize = stiPosition.GetPositionInfo(structTrade.bstrSymbol, "", Globals.account); if (Math.Abs(Convert.ToInt32(positionSize)) == (structTrade.nQuantity)) { SterlingLib.structSTIPositionUpdate positionInfo = stiPosition.GetPositionInfoStruct(structTrade.bstrSymbol, "", Globals.account); decimal positionCost = Math.Abs(Convert.ToDecimal(positionInfo.fPositionCost)); decimal averagePrice = Math.Abs(positionCost / Convert.ToDecimal(positionSize)); decimal stopRange = Math.Abs(averagePrice - Convert.ToDecimal(structTrade.fStpPrice)); //MessageBox.Show(averagePrice.ToString() + " : " + structTrade.fStpPrice + " : " + stopRange.ToString()); decimal profitRange = stopRange * rangeMultiple; //MessageBox.Show(profitRange.ToString()); //Now that we have the range, create a summary of the profit taker with the info... stopPrice = Convert.ToDecimal(structTrade.fStpPrice); incrementPrice = Math.Abs(Math.Round((profitRange) / (Convert.ToInt32(positionSize) / 100), 2)); numIntervals = Math.Abs(Convert.ToInt32(positionSize) / 100); profitRange = numIntervals * incrementPrice; //MessageBox.Show(incrementPrice.ToString()); //Now we have increment price, max size, initial size, starting size, starting price (average price, rounded to 2 decimal places) startingPrice = Math.Round(averagePrice, 2); rangeSize = Math.Abs(Math.Round(profitRange, 2)); startingSize = Convert.ToInt32(positionSize); if (Convert.ToInt32(positionSize) < 0) { direction = "S"; rangeEnd = startingPrice - rangeSize; } else if (Convert.ToInt32(positionSize) > 0) { direction = "B"; rangeEnd = startingPrice + rangeSize; } else { direction = "N"; } var myForm = new Form2(startingPrice, true, Math.Abs(Convert.ToInt32(positionSize)), Math.Abs(Convert.ToInt32(positionSize)), Math.Abs(Convert.ToInt32(positionSize)), rangeMultiple, Convert.ToDecimal(structTrade.fStpPrice), structTrade.bstrSymbol, direction); this.Invoke((MethodInvoker) delegate() { myForm.Show(); }); } else { MessageBox.Show("Stop order size must be equal to position size"); } } } } else if (autoProfitOn && Globals.profitTakeMethod == "Increment") { if (structTrade.nOrderStatus == 13) { if (structTrade.nPriceType == 7 || structTrade.nPriceType == 8) { Form rangePicker = new RangePicker() { TopMost = true, TopLevel = true, StartPosition = FormStartPosition.CenterScreen }; int rangeMultiple = 1; DialogResult result = rangePicker.ShowDialog(); rangePicker.Activate(); rangePicker.TopMost = true; rangePicker.Focus(); rangePicker.BringToFront(); if (result == DialogResult.Yes) { rangeMultiple = 2; } if (result == DialogResult.No) { rangeMultiple = 3; } if (result == DialogResult.OK) { rangeMultiple = 4; } if (rangeMultiple == 1) { return; //Exit if no value chosen } string positionSize = stiPosition.GetPositionInfo(structTrade.bstrSymbol, "", Globals.account); if (Math.Abs(Convert.ToInt32(positionSize)) == (structTrade.nQuantity)) { SterlingLib.structSTIPositionUpdate positionInfo = stiPosition.GetPositionInfoStruct(structTrade.bstrSymbol, "", Globals.account); decimal positionCost = Math.Abs(Convert.ToDecimal(positionInfo.fPositionCost)); decimal averagePrice = Math.Abs(positionCost / Convert.ToDecimal(positionSize)); decimal stopRange = Math.Abs(averagePrice - Convert.ToDecimal(structTrade.fStpPrice)); //MessageBox.Show(averagePrice.ToString() + " : " + structTrade.fStpPrice + " : " + stopRange.ToString()); decimal profitRange = stopRange * rangeMultiple; //MessageBox.Show(profitRange.ToString()); //Now that we have the range, create a summary of the profit taker with the info... stopPrice = Convert.ToDecimal(structTrade.fStpPrice); incrementPrice = Math.Abs(Math.Round((profitRange) / (Convert.ToInt32(positionSize) / 100), 2)); numIntervals = Math.Abs(Convert.ToInt32(positionSize) / 100); profitRange = numIntervals * incrementPrice; //MessageBox.Show(incrementPrice.ToString()); //Now we have increment price, max size, initial size, starting size, starting price (average price, rounded to 2 decimal places) startingPrice = Math.Round(averagePrice, 2); rangeSize = Math.Abs(Math.Round(profitRange, 2)); startingSize = Convert.ToInt32(positionSize); if (Convert.ToInt32(positionSize) < 0) { direction = "S"; rangeEnd = startingPrice - rangeSize; } else if (Convert.ToInt32(positionSize) > 0) { direction = "B"; rangeEnd = startingPrice + rangeSize; } else { direction = "N"; } decimal profitOffset = stopRange; var myForm = new Form1(startingPrice, true, Math.Abs(Convert.ToInt32(positionSize)), Math.Abs(Convert.ToInt32(positionSize)), Math.Abs(Convert.ToInt32(positionSize)), incrementPrice, profitOffset, 100, structTrade.bstrSymbol, direction); this.Invoke((MethodInvoker) delegate() { myForm.Show(); }); } else { MessageBox.Show("Stop order size must be equal to position size"); } } } } }