fxcm / ForexConnectAPI

Designed to trade, retrieve live/history price. Intended to be used to build auto-trading robots, custom trading on FXCM accounts.
132 stars 47 forks source link

How to change trade Stop Limit via vba / excel? #7

Closed AVISHAY123 closed 3 years ago

AVISHAY123 commented 3 years ago

How to change trade Stop Limit via vba / excel? thank you

fxcm-dhalpert commented 3 years ago

here is example ho to change a waiting order price or amount, you may need to pass to this function the order_id for the stop or limit attached to open position.

Sub editOrder(sOrderID As String, sAccountID As String, iAmount As Integer, dRate As Double) Dim factory As IRequestFactory Set factory = mSession.getRequestFactory() If factory Is Nothing Then Exit Sub End If Dim valuemapChangeOrder As IValueMap Set valuemapChangeOrder = factory.createValueMap() Call valuemapChangeOrder.setString(RequestParamsEnum_Command, fxconst.Commands.editOrder) Call valuemapChangeOrder.setString(RequestParamsEnum_OrderID, sOrderID) Call valuemapChangeOrder.setString(RequestParamsEnum_AccountID, sAccountID) Call valuemapChangeOrder.setDouble(RequestParamsEnum_Rate, dRate) Call valuemapChangeOrder.setInt(RequestParamsEnum_Amount, iAmount) Call valuemapChangeOrder.setString(RequestParamsEnum_CustomID, "EditOrderTest")

'create request from valueMap
Dim request As IRequest
Set request = factory.createOrderRequest(valuemapChangeOrder)
If request Is Nothing Then
    MsgBox "Order's request can not be created: " + factory.getLastError()
    Exit Sub
End If
Call mSession.sendRequest(valuemapChangeOrder)

End Sub

for more information please see online help, you may need to convert the C# to VBA, it uses same logic. https://fxcodebase.com/bin/forexconnect/1.4.1/help/DotNet/web-content.html#NetTradingCommandsEditOrder.html

AVISHAY123 commented 3 years ago

Thank you but this is for a waiting order I need for running trade

fxcm-dhalpert commented 3 years ago

when you have open position with stop an limit attached, the stop and limit are waiting orders and each has its own order_id, to change it you need to use order_id for stop or limit.

AVISHAY123 commented 3 years ago

Thank you it works Which command can I add to configure trailstep?

fxcm-dhalpert commented 3 years ago

the trailing stop can be changed from same function with same "editOrder" command, for example

Call valuemapChangeOrder.setInt(RequestParamsEnum_TrailStep, 15)

AVISHAY123 commented 3 years ago

I get an error "object required" there is no valuemapChangeOrder object

fxcm-dhalpert commented 3 years ago

the Call valuemapChangeOrder.setInt(RequestParamsEnum_TrailStep, 15) should be part of editOrder() function above.

AVISHAY123 commented 3 years ago

There is no error now, but it does nothing

fxcm-dhalpert commented 3 years ago

does the attached stop have already trailing stop? this function is to change existing order with trailing stop

AVISHAY123 commented 3 years ago

no How can I add trailing stop?

fxcm-dhalpert commented 3 years ago

when you create the new order add the trailing stop with the attached stop, using same Call valuemapChangeOrder.setInt(RequestParamsEnum_TrailStep, 15) just add it to the CreateOrder command.

AVISHAY123 commented 3 years ago

I created a new order and add that line But, there is no trailstep

fxcm-dhalpert commented 3 years ago

what are the valuemap fields

AVISHAY123 commented 3 years ago
Set valueMap = requestFactory.createValueMap()
Call valueMap.setString(RequestParamsEnum_Command, constants.Commands.createOrder)
Call valueMap.setString(RequestParamsEnum_OrderType, constants.orders.TrueMarketOpen)
Call valueMap.setInt(RequestParamsEnum_Amount, amount)
Call valueMap.setString(RequestParamsEnum_BuySell, buysell) 
Call valueMap.setString(RequestParamsEnum_AccountID, MyAcc)
Call valueMap.setString(RequestParamsEnum_OfferID, offer.OfferID)
Call valueMap.setDouble(RequestParamsEnum_RateLimit, Up) 
Call valueMap.setDouble(RequestParamsEnum_RateStop, Dn) 
Call valueMap.setInt(RequestParamsEnum_TrailStep, 50)
fxcm-dhalpert commented 3 years ago

Please replace TrailStep with TrailStepStop so the trailing stop will be for the attached stop not for the main order

AVISHAY123 commented 3 years ago

Now, the order not created

fxcm-dhalpert commented 3 years ago

Example ELS order with Trailing Stop

O2GRequest request = null; O2GRequestFactory requestFactory = session.getRequestFactory();

O2GValueMap valuemap = requestFactory.createValueMap(); valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder); valuemap.setString(O2GRequestParamsEnum.OrderType, "OM"); valuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID); valuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID); valuemap.setString(O2GRequestParamsEnum.BuySell, sBuySell); valuemap.setInt(O2GRequestParamsEnum.Amount, iAmount); valuemap.setDouble(O2GRequestParamsEnum.Rate, dRate); valuemap.setDouble(O2GRequestParamsEnum.RateLimit, dRateLimit); valuemap.setDouble(O2GRequestParamsEnum.RateStop, dRateStop); valuemap.setString(O2GRequestParamsEnum.CustomID, "EntryOrderWithStopLimit"); valuemap.setString(O2GRequestParamsEnum.TimeInForce, Constants.TIF.GTC); valuemap.setInt(O2GRequestParamsEnum.TrailStepStop, dTrailStepStop); <---- Trailing Stop

AVISHAY123 commented 3 years ago

Thank you but trade not created If I omit the last line, it created

fxcm-dhalpert commented 3 years ago

which version of FC API you using?

AVISHAY123 commented 3 years ago

1.4.1

fxcm-dhalpert commented 3 years ago

the fixed trailing stop should be 10 or above, dynamic trailing stop should be 1, just tested and it seems ok

Call valueMap.setInt(RequestParamsEnum_TrailStepStop, 10)

AVISHAY123 commented 3 years ago

still not created with that line

fxcm-dhalpert commented 3 years ago

can you please email the related snip code and parameters values to api@fxcm.com

AVISHAY123 commented 3 years ago

I just did