How to do Real time Monitoring of an API feed?

Omnomnom

Junior Member
Apr 3, 2014
7
0
0
How to do Real time Monitoring of an API feed and execute a function when a variable exceeds x?

I want to monitor API feeds like the one below (in as close to real time as possible, pulled every e.g. 60 seconds) for instances of e.g. the variable "total" and alert me/execute a macro of my choice when instances of "total" exceed e.g. 100.
Looking for a working example using any means.

I'm a beginner I understand things such as functions/macros (from autohotkey), html & css. This is the most complex thing that I've attempted so far so please keep things as simple as possible :D.

https://api.mintpal.com/v1/market/trades/bc/btc

Code:
[{    "count":"100",    "trades":[{       "type":"1",       "price":"0.00000023",       "amount":"412128.80177019",       "total":"0.09478962",       "time":"1394498289.2727"    },    ... }]
 
Last edited:

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,697
4,658
75
Hm, you're on Windows (autohotkey), aren't you? This would be easier in Linux. On Windows, maybe the easiest way would be to write a user script to parse the JSON? Here's a bunch of tutorials on writing user scripts for Greasemonkey (a Firefox add-on):

http://wiki.greasespot.net/Tutorials

You'll need to reload the page periodically. Here's how to do that.

Alerting can be done with alert(), but that usually doesn't leave the browser window these days. And you certainly can't execute a macro outside the browser from the browser.
 

Omnomnom

Junior Member
Apr 3, 2014
7
0
0
Hm, you're on Windows (autohotkey), aren't you? This would be easier in Linux. On Windows, maybe the easiest way would be to write a user script to parse the JSON? Here's a bunch of tutorials on writing user scripts for Greasemonkey (a Firefox add-on):

http://wiki.greasespot.net/Tutorials

You'll need to reload the page periodically. Here's how to do that.

Alerting can be done with alert(), but that usually doesn't leave the browser window these days. And you certainly can't execute a macro outside the browser from the browser.

I'll try this, a browser popup would be a useful start, maybe there is something that can play a sound or send and email as well with greasemonkey.
 

Omnomnom

Junior Member
Apr 3, 2014
7
0
0
This is what I've got so far. Are there any tools to debug? Can you see any problems with this already?

Code:
// ==UserScript==
// @name        Mintpal1
// @namespace   MintPal
// @include     [URL]https://api.mintpal.com/v1/market/trades/bc/btc[/URL]
// @version     1
// @grant       none
// ==/UserScript==

var $;

// Add jQuery
    (function(){
        if (typeof unsafeWindow.jQuery == 'undefined') {
            var GM_Head = document.getElementsByTagName('head')[0] || document.documentElement,
                GM_JQ = document.createElement('script');
    
            GM_JQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
            GM_JQ.type = 'text/javascript';
            GM_JQ.async = true;
    
            GM_Head.insertBefore(GM_JQ, GM_Head.firstChild);
        }
        GM_wait();
    })();

// Check if jQuery's loaded
    function GM_wait() {
        if (typeof unsafeWindow.jQuery == 'undefined') {
            window.setTimeout(GM_wait, 100);
        } else {
            $ = unsafeWindow.jQuery.noConflict(true);
            letsJQuery();
        }
    }

// All your GM code must be inside this function
    function letsJQuery() {
        alert($); // check if the dollar (jquery) function works
        alert($().jquery); // check jQuery version
    }

$.getJSON('https://api.mintpal.com/v1/market/trades/bc/btc', {}, function(JsonData){

    if ( total >= 10 ) {
      alert(A trade with a value over 10 BTC has been executed.)
    }

    
  }

});

<script>
     var time = new Date().getTime();
     $(document.body).bind("mousemove keypress", function(e) {
         time = new Date().getTime();
     });

     function refresh() {
         if(new Date().getTime() - time >= 60000) 
             window.location.reload(true);
         else 
             setTimeout(refresh, 10000);
     }

     setTimeout(refresh, 10000);
</script>