Last active
December 7, 2017 15:57
-
-
Save buybackoff/434b71cbab9b41462e9899cc4baddae2 to your computer and use it in GitHub Desktop.
GDAX WebSockets connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Net.WebSockets; | |
var wsc = new ClientWebSocket(); | |
await wsc.ConnectAsync(new Uri("wss://ws-feed.gdax.com"), CancellationToken.None); | |
Console.WriteLine("Connected..."); | |
var msg = @"{""type"": ""subscribe"", ""product_ids"": [""BTC-USD"", ""ETH-USD"", ""ETH-BTC""]}"; | |
Console.WriteLine(msg); | |
await wsc.SendAsync(new ArraySegment<byte>(Encoding.UTF8.GetBytes(msg)), WebSocketMessageType.Text, true, CancellationToken.None); | |
var buffer = new ArraySegment<byte>(new byte[4096]); | |
while (true) | |
{ | |
WebSocketReceiveResult result = await wsc.ReceiveAsync(buffer, CancellationToken.None); | |
if (result.CloseStatus.HasValue) | |
{ | |
Console.WriteLine("Closed connection..."); | |
break; | |
} | |
var str = Encoding.UTF8.GetString(buffer.Array, 0, result.Count); | |
Console.WriteLine(str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment