Knowledgebase:
ClosePosition
Posted by Mohammad Rahhal, Last modified by Rawan Al Hourani on 04 July 2018 11:46 AM

Syntax

 Function ClosePosition(ByRef AccountID As Integer, ByRef Ticket As Integer, ByRef Amount As Double, ByRef Price As Double, ByRef RefAskPrice As Double, ByRef Comm As Double, RefBidPrice As Double,TransTag As String ,Optional UserDefinedDate As String = "") As CallingResultsEnum

To close an open position at a specific price for a given account. After ClosePosition method executes the ClosePosResult event fire.

Parameters

Part Description 
AccountID Account number to close the position for it, a value of type Integer.
Ticket Ticket number for the position you want to close, a value of type Integer.
Amount Amount of lots, value of type double.
Price The price you want to close in, a value of type double.
RefAskPrice  Ask price for reference symbol, a value of type double.
Comm The Commission you want to use when close the position, value of type double.
RefBidPrice  Bid price for reference symbol, a value of type double.
TransTag String value to mark the close position operation when the result came from the server.
UserDefinedDate

Trade close time , Date in format (DD/MM/YYYY HH:mm:ss).

"" : means Now.

 

Return value  

Returns value of type CallingResultsEnum ,if the request sent to the server successfully it will return SuccessResult.

Sample

 
 Public WithEvents m_oBOAPI As CVertexFXBOAPI 

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

     Dim result As VertexFXBOAPI11.CallingResultsEnum
     Dim vAccount As COAccount
     Dim vClient As COClient
     Dim vSym As COSymbol
     Dim Pos As COOpenPosition
     Dim AccountID As Integer
     vSym = m_oBOAPI.SymbolByIndex(1,True)
     vClient = m_oBOAPI.ClientByIndex(1)
     vAccount = m_oBOAPI.AccountByIndex(vClient.ClientID,1)
     AccountID = vAccount.AccountID
     Pos = m_oBOAPI.OpenPositionByIndex(1)

     result = m_oBOAPI.ClosePosition(AccountID, Pos.Ticket, Pos.Lots, Pos.Price, Pos.RefAskPrice, 0, Pos.RefBidPrice,"TransTag","")

     MsgBox(result.ToString)

 End Sub

 Private Sub m_oBOAPI_ClosePosResult(ByRef Result As VertexFXBOAPI11.NewOrderResultEnum, ByRef OpenTicket As Integer, TransTag as String) Handles m_oBOAPI.ClosePosResult

        MsgBox(Result.ToString)

 End Sub
 


See Also


VertexFX Backoffice API Index

(0 vote(s))
Helpful
Not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).

Help Desk Software by Hybrid Solutions