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 ..

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