class Data { constructor() { // The user name this.user_name = bt_data.user_name; // The id's of the HTML elements that contain sections of the user interface. this.chart1_id = 'chart'; this.chart2_id = 'chart2'; this.chart3_id = 'chart3'; /* Set into memory configuration data from the server. */ // The assets being traded. this.trading_pair = bt_data.trading_pair; // The time period of the charts. this.interval = bt_data.interval; // All the indicators available. this.indicators = bt_data.indicators; /* Comms handles communication with the servers. Register callbacks to handle various incoming messages.*/ this.comms = new Comms(); this.comms.registerCallback('candle_update', this.candle_update) this.comms.registerCallback('candle_close', this.candle_close) this.comms.registerCallback('indicator_update', this.indicator_update) // Open the connection to our local server. this.comms.setAppCon(); /* Open connection for streaming candle data wth the exchange. Pass it the time period of candles to stream. */ this.comms.setExchangeCon(this.interval, this.trading_pair); //Request historical price data from the server. this.price_history = this.comms.getPriceHistory(this.user_name); //last price from price history. this.price_history.then((value) => { this.last_price = value[value.length-1].close; }); // Request from the server initialization data for the indicators. this.indicator_data = this.comms.getIndicatorData(this.user_name); // Call back for indicator updates. this.i_updates = null; } candle_update(new_candle){ // This is called everytime a candle update comes from the local server. window.UI.charts.update_main_chart(new_candle); //console.log('Candle update:'); this.last_price = new_candle.close; } registerCallback_i_updates(call_back){ this.i_updates = call_back; } indicator_update(data){ // This is called everytime an indicator update come in. window.UI.data.i_updates(data); } candle_close(new_candle){ // This is called everytime a candle closes. //console.log('Candle close:'); //console.log(new_candle); } }