Send http request with trade info

Created at 28 Jun 2016, 21:57
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
swingfish's avatar

swingfish

Joined 25.06.2016

Send http request with trade info
28 Jun 2016, 21:57


does anyone know if its possible to have a Bot that sends a web request on positions opening/closing and update them accordingly via http ? 

 

the idea is to store the ongoing trades in a external database for later analytics 

 

i have that for mt4 .. but seems harder to do in calgo .. 

 

 


@swingfish
Replies

moneybiz
28 Jun 2016, 22:19

RE:

Actually it's quite easy.
You need to subscribe to position opened and position closed events to send your requests to your web api.

Here is the code.

protected override void OnStart()
{
    // Subscribe to events.
    Positions.Opened += OnPositionOpened;
    Positions.Closed += OnPositionClosed;
}

protected override void OnStop()
{
    // Unsubscribe to events.
    Positions.Opened -= OnPositionOpened;
    Positions.Closed -= OnPositionClosed;
}

public void OnPositionOpened(PositionOpenedEventArgs args)
{
    var endpoint = "htpp://api.server.com/positions/add";
    var data = string.Format("pid={0}&ep={1}&et={2}", args.Position.Id, args.Position.EntryPrice, args.Position.EntryTime);

    var response = new WebClient().UploadString(endpoint, data);
}

public void OnPositionClosed(PositionClosedEventArgs args)
{
}

 


@moneybiz

swingfish
29 Jun 2016, 00:36

NICE !! 

that is actually more easy indeed ... thanks alot 

 


@swingfish