Author

Topic: MtGox Streaming API Question (Read 1293 times)

full member
Activity: 217
Merit: 100
April 29, 2013, 06:10:34 PM
#13
Quote
That is how you unsubscribe and subscribe to channels. If you need help subscribing to the lag channel later to late me know Smiley I didn't realize the socket io and the websocket were that close in syntax

Edit: had to change some of the leftover code from mine

He didn't ask, so I'll ask... How do you subscribe to the lag channel? Thanks!



+1
newbie
Activity: 5
Merit: 0
April 29, 2013, 01:22:20 PM
#12
Quote
That is how you unsubscribe and subscribe to channels. If you need help subscribing to the lag channel later to late me know Smiley I didn't realize the socket io and the websocket were that close in syntax

Edit: had to change some of the leftover code from mine

He didn't ask, so I'll ask... How do you subscribe to the lag channel? Thanks!

newbie
Activity: 32
Merit: 0
April 10, 2013, 05:05:26 PM
#11
Finally figured it out.  The code from listentobitcoin.com really helped https://github.com/MaxLaumeister/Listen-To-Bitcoin/blob/master/socket.js

I was just missing wrapping JSON.stringify() around my send message.

Using this is much easier though: http://blockchain.info/api/exchange_rates_api

But if you do go the socket to mtgox route, it looks like a plain reconnecting websocket like listen to bitcoin switched to is more reliable than the socket.io version.

newbie
Activity: 32
Merit: 0
April 09, 2013, 04:54:37 PM
#10
I think I'm going to abandon connecting to their socket directly as it seems unreliable and use my server as a proxy to communicate with mtgox api.

On server side, every 15-30 seconds my server will send an ajax request to
https://data.mtgox.com/api/2/BTCUSD/money/ticker
If the price has changed I will update my entry in my database to reflect the new price and emit a socket.io event of a price update

On client side, the user will initially ping my server db for the price info and then connect to my server using socket.io and wait for price updates.
newbie
Activity: 12
Merit: 0
April 09, 2013, 07:01:06 AM
#9
Hrmmmm.

Crap. I'm not sure then. I've been up all night and it's 8:02 I can barely stay awake Sad I'll try again in a few hours
newbie
Activity: 32
Merit: 0
April 09, 2013, 06:44:06 AM
#8
You sure you're not receiving depth channel info still?  Here's the code I tried.

Code:
   
   

Output from console.  In bold is the server reply to my mtgox.send() request.

Connected
Object {op: "subscribe", channel: "dbf1dee9-4f2e-4a08-8cb7-748919a71b21"}
Object {op: "subscribe", channel: "d5f06780-30a8-4a48-a2f8-7ed181b4a13f"}
Object {op: "subscribe", channel: "24e67e0d-1cad-4cc0-9e7a-f8523ef460fe"}
Object {op: "remark", success: false, message: "Unknown command", debug: Object}
Object {channel: "24e67e0d-1cad-4cc0-9e7a-f8523ef460fe", channel_name: "depth.BTCUSD", op: "private", origin: "broadcast", private: "depth"…}
Object {channel: "d5f06780-30a8-4a48-a2f8-7ed181b4a13f", channel_name: "ticker.BTCUSD", op: "private", origin: "broadcast", private: "ticker"…}
$206.00002
Object {channel: "24e67e0d-1cad-4cc0-9e7a-f8523ef460fe", channel_name: "depth.BTCUSD", op: "private", origin: "broadcast", private: "depth"…}
Object {channel: "dbf1dee9-4f2e-4a08-8cb7-748919a71b21", channel_name: "trade.BTC", op: "private", origin: "broadcast", private: "trade"…}
 
newbie
Activity: 12
Merit: 0
April 09, 2013, 06:30:47 AM
#7
ok this

Code:
LogTextToConsole(output, msg.ticker.last.display_[Suspicious link removed]String());

don't know why this keeps saying that but it is supposed to be display_short and then .toString()

edit: double edit, damn I gotta hit the sack soon I am tired. Messing up

Code:
ob.insertBefore(divText, ob.firstChild);
ob.firstChild was console.firstChild i switched it to ob.firstChild (what it is supposed to be).

now all should work fine... I hope
newbie
Activity: 12
Merit: 0
April 09, 2013, 06:13:42 AM
#6
Ok so here is the code you are looking for (and one of my homemade functions, enjoy). This works and should show you what you want.

Code:




Untitled Document











http://www.introspectivity.com/TradeThatCoin/testcode.php

What I think was going wrong for you was where you had your script. I've always seen them at the bottom of the body for sockets, that's where I've been putting mine anywhere with no problems.

also biggest thing they don't specifically tell you

Code:
mtgox.send({
     "channel":depth,
     "op":"unsubscribe"
});

That is how you unsubscribe and subscribe to channels. If you need help subscribing to the lag channel later to late me know Smiley I didn't realize the socket io and the websocket were that close in syntax

Edit: had to change some of the leftover code from mine
newbie
Activity: 12
Merit: 0
April 09, 2013, 05:45:54 AM
#5
Code:




Untitled Document









This so far is listing the channels as they come in. Everytime the server sends out one of the channels (ticker, depth, or trades) it lists the channel in the console. I am now going to try and do the other part you were working on
newbie
Activity: 12
Merit: 0
April 09, 2013, 05:36:16 AM
#4
Trying to work on your code right now bud - should have a solution for you and reasoning here in like 15
newbie
Activity: 32
Merit: 0
April 09, 2013, 05:07:56 AM
#3
I am having the same problem but using socket.io... the newbie restriction here is incredibly frustrating.  I read the whole Mtgox API thread(though not while logged in) and didn't find an answer.  Here's my code which seems to work, but I can't figure out how to unsubscribe from channels.

   
   

I've tried the below at various places, but haven't gotten that to work.
       //var unsub = {"op": "unsubscribe", "channel": "d5f06780-30a8-4a48-a2f8-7ed181b4a13f"};
       //mtgox.emit("broadcast", unsub);
       //mtgox.send(unsub);
newbie
Activity: 12
Merit: 0
April 09, 2013, 04:48:15 AM
#2
bump
newbie
Activity: 12
Merit: 0
April 09, 2013, 04:20:54 AM
#1
Working on a trade ticker. I know there are a good chunk of these already but I am working on a personal one for me and a few friends. Figure my server would be able to handle me and 2 other people better than trying to squeeze in with 5000 other people.

Anywho... was going to post in https://bitcointalk.org/index.php?topic=5855.340 but I guess I have to do it here for now

http://www.introspectivity.com/TradeThatCoin/ - The product of a few hours worth of work today (and learning how to use WebSockets, small pain in the ass but fairly easy!). I am noticing that however I don't stay connected for long with the mtgox streaming api on my site and that other websites like bitcoin.clarkmoody.com connection stay alive a lot longer.

Currently in my code I am unsubscribed from 2 channels, would this have an effect? Maybe because things aren't getting pushed as much? If this is the case I thought websockets was supposed to just remain alive?

I am pretty confused as far as that goes. Not really sure what to do to fix that.

Edit: P.S Go easy on me as far as looks... This is no where near the finished version. Just needed a console to look @ output while I hammer all the bugs out then drastically change the layout (gonna be more for mobile - Clarks unfortunately doesn't have a mobile version)
Jump to: