<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi Noah,<br>
    <br>
    I haven't looked at your code, but this library parses that same
    feed. (It's also on Hackage)<br>
    <br>
    <a class="moz-txt-link-freetext" href="https://github.com/AndrewRademacher/coinbase-exchange">https://github.com/AndrewRademacher/coinbase-exchange</a><br>
    <br>
    You may want to either use it or take a look at the code.<br>
    <br>
    Cheers,<br>
    <br>
    Dimitri<br>
    <br>
    <br>
    <br>
    <div class="moz-cite-prefix">Em 23/08/15 16:06, Noah Sluss escreveu:<br>
    </div>
    <blockquote
cite="mid:CAM_Gs8epi-z7F0CYwP=qfKRF2uNq=7NQLjyb4p2UX99Qy_YrRw@mail.gmail.com"
      type="cite">
      <div dir="ltr">Hello,
        <div><br>
        </div>
        <div>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.</div>
        <div><br>
        </div>
        <div>Here is my code:</div>
        <div>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">{-#
            LANGUAGE ViewPatterns #-}<br>
            {-# LANGUAGE OverloadedStrings #-}<br>
          </blockquote>
          <div> </div>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">import
            Data.Text<br>
            import Data.Text.Encoding (decodeUtf8)<br>
            import Network.WebSockets<br>
            import qualified Data.ByteString.Lazy as LBS<br>
          </blockquote>
          <div> </div>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">main
            :: IO ()<br>
            main = runClient "<a moz-do-not-send="true"
              href="http://ws-feed.exchange.coinbase.com">ws-feed.exchange.coinbase.com</a>"
            8080 "/"  handleConnection<br>
            handleConnection connection = do<br>
              send connection initSub<br>
              let loop = do<br>
                    priceMsg <- receiveDataMessage connection<br>
                    print priceMsg<br>
              loop<br>
          </blockquote>
          <div> </div>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">initSub
            :: Message<br>
            initSub = DataMessage $ Text "{\"type\":\"subscribe\",
            \"product_id\":\"BTC-USD\"}"</blockquote>
        </div>
        <div><br>
        </div>
        <div>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: "<a moz-do-not-send="true"
            href="https://ws-feed.exchange.coinbase.com/">https://ws-feed.exchange.coinbase.com/</a>". </div>
        <div><br>
        </div>
        <div>This isn't right, because the websocket feed uses the
          <a class="moz-txt-link-freetext" href="wss://">wss://</a> protocol rather than <a class="moz-txt-link-freetext" href="https://">https://</a>. i've tried changing the
          url to be "<a class="moz-txt-link-freetext" href="wss://">wss://</a><a moz-do-not-send="true"
            href="http://ws-feed.exchange.coinbase.com/">ws-feed.exchange.coinbase.com/</a>",
          but when I try that, dns resolution fails. If I had to guess,
          I could imagine that it tries to look for "<a class="moz-txt-link-freetext" href="https://wss://">https://wss://</a><a
            moz-do-not-send="true"
            href="http://ws-feed.exchange.coinbase.com">ws-feed.exchange.coinbase.com</a>",
          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. </div>
        <div><br>
        </div>
        <div>Any insights as to what's going on here would be incredibly
          helpful.</div>
        <div><br>
        </div>
        <div>Thanks,</div>
        <div>Noah</div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Beginners mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Beginners@haskell.org">Beginners@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>