Status API returning exception message

Steve Sokolowski avatar
Steve Sokolowski
Archived posts: 4559
Joined: Aug 27, 2014

Re: Status API returning exception message

by Steve Sokolowski · · Post #5728

kaptainkrayola wrote:When I query the live stats api https://prohashing.com/api/status?key=XXX I get back the message : { message: 'An unexpected exception occurred. The issue has been logged.' }. The error only occurs if i use the key for an account with a lot of miners though. If i use they key from an account with no miners it returns fine.
The REST API is now unsupported. We asked in the forums if there would be opposition to reassigning resources to support a new live WAMP API, which can provide instant updates with less bandwidth.

Check out the WAMP API in the documentation. If you can implement that, it will provide you with much more data that changes within milliseconds, instead of being averaged over 90 seconds.
kaptainkrayola
Archived posts: 7
Joined: Apr 17, 2017

Re: Status API returning exception message

by kaptainkrayola · · Post #5742

I was able to get node.js to work with your api but there are two issues

1. Node.js does not like your SSL cert for some reason so you have to add

Code:

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
to your code otherwise node simply will not talk to your service

2. Your example code has an error at the top where you define

Code:

var wampConnection = null;
var wampUser = 'web';
var wampPassword = 'web';
you also need

Code:

var wampSession = null 
if you don't define "wampSession" then down in the initialSessionUpdatesReceived function it won't be defined and you won't get your subscription hooked up. The reference inside of connectionOpen isn't valid either. I see that session is passed to connectionOpen but i'm not sure if it's the same session data or not. Adding the wampSession definition above at the top fixes the error and I get miner updates now.
Steve Sokolowski avatar
Steve Sokolowski
Archived posts: 4559
Joined: Aug 27, 2014

Re: Status API returning exception message

by Steve Sokolowski · · Post #5743

kaptainkrayola wrote:I was able to get node.js to work with your api but there are two issues

1. Node.js does not like your SSL cert for some reason so you have to add

Code:

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
to your code otherwise node simply will not talk to your service

2. Your example code has an error at the top where you define

Code:

var wampConnection = null;
var wampUser = 'web';
var wampPassword = 'web';
you also need

Code:

var wampSession = null 
if you don't define "wampSession" then down in the initialSessionUpdatesReceived function it won't be defined and you won't get your subscription hooked up. The reference inside of connectionOpen isn't valid either. I see that session is passed to connectionOpen but i'm not sure if it's the same session data or not. Adding the wampSession definition above at the top fixes the error and I get miner updates now.
Wow, thanks! That explains why people were having trouble connecting.

But for some reason this code still works on the web version, so I guess that the SSL certificate issue is only a node.js issue? I'm not familiar with node.js, so I'm glad someone was able to help me out.

I'll check in your changes to the website code, and they should go out this weekend. I told Chris to tip you $5 for your hard work by crediting your account, since you did a great service to the community and to us.
mjgraham
Archived posts: 16
Joined: Oct 31, 2016

Re: Status API returning exception message

by mjgraham · · Post #5744

Just to add a bit I never could get the examples to work either but finally after looking at another example for poloniex I got this going, just to get the data and dump it to a JSON string so I can work on it elsewhere .

Code:

process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';

var autobahn = require('autobahn');
var wsuri = "wss://live.prohashing.com:443/ws";
var wampUser = 'web';
var wampPassword = wampUser;

var connection = new autobahn.Connection({
  url: wsuri,
  realm: "mining",
  authmethods: ['wampcra'],
  authid: wampUser,
  onchallenge: onChallenge
});

function onChallenge(wampSession, method, extra) {
        if (method == 'wampcra') {
                return autobahn.auth_cra.sign(wampPassword, extra.challenge);
        }
};

connection.onopen = function (session) {
        session.subscribe('profitability_updates', onProfitabilityUpdate);
        session.call('f_all_miner_updates', ['api_key']).then(initialSessionUpdatesReceived);
        session.subscribe('miner_updates_api_key', onMinerUpdate);
}
        function initialSessionUpdatesReceived(args,kwargs) {
                console.log(JSON.stringify(args));
        };


        function onProfitabilityUpdate(args,kwargs) {
                console.log(JSON.stringify(args[0]));
        };

        function onMinerUpdate(args,kwargs) {
                console.log(JSON.stringify(args[0]));
        };
connection.onclose = function () {
  console.log("Websocket connection closed");
}

connection.open();
of course replace apt_key with your key and you should get profit updates and miner updates and whatever else you can do to make it awesome.
kaptainkrayola
Archived posts: 7
Joined: Apr 17, 2017

Re: Status API returning exception message

by kaptainkrayola · · Post #5746

Steve Sokolowski wrote:
kaptainkrayola wrote:I was able to get node.js to work with your api but there are two issues

1. Node.js does not like your SSL cert for some reason so you have to add

Code:

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
to your code otherwise node simply will not talk to your service

2. Your example code has an error at the top where you define

Code:

var wampConnection = null;
var wampUser = 'web';
var wampPassword = 'web';
you also need

Code:

var wampSession = null 
if you don't define "wampSession" then down in the initialSessionUpdatesReceived function it won't be defined and you won't get your subscription hooked up. The reference inside of connectionOpen isn't valid either. I see that session is passed to connectionOpen but i'm not sure if it's the same session data or not. Adding the wampSession definition above at the top fixes the error and I get miner updates now.
Wow, thanks! That explains why people were having trouble connecting.

But for some reason this code still works on the web version, so I guess that the SSL certificate issue is only a node.js issue? I'm not familiar with node.js, so I'm glad someone was able to help me out.

I'll check in your changes to the website code, and they should go out this weekend. I told Chris to tip you $5 for your hard work by crediting your account, since you did a great service to the community and to us.

I'm guessing that since your cert works fine in the browsers it's a non-issue for client side implementations. NodeJS is likely just validating the cert a different way or is missing an intermediary in its particular cert store. The really fun part is that autobahnJS suppresses ALL unhandled exceptions so you didn't get an error trying to connect, your app just sat there doing nothing.

Thanks for the Tip, much appreciated. I really like the WS connection as well since push is always better than polling.
Steve Sokolowski avatar
Steve Sokolowski
Archived posts: 4559
Joined: Aug 27, 2014

Re: Status API returning exception message

by Steve Sokolowski · · Post #5756

kaptainkrayola wrote:
Steve Sokolowski wrote:
kaptainkrayola wrote:I was able to get node.js to work with your api but there are two issues

1. Node.js does not like your SSL cert for some reason so you have to add

Code:

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
to your code otherwise node simply will not talk to your service

2. Your example code has an error at the top where you define

Code:

var wampConnection = null;
var wampUser = 'web';
var wampPassword = 'web';
you also need

Code:

var wampSession = null 
if you don't define "wampSession" then down in the initialSessionUpdatesReceived function it won't be defined and you won't get your subscription hooked up. The reference inside of connectionOpen isn't valid either. I see that session is passed to connectionOpen but i'm not sure if it's the same session data or not. Adding the wampSession definition above at the top fixes the error and I get miner updates now.
Wow, thanks! That explains why people were having trouble connecting.

But for some reason this code still works on the web version, so I guess that the SSL certificate issue is only a node.js issue? I'm not familiar with node.js, so I'm glad someone was able to help me out.

I'll check in your changes to the website code, and they should go out this weekend. I told Chris to tip you $5 for your hard work by crediting your account, since you did a great service to the community and to us.

I'm guessing that since your cert works fine in the browsers it's a non-issue for client side implementations. NodeJS is likely just validating the cert a different way or is missing an intermediary in its particular cert store. The really fun part is that autobahnJS suppresses ALL unhandled exceptions so you didn't get an error trying to connect, your app just sat there doing nothing.

Thanks for the Tip, much appreciated. I really like the WS connection as well since push is always better than polling.
Your code is now featured in the documentation. In a future release next weekend, I'll add links to your packages. Your tip has also been paid.