I'm writing an app in Dart, which PubNub has no libraries for. My question is, would it be possible to interact with MtGox api (which is, as far as I understand, built on PubNub) using Websockets? How does PubNub relate to Websockets? Their documentation mostly advertises their SDK libraries. I'm rather confused where to start.
-
excellent question we are working on providing an answer here for you. – Stephen Blum Jan 08 '14 at 19:44
-
are you looking to build a graph with Dart that is Real-time or one that shows 24 hour trends? – Stephen Blum Jan 08 '14 at 20:39
-
I'm building a trading app, so I'm gonna need to update an order book in real time and stuff like that. – orion3 Jan 08 '14 at 21:01
1 Answers
PubNub Dart Subscribe to Mt.Gox Bitcoin Feed
The question ask about how to use the PubNub Real-Time Network without an SLA officially supported SDK provided by PubNub. We do not recommend this and instead have provided the recommended method which includes using the standard import 'dart:js'
library interop. Details follow but if you still want to continue with a non-library method, the docs for the HTTP REST Push API interface will be a general starting point. But now we are going onward with the recommended method below! Please continue reading.
Subscribing to the Mt.Gox Bitcoin Real-Time feed using Google Dart is rather simple, though a bit confusing at first. Start by setting up your HTML file with the following script tags; and don't forget the PubNub <div>
!
PubNub Dart HTML File Example
<h1>PubNub Dart JavaScript SDK Usage Example</h1>
<div id="pubnub" sub-key="sub-c-50d56e1e-2fd9-11e3-a041-02ee2ddab7fe"></div>
<script src="https://cdn.pubnub.com/pubnub.min.js"></script>
<script type="application/dart" src="pubnub_sample.dart"></script>
<script src="packages/browser/dart.js"></script>
<script src="packages/browser/interop.js"></script>
NOTE: The PubNub
<div>
includes the Mt.Gox Subscribe Key paramater.
PubNub Dart Source File and SDK Usage Subscribe Callback Example
Next your Dart app source code will simply open the TCP Socket to the live stream. Note the channel ID is d5f06780-30a8-4a48-a2f8-7ed181b4a13f
. This is one of many channel streams provided by Mt.Gox which allow you to receive Trade/Depth/Ticker signals.
PubNub Dart Source File
import 'dart:js';
void main() {
context['PUBNUB'].callMethod( 'subscribe', [new JsObject.jsify({
"channel" : "d5f06780-30a8-4a48-a2f8-7ed181b4a13f",
"message" : ( message, env, channel, age ) => print(message)
})] );
}
That's it! You can start receiving live Real-Time signals from Mt.Gox using this method. Also you'll want to add or change the channel for different types of events.
NOTE: You can find more Mt.Gox Channels by requesting the channel listing API call: PubNub Mt.Gox Channel Stream Feed Listing for Ticker/Trade/Depth Signals

- 6,498
- 2
- 34
- 46
-
Indeed, simply using PubNub js lib from Dart with dart:js would work and that can be considered a solution for now. Still, being somewhat of a purist, I wish I had more insight into how pubnub actually works. Your example in the answer is under construction and not finished, but it looks like you're not intending to use PubNub API directly, but rather just call methods on a pubnub object. So, to clarify, I don't really need Dart code, but rather some info on where to connect and what to expect :) – orion3 Jan 09 '14 at 07:50
-
You are indeed correct! We are going to use the PubNub JavaScript SDK inside Dart. But it is a bit tricky so we are looking in to ways to solve this for you. – Stephen Blum Jan 10 '14 at 03:35
-
@snitko Okay we finally found a working example which allows you to subscribe to the stream feed of Mt.Gox using the SLA supported JavaScript SDK provided by PubNub. – Stephen Blum Jan 10 '14 at 05:19