[Haskell-beginners] Websockets Library

Dimitri DeFigueiredo defigueiredo at ucdavis.edu
Sun Aug 23 22:19:36 UTC 2015


Hi Noah,

I haven't looked at your code, but this library parses that same feed. 
(It's also on Hackage)

https://github.com/AndrewRademacher/coinbase-exchange

You may want to either use it or take a look at the code.

Cheers,

Dimitri



Em 23/08/15 16:06, Noah Sluss escreveu:
> Hello,
>
> I've been trying to use the WebSockets library to connect to the 
> coinbase feed. The library seems to be doing something behind the 
> scenes that I'm not expecting.
>
> Here is my code:
>
>     {-# LANGUAGE ViewPatterns #-}
>     {-# LANGUAGE OverloadedStrings #-}
>
>     import Data.Text
>     import Data.Text.Encoding (decodeUtf8)
>     import Network.WebSockets
>     import qualified Data.ByteString.Lazy as LBS
>
>     main :: IO ()
>     main = runClient "ws-feed.exchange.coinbase.com
>     <http://ws-feed.exchange.coinbase.com>" 8080 "/"  handleConnection
>     handleConnection connection = do
>       send connection initSub
>       let loop = do
>             priceMsg <- receiveDataMessage connection
>             print priceMsg
>       loop
>
>     initSub :: Message
>     initSub = DataMessage $ Text "{\"type\":\"subscribe\",
>     \"product_id\":\"BTC-USD\"}"
>
>
> When I run this, I get a print out showing a malformed response 
> exception with a Moved permanently message. Now, it also shows the 
> location that I was trying to connect to, which is: 
> "https://ws-feed.exchange.coinbase.com/".
>
> This isn't right, because the websocket feed uses the wss:// protocol 
> rather than https://. i've tried changing the url to be 
> "wss://ws-feed.exchange.coinbase.com/ 
> <http://ws-feed.exchange.coinbase.com/>", but when I try that, 
> dns resolution fails. If I had to guess, I could imagine that it tries 
> to look for "https://wss://ws-feed.exchange.coinbase.com 
> <http://ws-feed.exchange.coinbase.com>", which would obviously not 
> work. I'm wondering if there is a way within the library to change the 
> protocol that  client uses. If there is, it doesn't seem to be 
> documented.
>
> Any insights as to what's going on here would be incredibly helpful.
>
> Thanks,
> Noah
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150823/6210b3ff/attachment.html>


More information about the Beginners mailing list