Public timer1_counter As Integer = 5 ' used to count down 5 tenths of a second
Place this code at the beginning of the cbSymbol_keyDown event AxTws1.reqAccountUpdates(0, "DU132564") ' number zero cancels request
Place this code at the end of the cbSymbol keyDown event for the AxTws1.reqAccountUpdates(1, "DU132564") ' number 1 requests account updates
Timer1.Start() ' starts the count down timer
numLimitPrice KeyDown Event
Private Sub numPrice_KeyDown(sender As Object, e As KeyEventArgs) Handles numPrice.KeyDown
numPrice.DecimalPlaces = 2
numPrice.Increment = 0.1
End Sub
numLimitPrice Keyup Event Private Sub numPrice_KeyUp(sender As Object, e As KeyEventArgs) Handles numPrice.KeyUp
numPrice.DecimalPlaces = 2
numPrice.Increment = 0.01
End Sub
Tick Event Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
' checks if the timer = 0
If (timer1_counter = 0) Then
' puts the value of Bid from the text box into the limit price numericUpDown
numPrice.Value = Double.Parse(tbBid.Text)
Timer1.Stop() ' Stops the timer
timer1_counter = 5 ' resets the counter to 5
End If
' counter counts down 1 every tick
timer1_counter -= 1
End Sub
[showhide type="links2" more_text=" * Show the code for updatePortfolioEx click here" less_text=" * Hide the code for updatePortfolioEx click here"] Private Sub AxTws1_updatePortfolioEx(sender As Object, e As AxTWSLib._DTwsEvents_updatePortfolioExEvent) Handles AxTws1.updatePortfolioEx
Dim theSymbol1 As String
theSymbol1 = e.contract.symbol
' e.averageCost
' e.marketValue
' e.realizedPNL
' e.unrealizedPNL
' e.position
' e.marketValue
' e.contract.symbol = stock symbol
' if the symbol in the combo box is the same as the e.contract.symbol
' then add the Position size and the average price to the text boxes
If theSymbol1 = cbSymbol.Text Then
' Gets the average price of the current symbol
Dim averagePrice As Double = e.averageCost
'Rounds off the current price adds it to the text box
tbAvgPrice.Text = averagePrice.ToString("0.00")
' puts the position size in the text box
tbPosition.Text = e.position.ToString()
End If
End Sub
[/showhide]
No comments:
Post a Comment