brighter-trading/static/data.js

56 lines
2.0 KiB
JavaScript

class Data {
constructor() {
// 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. Pass it
a list of callbacks to handle various incoming messages.*/
this.comms = new Comms(this.candle_update, this.candle_close, this.indicator_update);
// Open the connection to our local server.
this.comms.set_app_con();
/* Open connection for streaming candle data wth the exchange.
Pass it the time period of candles to stream. */
this.comms.set_exchange_con(this.interval);
//Request historical price data from the server.
this.price_history = this.comms.getPriceHistory();
// Request from the server initialization data for the indicators.
this.indicator_data = this.comms.getIndicatorData();
// 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:');
//console.log(new_candle);
}
set_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);
}
}