ageisp0lis

[bitcoin] mt.gox live ticker for mIRC

Nov 2nd, 2011
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 7.13 KB | None | 0 0
  1. /*
  2. mt.gox live ticker for mIRC
  3. by ageis @ #bitcoin-otc on freenode
  4. modified: 11/02/2011
  5. donations: 1AgeisUFv9NJ3AGGq7VPJWymGfFpCHDhCw
  6.  
  7. this script supplies small dialog(s)/window(s)
  8. to load the script, type /load -rs mtgoxticker.mrc
  9. !! you must allow initialization commands
  10. to set variables required by this script !!
  11. to show the ticker, type /mtgoxticker
  12. to configure settings, type /mtgoxsettings
  13. or right-click for the menu
  14.  
  15. options:
  16. - vertical or horizontal tickers    [default: horizontal]
  17. - adjustable refresh rate       [default: 30 seconds]
  18. - always on top             [default: on]
  19. - show on desktop           [default: off]
  20. - refresh while offline         [default: off]
  21. */
  22.  
  23. on *:LOAD:{
  24.   unset mtgox*
  25.   set %mtgoxurl https://mtgox.com/code/ticker.php
  26.   set %mtgoxrefresh 30
  27.   set %mtgoxaot 1
  28.   set %mtgoxoffline 0
  29.   set %mtgoxdesktop 0
  30.   set %mtgoxvert 0
  31. }
  32.  
  33. menu * {
  34.   mt.gox
  35.   ..ticker:mtgoxticker
  36.   ..config:mtgoxsettings
  37. }
  38.  
  39. dialog mtgoxconfig {
  40.   title "settings"
  41.   size -1 -1 54 78
  42.   option dbu
  43.   check "always on top",1, 2 2 45 10,
  44.   check "show on desktop",2, 2 12 50 10,
  45.   check "refresh offline",3, 2 22 45 10,  
  46.   combo 9,2 33 50 9, drop
  47.   text "refresh rate:",4, 2 45 50 8, center
  48.   edit "",5, 2 52 30 11, limit 5
  49.   text "secs",6, 34 54 10 10
  50.   button "okay",99, 2 66 50 10, ok flat
  51. }
  52.  
  53. dialog mtgoxticker_vt {
  54.   title "mt.gox"
  55.   size -1 -1 48 60
  56.   option dbu
  57.   text "AVG:" ,1, 2   0 14 8
  58.   edit ""     ,2, 18  0 30 10,read
  59.   text "LOW:" ,3, 2  10 14 8
  60.   edit ""     ,4, 18 10 30 10,read
  61.   text "HIGH:",5, 2  20 14 8
  62.   edit ""     ,6, 18 20 30 10,read
  63.   text "BID:" ,7, 2  30 14 8
  64.   edit ""     ,8, 18 30 30 10,read
  65.   text "ASK:" ,9, 2  40 14 8
  66.   edit ""     ,10,18 40 30 10,read
  67.   text "LAST:",11,2  50 14 8
  68.   edit ""     ,12,18 50 30 10,read
  69.   ;button "refresh", 99, 0 60 48 10, flat
  70. }
  71.  
  72. dialog mtgoxticker_hz {
  73.   title "mt.gox live ticker"
  74.   size -1 -1 276 10
  75.   option dbu
  76.   text "AVG:" ,1, 2   1 12 8
  77.   edit ""     ,2, 16  0 30 10,read
  78.   text "LOW:" ,3, 48  1 14 8
  79.   edit ""     ,4, 64  0 30 10,read  
  80.   text "HIGH:",5, 96  1 14 8
  81.   edit ""     ,6, 112 0 30 10,read  
  82.   text "BID:" ,7, 144  1 12 8
  83.   edit ""     ,8, 156  0 30 10,read  
  84.   text "ASK:" ,9, 188  1 12 8
  85.   edit ""     ,10,200  0 30 10,read  
  86.   text "LAST:",11,232  1 14 8
  87.   edit ""     ,12,246  0 30 10,read  
  88.   ;button "refresh", 99,278  0 32 10, flat
  89. }
  90.  
  91. on *:dialog:mtgoxticker_vt:init:0:{
  92.   mtgoxupdate mtgoxticker_vt
  93.   if (%mtgoxoffline == 1) {
  94.     .timergoxvt -o 0 %mtgoxrefresh mtgoxupdate mtgoxticker_vt
  95.   }
  96.   else { .timergoxvt 0 %mtgoxrefresh mtgoxupdate mtgoxticker_vt }
  97. }
  98. ;on *:dialog:mtgoxticker_vt:sclick:99:{ mtgoxupdate mtgoxticker_vt }
  99. on *:dialog:mtgoxticker_vt:close:0:{ .timergoxvt off }
  100.  
  101. on *:dialog:mtgoxticker_hz:init:0:{
  102.   mtgoxupdate mtgoxticker_hz
  103.   if (%mtgoxoffline == 1) {
  104.     timergoxhz -o 0 %mtgoxrefresh mtgoxupdate mtgoxticker_hz
  105.   }
  106.   else { timergoxhz 0 %mtgoxrefresh mtgoxupdate mtgoxticker_hz }
  107. }
  108.  
  109. ;on *:dialog:mtgoxticker_hz:sclick:99:{ mtgoxupdate mtgoxticker_hz }
  110. on *:dialog:mtgoxticker_hz:close:0:{ .timergoxhz off }
  111.  
  112. on *:dialog:mtgoxconfig:init:0:{
  113.   did -arf mtgoxconfig 5 %mtgoxrefresh
  114.   did -ai mtgoxconfig 9 vertical
  115.   did -ai mtgoxconfig 9 horizontal
  116.  
  117.   if (%mtgoxvert == 1) { did -c mtgoxconfig 9 1 }
  118.   else { did -c mtgoxconfig 9 2 }
  119.   if (%mtgoxaot == 1) { did -c mtgoxconfig 1 }
  120.   if (%mtgoxoffline == 1) { did -c mtgoxconfig 3 }
  121.   if (%mtgoxdesktop == 1) { did -c mtgoxconfig 2 }
  122. }
  123.  
  124. on *:dialog:mtgoxconfig:sclick:1:{
  125.   if ($did(mtgoxconfig,1).state == 1) { set %mtgoxaot 1 }
  126.   else { set %mtgoxaot 0 }
  127. }
  128.  
  129. on *:dialog:mtgoxconfig:sclick:2:{
  130.   if ($did(mtgoxconfig,2).state == 1) { set %mtgoxdesktop 1 }
  131.   else { set %mtgoxdesktop 0 }
  132. }
  133.  
  134. on *:dialog:mtgoxconfig:sclick:3:{
  135.   if ($did(mtgoxconfig,3).state == 1) { set %mtgoxoffline 1 }
  136.   else { set %mtgoxoffline 0 }
  137. }
  138.  
  139. on *:dialog:mtgoxconfig:sclick:9:{
  140.   if ($did(mtgoxconfig,9) == vertical) { set %mtgoxvert 1 }
  141.   else { set %mtgoxvert 0 }
  142. }
  143. on *:dialog:mtgoxconfig:edit:5:{
  144.   set %mtgoxrefresh $did(mtgoxconfig,5)
  145. }
  146.  
  147. alias mtgoxticker {
  148.   var %params -mv
  149.   if (%mtgoxdesktop == 1) { %params = %params $+ d }
  150.   if (%mtgoxaot == 1) { %params = %params $+ o }
  151.  
  152.   if (%mtgoxvert == 1) {
  153.     dialog %params mtgoxticker_vt mtgoxticker_vt
  154.   }
  155.   else { dialog %params mtgoxticker_hz mtgoxticker_hz }
  156. }
  157.  
  158. alias mtgoxupdate {
  159.   .jsonclearcache %mtgoxurl
  160.   var %mtgoxavg $json(%mtgoxurl,ticker,avg)
  161.   var %mtgoxhigh $json(%mtgoxurl,ticker,high)
  162.   var %mtgoxlow $json(%mtgoxurl,ticker,low)
  163.   var %mtgoxbid $json(%mtgoxurl,ticker,buy)
  164.   var %mtgoxask $json(%mtgoxurl,ticker,sell)
  165.   var %mtgoxlast $json(%mtgoxurl,ticker,last)
  166.   did -ar $1 2 %mtgoxavg
  167.   did -ar $1 4 %mtgoxlow
  168.   did -ar $1 6 %mtgoxhigh
  169.   did -ar $1 8 %mtgoxbid
  170.   did -ar $1 10 %mtgoxask
  171.   did -ar $1 12 %mtgoxlast
  172. }
  173.  
  174. alias mtgoxsettings {
  175.   dialog -mov mtgoxconfig mtgoxconfig
  176. }
  177.  
  178. ;JSON implementation by Timi at http://timscripts.com/
  179.  
  180. alias json {
  181.   if ($isid) {
  182.     var %c = jsonidentifier,%x = 2,%str,%p,%v,%addr
  183.     if ($isfile($1)) { %addr = $qt($replace($1,\,\\,;,\u003b,",\u0022)) }
  184.     else { %addr = $qt($replace($1,;,\u003b,",\u0022)) }
  185.     json.comcheck
  186.     if (!$timer(jsonclearcache)) { .timerjsonclearcache -o 0 300 jsonclearcache }
  187.     while (%x <= $0) {
  188.       %p = $($+($,%x),2)
  189.       if (%p == $null) { noop }
  190.       elseif (%p isnum || $qt($noqt(%p)) == %p) { %str = $+(%str,[,%p,]) }
  191.       else { %str = $+(%str,[",%p,"]) }
  192.       inc %x
  193.     }
  194.     if ($prop == count) { %str = %str $+ .length }
  195.     if ($isfile($1)) {
  196.       if ($com(%c,eval,1,bstr,$+(str2json,$chr(40),filejson,$chr(40),%addr,$chr(41),$chr(41),%str))) { return $com(%c).result }
  197.     }
  198.     elseif (http://* iswm $1 || https://* iswm $1) {
  199.       if ($com(%c,eval,1,bstr,$+(str2json,$chr(40),urlcache[,%addr,],$chr(41),%str))) { return $com(%c).result }
  200.       elseif ($com(%c,eval,1,bstr,$+(urlcache[,%addr,]) = $+(httpjson,$chr(40),$qt($1),$chr(41)))) {
  201.         if ($com(%c,eval,1,bstr,$+(str2json,$chr(40),urlcache[,%addr,],$chr(41),%str))) { return $com(%c).result }
  202.       }
  203.     }
  204.     elseif ($com(%c,eval,1,bstr,$+(x=,%addr,;,x,%str,;))) { return $com(%c).result }
  205.   }
  206. }
  207.  
  208. alias jsonclearcache {
  209.   if ($com(jsonidentifier)) {
  210.     if (!$1) { noop $com(jsonidentifier,executestatement,1,bstr,urlcache = {}) }
  211.     else { echo -qg $com(jsonidentifier,executestatement,1,bstr,urlcache[" $+ $1 $+ "] = "") }
  212.   }
  213. }
  214.  
  215. alias -l json.comcheck {
  216.   var %c = jsonidentifier
  217.   if (!$com(%c)) {
  218.     .comopen %c MSScriptControl.ScriptControl
  219.     noop $com(%c,language,4,bstr,jscript) $com(%c,addcode,1,bstr,function httpjson(url) $({,0) y=new ActiveXObject("Microsoft.XMLHTTP");y.open("GET",url,false);y.send();return y.responseText; $(},0))
  220.     noop $com(%c,addcode,1,bstr,function filejson (file) $({,0) x = new ActiveXObject("Scripting.FileSystemObject"); txt1 = x.OpenTextFile(file,1); txt2 = txt1.ReadAll(); txt1.Close(); return txt2; $(},0))
  221.     noop $com(%c,addcode,1,bstr,function str2json (json) $({,0) return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(json.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + json + ')'); $(},0))
  222.     noop $com(%c,addcode,1,bstr,urlcache = {})
  223.   }
  224. }
Add Comment
Please, Sign In to add comment