Pregunta

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.

¿Fue útil?

Solución

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 Subscribe to Mt.Gox Bitcoin Feed

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

PubNub Mt.Gox Channel Stream Feed Listing for Ticker/Trade/Depth Signals

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top