PageSourceSearch

http://genuspaper.com/wp-content/plugins/live-stock-prices-for-wordpress/js/eod-stock-prices.js?ver=7.1.2

js genuspaper.com collected 2026-10-05 19:54:55 UTC 6,880 bytes, 194 lines download raw bytes

1let eod_api_token = '';
2jQuery(async function($){
3    eod_api_token = await $.ajax({
4        method: "POST",
5        url: eod_ajax_url,
6        data: {
7            'action': 'get_eod_token',
8            'nonce_code': eod_ajax_noncerr,
9        }
10    });
11    eod_display_all_live_tickers();
12    eod_display_all_historical_tickers();
13    eod_init_realtime_tickers()
14    
15    // Refresh tickers every minute. It will affect your daily API Limit!
16    const EOD_refresh_common_tickers = false,
17          EOD_refresh_interval = 60000;             // 60000 = 1 minute
18    if(EOD_refresh_common_tickers){
19        let EOD_refresh = setInterval(function () {
20            console.log("EOD_refresh_common_tickers");
21            eod_display_all_live_tickers();
22        }, EOD_refresh_interval);
23    }
24});
25
26function check_token_capability(target, callback){
27    $.ajax({
28        dataType: "json",
29        method: "POST",
30        url: eod_ajax_url,
31        data: {
32            'action': 'check_token_capability',
33            'nonce_code': eod_ajax_noncerr,
34            'target': target
35        }
36    }).always((data) => {})
37    .done((data) => {
38        let error = data.error ? data.error : false;
39        callback(error);
40    });
41}
42
43function get_eod_ticker(type = 'historical', list, callback){
44    if(typeof callback !== 'function' || !$.isArray(list) || list.length < 1) return false;
45
46    $.ajax({
47        dataType: "json",
48        method: "POST",
49        url: eod_ajax_url,
50        data: {
51            'action': 'get_real_time_ticker',
52            'nonce_code': eod_ajax_noncerr,
53            'list': list,
54            'type': type
55        }
56    }).always((data) => {})
57    .done((data) => { callback(data); });
58}
59
60function render_eod_ticker(type, target, value, prevValue = false){       
61    if(!target) return false;
62            
63    // The ticker can be without the other half.
64    let trg = target.toLowerCase().split('.'),
65        full_t_class = '.'+type+'.eod_t_'+trg.join('_'),     // AAPL.US
66        t_class = '.'+type+'.eod_t_'+trg[0];                 // AAPL
67    
68    // Display error
69    if(!value || value === 'NA'){
70        $(full_t_class+', '+t_class).text('no result from real time api').closest('.eod_ticker').addClass('error');
71        return false;
72    }
73   
74    // Close value
75    value = parseFloat(value).toFixed(4);
76    $(full_t_class+', '+t_class).text(value);
77    
78    // Evolution
79    if(!prevValue || value == '-') return false;
80    let evolution = parseFloat(value - prevValue).toFixed(2),
81        evol_html = '(<span role="value">'+(evolution > 0 ? '+' : '')+evolution+'</span>)';
82    $(full_t_class+' + [role=evolution], '+t_class+' + [role=evolution]').html(evol_html).closest('.eod_ticker')
83        .toggleClass('plus', evolution > 0)
84        .toggleClass('equal', evolution == 0)
85        .toggleClass('minus', evolution < 0);
86}
87
88
89/* =========================================
90     loading and displaying all live tickers
91   ========================================= */
92function eod_display_all_live_tickers(){
93    // Finding and prepare all tickers. Creating list.
94    let eod_t_list = [];
95
96    $(".eod_live").each(function(){
97        let target = $(this).attr('data-target');
98            
99        // Common ticker
100        if( eod_t_list.indexOf(target) === -1 )
101            eod_t_list.push(target);
102    });
103    
104    // Get and display close value
105    get_eod_ticker('live', eod_t_list, function(data){
106        if(!data || data.error) return false;
107        if(data.code){
108            render_eod_ticker('eod_live', data.code, data.close, data.previousClose);
109        }else if(data['0']){
110            for(const [key, item] of Object.entries(data)){
111                render_eod_ticker('eod_live', item.code, item.close, item.previousClose);
112            }
113        }
114    });
115}
116
117
118/* =========================================
119     loading and displaying all historical tickers
120   ========================================= */
121function eod_display_all_historical_tickers(){
122    // Finding and prepare all tickers. Creating list.
123    let eod_t_list = [];
124
125    $(".eod_historical").each(function(){
126        let target = $(this).attr('data-target');
127            
128        // Common ticker
129        if( eod_t_list.indexOf(target) === -1 )
130            eod_t_list.push(target);
131    });
132    
133    // Get and display close value
134    get_eod_ticker('historical', eod_t_list, function(data){
135        if(!data || data.error) return false;
136        if(data.code){
137            render_eod_ticker('eod_historical', data.code, data.close, data.previousClose);
138        }else if(data['0']){
139            for(const [key, item] of Object.entries(data)){
140                render_eod_ticker('eod_historical', item.code+'.'+item.exchange_short_name, item.close, item.prev_close);
141            }
142        }
143    });
144}
145
146/* =========================================
147     init display realtime tickers
148   ========================================= */
149function eod_init_realtime_tickers(){
150    // Finding and prepare all tickers. Creating list.
151    let eod_rt_list = {
152        'cc':     [],
153        'forex':  [],
154        'us':     []
155    };
156    $(".eod_realtime").each(function(){
157        let target = $(this).attr('data-target'),
158            [code, type] = target.toLowerCase().split('.');
159            
160        // Realtime ticker
161        if(type && eod_rt_list[type] && eod_rt_list[type].indexOf( code ) === -1)
162           eod_rt_list[type].push(code); 
163    });
164    
165    // Create websocket
166    const ws_eod = {
167        'cc':     new WebSocket('wss://ws.eodhistoricaldata.com/ws/crypto?api_token='+eod_api_token),
168        'forex':  new WebSocket('wss://ws.eodhistoricaldata.com/ws/forex?api_token='+eod_api_token),
169        'us':     new WebSocket('wss://ws.eodhistoricaldata.com/ws/us?api_token='+eod_api_token)
170    };
171    for(let type in eod_rt_list){
172        if(eod_rt_list[type].length){
173            ws_eod[type].addEventListener('open', function(event){
174                for(let q of eod_rt_list[type]){
175                    ws_eod[type].send('{"action": "subscribe", "symbols": "'+q.toUpperCase()+'"}');
176                }
177            });
178        }
179    }
180
181    ws_eod.cc.addEventListener('message', function(event){
182        let res = JSON.parse(event.data);
183        if(res.p) render_eod_ticker('eod_realtime', res.s+'.CC', res.p);
184    });
185    ws_eod.forex.addEventListener('message', function(event){
186        let res = JSON.parse(event.data);
187        if(res.a) render_eod_ticker('eod_realtime', res.s+'.FOREX', res.a);
188    });
189    ws_eod.us.addEventListener('message', function(event){
190        let res = JSON.parse(event.data);
191        if(res.p) render_eod_ticker('eod_realtime', res.s+'.US', res.p);
192    });
193}
194

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.