using javascript to monitor stk trends




script features :

give alarms at turning points
monitor only one stk

major functions:

Initial setup

read variable to store the stk code from local storage
create a button to change stk code and store to local storage

create a button to change trend period and store to local storage
trend period will be hour and 5 mins options

Collect data

read updated data from source, avoiding the cors

  theHeader = "http://web.ifzq.gtimg.cn/appstock/app/hkfqkline/get?_var=kline_dayqfq¶m=hk"
  theTail = ',day,,,1,qfq'
  con = url(paste0(theHeader,onecode,theTail), encoding = "GB2312") # GB2312


let script = document.createElement('script');
script.src = 'http://www.nealyang.cn/login?username=Nealyang&callback=callback';
document.body.appendChild(script);

function callback(res) {
  console.log(res);
}

function jsonCallback(json){
  console.log(json);
}

$.ajax({
  url: "http://run.plnkr.co/plunks/v8xyYN64V4nqCshgjKms/data-2.json",
  type: "application/json"
});

extract data and store in variable

calculate trend data

comparison

compare with previous trend data to decide alarm status
turning up:
if trend point is going down and data value is above trend point, trigger alarm(time, up, stkcode, value)

turning down:
if trend point is going up and data value is below trend point, trigger alarm(time, down, stkcode, value)

alarm function

<audio id="xyz" src="beep1.mp3" preload="auto"></audio>
<b onclick="playAudio()">test it</b>

<script>
function playAudio() { 
    document.getElementById('xyz').play();
    alert("time, up or down, stkcode, value!");
    record the time, status and value in local storage
} 
</script>