Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jun 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to do Real time Monitoring of an API feed and call a function on an event?

    How to do Real time Monitoring of an API feed and execute a function when a variable exceeds x? (Full length thread title)

    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 .

    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"
       },
       ...
    }]

  • #2
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,823
    Thanks
    42
    Thanked 199 Times in 198 Posts
    this is very vague- what language are you working in? what have you tried? are you simply looking for guidance? you could create triggers, timers, sleep()... There are many ways to do this.

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #3
    New to the CF scene
    Join Date
    Jun 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm looking for guidance, yes, I don't know know where to begin with this or what language or tools to use. If this code exists already as part of something then I'd like to use it as a snippet, compile it etc. I could easily edit the parameters.

  • #4
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,823
    Thanks
    42
    Thanked 199 Times in 198 Posts
    Quote Originally Posted by alykins View Post
    what language are you working in?
    Answering this is key

    Quote Originally Posted by alykins View Post
    you could create triggers, timers, sleep()
    events/triggers
    timers
    sleep()

    but those are just a few, and in .net. Need to pick a language first.

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #5
    New to the CF scene
    Join Date
    Jun 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I rewrote the whole description of what I'm trying to do

    How to Parse External JSON code in Greasemonkey (or any other language) and use comparison operators?

    I want to parse this JSON feed https://api.mintpal.com/v1/market/trades/bc/BTC and then execute an alert() when new instances of "total" in the JSON feed are greater than e.g. 100. What's the simplest way to do this? This is the code I have so far.

    The essence of what I'm trying to do is just below, ideally I want it to play a sound file and send me an email if that's possible, apparently executing external macros from the browser is impossible. I know this is probably a really simple thing to do for an experienced programmer, but I'm a beginner, I'm also interested in examples of this code in any other language as long as I can edit the parameters and compile on windows []

    Code:
    $.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.) //alert+execute sound file etc.
        }
    
    // some code to reload the feed to check for new data every 60 seconds.
    The full thing.

    Code:
    / ==UserScript==
    // @name        Mintpal1
    // @namespace   MintPal
    // @include     https://api.mintpal.com/v1/market/trades/bc/btc
    // @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>
    I'd like to be able the edit the thread title and op but no dice.

  • #6
    New to the CF scene
    Join Date
    Jun 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Alternative to JBison?

    I've found something that does exactly what I need it to do (JBison)

    https://softwaremill.com/img/uploads...02-28_2020.png

    The problem now is that it doesn't support JSON feeds above 2048 bytes (very strange limitation) and it checks the feed once every 5 minutes, instead of the 30-60 seconds which I need.
    Does anyone know of an alternative?


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •