Description
Example used in
using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None, AddIndicators = true)]
public class WebSocketsExample : Robot
{
private WebSocketClient _webSocketClient = new WebSocketClient();
private readonly Uri _targetUri = new Uri("wss://marketdata.tradermade.com/feedadv");
protected override void OnStart()
{
_webSocketClient.Connect(_targetUri);
_webSocketClient.TextReceived += _webSocketClient_TextReceived;
var data = "{\"userKey\":\"wsI4foSciCjMyCuoc2xw\", \"symbol\":\"EURUSD\"}";
_webSocketClient.Send(data);
}
private void _webSocketClient_TextReceived(WebSocketClientTextReceivedEventArgs obj)
{
Print(obj.Text.Replace("{","").Replace("}","").ToString());
}
protected override void OnTick()
{
// Handle price updates here
}
protected override void OnStop()
{
_webSocketClient.Close(WebSocketClientCloseStatus.NormalClosure);
}
}
}
Spotware
Joined on 23.09.2013
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Web Sockets Example_withSourceCode.algo
- Rating: 5
- Installs: 207
- Modified: 26/08/2024 12:36
Warning! Running cBots downloaded from this section may lead to financial losses. Use them at your own risk.
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
Why can you connect to Websocket with AccessRights.None?