def get_xxx_content(burl): """ Content of the page """ box_content = ''+\ '<div class="box-top">' +\ ' <div class="row">'+\ ' <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-center-content" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ '*** URL is '+ str(burl) +\ ' </div>'+\ ' </div>'+\ ' </div>'+\ '</div>' box_content = box_content +\ '<div class="box">' +\ ' <div class="row">'+\ ' <div class="col-lg-6 col-md-12 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-center-content" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ '*** URL is '+ str(burl) +\ ' </div>'+\ ' </div>'+\ ' <div class="col-lg-6 col-md-12 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-center-content" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ '*** URL is '+ str(burl) +\ ' </div>'+\ ' </div>'+\ ' </div>'+\ '</div>' return box_content
def get_sa_terminal_content(burl): """ Content of the page """ box_content = get_box_user_profile_header() box_content = box_content + '<div id="popup_notification"></div>' box_content = box_content +\ '<div class="box">' +\ ' <div class="row">'+\ ' <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-center-content" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:orange;') +'">'+\ get_terminal_desc(burl) +\ ' </div>'+\ ' </div>'+\ ' <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-center-content" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:black;') +'">'+\ '<img src="'+ burl+ 'static/saterminal.png?'+ get_random_str(9) +'" height="200" />'+\ ' </div>'+\ ' </div>'+\ ' </div>'+\ '</div>' box_content = box_content +\ '<div class="box">' +\ ' <div class="row">'+\ ' <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-center-content" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ get_settings_note(burl) +\ ' </div>'+\ ' </div>'+\ ' </div>'+\ '</div>' return box_content
def get_sa_terminal_help_content(burl): """ Content of the page """ box_content = ''+\ '<div class="box-top">' +\ ' <div class="row">'+\ ' <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-center-content" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ '<h4>Smartalpha Help and Support</h4>'+\ ' </div>'+\ ' </div>'+\ ' </div>'+\ '</div>' box_content = box_content +\ '<div class="box">' +\ ' <div class="row">'+\ ' <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-center-content" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ 'email: <a href="mailto:[email protected]">[email protected]</a><br />'+\ 'help and learning page: <a href="'+\ open_window_as(burl +'h/#', 1) +'"><HELP> <GO></a>'+\ ' </div>'+\ ' </div>'+\ ' </div>'+\ '</div>' return box_content
def get_gcharts_column(chart_id, data, data_label, data_color, data_annotation, title, legend_position, width, height): """ Draw column chart """ return_data = '' maxval = 0 minval = 0 maxval = max(data) if maxval > 0: maxval = maxval + (maxval / 10) else: maxval = 0 minval = min(data) if minval < 0: minval = minval + (minval / 10) else: minval = 0 return_data = ' '+\ '<script type="text/javascript">'+\ ' google.charts.load("current", {packages:["corechart"]});'+\ ' google.charts.setOnLoadCallback(drawChart);'+\ ' function drawChart() {'+\ ' var data = google.visualization.arrayToDataTable(['+\ ' ["label", "", { role: "style" }, {role: "annotation"} ],'+\ get_gcharts_column_data(data, data_label, data_color, data_annotation) +\ ' ]);'+\ ' var view = new google.visualization.DataView(data);'+\ ' var options = {'+\ ' title: "'+ str(title) +'",'+\ ' titleTextStyle: {color:"'+ theme_return_this('black', 'white') +'"},'+\ ' backgroundColor: "transparent",'+\ ' bar: {groupWidth: "90%"},'+\ ' legend: { position: "'+ str(legend_position) +'" },'+\ ' vAxis: {'+\ ' gridlines: {color: "transparent"},'+\ ' textStyle: {color: "'+ theme_return_this('black', 'white') +'"},'+\ ' viewWindow:{min:'+ str(minval) +',max:'+ str(maxval) +'},' +\ ' },'+\ ' hAxis: {'+\ ' gridlines: {color: "transparent"},'+\ ' textStyle: {color: "'+ theme_return_this('black', 'white') +'"},'+\ ' }'+\ ' };'+\ ' var chart = new google.visualization.ColumnChart(document.getElementById("'+\ str(chart_id) +'"));'+\ ' chart.draw(view, options);'+\ ' }'+\ '</script>'+\ '<div id="'+ str(chart_id) +'" style="width: '+\ str(width) +'; height: '+ str(height) +';"></div>' return return_data
def get_terminal_desc(burl): """ xxx """ ret = '' func_name = 'launchTerminal()' title = '<h3 style="'+ theme_return_this('', 'color:white;') +\ 'text-align: left;">Smartalpha Terminal</h3>' description = '<div style:"text-align:left;">Add panels, charts and functions with '+\ '<a href="'+\ burl +'search/#'+'"><strong><search></strong></a> on the top-left corner. '+\ 'Type <a href="'+\ burl +'h/#"><strong><HELP></strong> <strong><GO></strong></a> for Help. '+\ 'To run terminal, do no operate the browser in fullscreen mode. <strong>ALLOW popup and redirects.</strong>'+\ '</div><div> </div>' launch_btn = '<a href="javascript:'+\ func_name +\ ';" class="btn btn-primary btn-lg" style="font-size: large;">Launch Terminal</a>' btn_space = '<div> </div>' ret = ''+\ get_terminal_button_func(burl, func_name)+\ title +\ description +\ launch_btn +\ btn_space return ret
def get_resetpassword_email_input(burl): """ xxx """ box_content = '' l_reset_password = '******' l_email_placeholder = 'Enter your email' l_btn_label = 'Reset Password' box_content = ' '+\ '<div class="box-top">' +\ ' <div class="row">'+\ ' <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-center-content" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ ' <span class="sectiont">'+\ l_reset_password +'</span>'+\ ' <form action="'+\ burl+'reset/?step=2" method="post" '+\ 'style="width: 100%; max-width: 600px; padding: 2%; margin: auto;">'+\ ' <input type="text" id="data" name="data" '+\ 'class="form-control" aria-label="Large" '+\ 'aria-describedby="inputGroup-sizing-sm" placeholder="'+\ l_email_placeholder +'" required>'+\ ' <button type="submit" '+\ 'class="btn btn-info btn-lg btn-block form-resetpassword-btn">' +\ l_btn_label + ' <i class="fas fa-arrow-right"></i></button>'+\ ' </form>'+\ ' </div>'+\ ' </div>'+\ ' </div>'+\ '</div>' return box_content
def get_box_risk_content(uid): """ xxx """ box_content = '' lang = get_selected_lang() connection = pymysql.connect(host=DB_SRV, user=DB_USR, password=DB_PWD, db=DB_NAME, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = connection.cursor(pymysql.cursors.SSCursor) sql = "SELECT portf_risk_consider FROM `recommendations` WHERE lang='" + lang + "' " cursor.execute(sql) res = cursor.fetchall() text_content = '' for row in res: text_content = row[0] sql = "SELECT instruments.account_reference, instruments.unit, "+\ "instruments.beta_st, instruments.alpha_st, instruments.stdev_st, "+\ "instruments.sharpe_ratio_st, "+\ "instruments.maximum_dd_st, instruments.romad_st, instruments.volatility_risk_st " +\ "FROM instruments "+\ "JOIN symbol_list ON symbol_list.symbol = instruments.symbol "+\ "WHERE symbol_list.uid=" + str(uid) cursor.execute(sql) res = cursor.fetchall() account_reference = 0 unit = '' stdev_st = 0 volatility_risk_st = 0 for row in res: account_reference = row[0] unit = row[1] stdev_st = row[4] volatility_risk_st = row[8] cursor.close() connection.close() dollar_amount = round(stdev_st, 2) percentage = round(volatility_risk_st * 100, 2) text_content = text_content.replace('{account_reference}', str(int(account_reference))) text_content = text_content.replace('{unit}', str(unit)) text_content = text_content.replace('{dollar_amount}', str(dollar_amount)) text_content = text_content.replace('{percentage}', str(percentage) + "%") l_title = 'Risk considerations' box_content = '' +\ ' <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-signal-recomm-trail-ret" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ ' <div><h6>'+ l_title +'</h6></div>'+\ ' <div>'+ text_content +'</div>'+\ '<div>'+ get_risk_table(uid) +'</div>'+\ ' </div>'+\ ' </div>' return box_content
def get_chart_box(uid): """ xxx """ chart_1y_perf = get_perf_chart(uid) tab_1_label = 'Performance' tab_1_link = '#perf' tab_1_id = tab_1_link.replace('#', '') return_data = '' +\ ' <div class="col-lg-8 col-md-8 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-portf-perf-portf-chart">'+\ ' <ul id="sa-tab-sm" class="nav nav-tabs" role="tablist">'+\ ' <li class="nav-item">'+\ ' <a class="nav-link active" '+\ 'data-toggle="pill" href="'+\ tab_1_link +'">'+\ tab_1_label +'</a>'+\ ' </li>'+\ ' </ul>'+\ ' <div class="tab-content">'+\ ' <div id="'+\ tab_1_id +'" class="tab-pane active" style="height: 325px; '+\ theme_return_this('', 'background-color: #20124d;') +'" ><br />'+\ chart_1y_perf +'</div>'+\ ' </div>'+\ ' </div>'+\ ' </div>' #To disable tab: remove the data-toggle="pill" return return_data
def get_box_trail_returns_content(uid): """ xxx """ box_content = '' connection = pymysql.connect(host=DB_SRV, user=DB_USR, password=DB_PWD, db=DB_NAME, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = connection.cursor(pymysql.cursors.SSCursor) sql = "SELECT instruments.fullname FROM instruments "+\ "JOIN symbol_list ON symbol_list.symbol = instruments.symbol "+\ "WHERE symbol_list.uid=" + str(uid) cursor.execute(sql) res = cursor.fetchall() for row in res: fullname = row[0] l_title = fullname + ' portfolio trailing returns' box_content = '' +\ ' <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-signal-recomm-trail-ret" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ ' <div><h6>'+ l_title +'</h6></div>'+\ get_trailing_returns(uid) +\ ' </div>'+\ ' </div>' cursor.close() connection.close() return box_content
def get_profile_content(uid, burl, terminal): """ Content of the page """ box_content = ''+\ '<div class="box-top">' +\ ' <div class="row">'+\ get_details_header(uid, burl)+\ get_sign_header(uid, burl, terminal)+\ ' <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-center-content">'+\ get_tab_component(uid, burl)+\ ' </div>'+\ ' </div>'+\ ' </div>'+\ '</div>' """ Content start here """ """""" """""" """""" """""" "" box_content = box_content +\ '<div class="box">' +\ ' <div class="row">'+\ ' <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-center-content" style="'+\ 'height: 400px; '+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ get_tradingview_profile(uid)+\ ' </div>'+\ ' </div>'+\ ' </div>'+\ ' <div class="row">'+\ ' <div class="col-lg-6 col-md-12 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-center-content" style="'+\ 'height: 350px; '+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ get_tradingview_chartoverview(uid)+\ ' </div>'+\ ' </div>'+\ get_chart_box(uid)+\ ' </div>'+\ '</div>' return box_content
def get_box_search(burl, nonavbar, terminal): """ xxx """ box_content = '' col_id = 0 sid = get_random_str(9) nonavbarparam = '<input type="hidden" name="nonavbar" value="1">' if nonavbar is None: nonavbarparam = '' l_placeholder = "Enter function, ticker or search. Hit <enter> to go." search_box = ' '+\ ' <form class="" action="'+ burl +'" method="get" id="searchForm" name="searchForm" >'+\ '<div class="sa-cursor">'+\ '<input type="search" id="filterInput" name="'+\ str(sid) +'" onkeyup="filterTable(); this.value = this.value.toUpperCase();" '+\ 'class="form-control" aria-label="Large" '+\ 'aria-describedby="inputGroup-sizing-sm" placeholder="'+\ l_placeholder +'" style="background: transparent;'+\ theme_return_this('', 'color: white;') +'" autofocus>'+\ '<i></i>'+\ '</div><div> '+\ ' </div>'+\ ' <input type="hidden" name="sid" value="'+ str(sid) +'">'+\ nonavbarparam +\ ' </form>' box_content = '' +\ '<script>'+\ 'function filterTable() {'+\ ' var input, filter, table, tr, td, i, txtValue;'+\ ' input = document.getElementById("filterInput");'+\ ' filter = input.value.toUpperCase();'+\ ' table = document.getElementById("table_search");'+\ ' tr = table.getElementsByTagName("tr");'+\ ' for (i = 0; i < tr.length; i++) {'+\ ' td = tr[i].getElementsByTagName("td")['+ str(col_id) +'];'+\ ' if (td) {'+\ ' txtValue = td.textContent || td.innerText;'+\ ' if (txtValue.toUpperCase().indexOf(filter) > -1) {'+\ ' tr[i].style.display = "";'+\ ' } else {'+\ ' tr[i].style.display = "none";'+\ ' }'+\ ' }'+\ ' }'+\ '}'+\ '</script>' box_content = box_content +\ search_box +\ gen_search_table(burl, nonavbar, terminal) return box_content
def get_recomm_layout(uid): """ xxx """ return_data = '' l_title = 'Technical Recommendation' return_data = '' +\ ' <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-signal-recomm-trail-ret" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ ' <div><h6>'+ l_title +'</h6></div>'+\ ' <div>'+ get_recomm(uid) +'</div>'+\ ' </div>'+\ ' </div>' return return_data
def get_aggregate_perf(): """ xxx """ box_content = '' l_title_aggregate_perf = 'Your Performance' box_content = '' +\ ' <div class="box-part rounded" style="height: 300px;'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'" >'+\ ' <span class="sectiont"><i class="fas fa-chart-area"></i> '+\ l_title_aggregate_perf +'</span>'+\ gen_aggregate_perf_graph() +\ ' </div>' return box_content
def get_search_table_content(burl, nonavbar, terminal): """ xxx """ return_data = '' nonavbarparam = '&nonavbar=1' if nonavbar is None: nonavbarparam = '' return_data = ' '+\ '<script>$(document).ready(function($) {'+\ '$(".sa-table-click-row").click(function() {'+\ 'window.document.location = $(this).data("href");'+\ '});'+\ '});</script>' connection = pymysql.connect(host=DB_SRV, user=DB_USR, password=DB_PWD, db=DB_NAME, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = connection.cursor(pymysql.cursors.SSCursor) sql = 'SELECT feed.search, feed.content, markets.market_label, feed.url, '+\ 'feed.type FROM feed LEFT JOIN markets ON markets.market_id = feed.market '+\ 'WHERE (feed.type<>9 AND feed.type<>3) ORDER BY feed.symbol' cursor.execute(sql) res = cursor.fetchall() for row in res: search_text = row[0] content_details = row[1] scope_text = row[2] url = format_url(row[3].replace('{burl}', burl), burl, nonavbarparam, terminal) feed_type = row[4] textcolor = '' if feed_type == 2: textcolor = theme_return_this('blue', '#5bc0de') return_data = return_data +\ '<tr class="sa-table-click-row" data-href="'+ str(url) +'">'+\ ' <td style="text-align: left; color:' +\ textcolor + ';" scope="row"><strong>'+ str(search_text) +'</strong></td>'+\ ' <td style="text-align: left; color:' +\ textcolor + ';">'+ str(content_details) +'</td>'+\ ' <td style="text-align: left; color:' +\ textcolor + ';">'+ str(scope_text) +'</td>'+\ '</tr>' cursor.close() connection.close() return return_data
def get_list_articles(burl, max_list, section_header, category): """ section_header = title of the section. category = category of document to display. """ ret = '' doc_cat = category title = '' uid = 0 l_latest_articles = section_header ret = '<span class="sectiont"><i class="fas fa-file-alt"></i> '+\ l_latest_articles +'</span>' connection = pymysql.connect(host=DB_SRV, user=DB_USR, password=DB_PWD, db=DB_NAME, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = connection.cursor(pymysql.cursors.SSCursor) sql = 'SELECT uid, title, '+\ '(SELECT ROUND((UNIX_TIMESTAMP() - UNIX_TIMESTAMP(date)) / 60) ) AS elapsed_time '+\ 'FROM documents WHERE category LIKE "%'+ str(doc_cat) +'%" '+\ 'ORDER BY date DESC LIMIT ' + str(max_list) cursor.execute(sql) res = cursor.fetchall() for row in res: uid = row[0] title = row[1] article_date = '' if category == 'article': article_date = get_elapsed_time(row[2]) ret = ret +\ '<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" '+\ 'style="border-top:0.5px; border-top-style: dotted; text-align: left;">'+\ '<i class="fas fa-file-alt"></i> '+\ ' '+\ '<strong>'+\ '<a href="'+ str(burl) +'doc/?uid='+ str(uid) +'" target="_blank">'+\ '<span style="'+\ theme_return_this('color:black;', 'color:#00ffff;') +' ">'+\ str(article_date) +'</span> '+\ str(title) +'</a>'+\ '</strong>'+\ '</div>' cursor.close() connection.close() return ret
def get_search_page_content(burl, nonavbar, terminal): """ xxx """ box_content = '' box_class = 'box' if nonavbar is None: box_class = 'box-top' box_content = ' ' +\ '<div class="'+ box_class +'">' +\ ' <div class="row">'+\ ' <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-center-content" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ get_box_search(burl, nonavbar, terminal) +\ ' </div>'+\ ' </div>'+\ ' </div>'+\ '</div>' return box_content
def set_new_password(burl, data, data2): """ xxx """ box_content = '' message_content = '<a href="'+\ burl +'logout/?resetpassword">Your password has been changed.</a>' new_password = get_hash_string(str(data)) user_uid = str(data2) user_new_uid = str(get_random_str(99)) connection = pymysql.connect(host=DB_SRV, user=DB_USR, password=DB_PWD, db=DB_NAME, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = connection.cursor(pymysql.cursors.SSCursor) sql = 'UPDATE Users SET password = "******" WHERE uid="' + str( user_uid) + '" ' cursor.execute(sql) sql = 'UPDATE Users SET uid ="' + str( user_new_uid) + '" WHERE uid="' + str(user_uid) + '" ' cursor.execute(sql) connection.commit() cursor.close() connection.close() box_content = ' '+\ '<div class="box-top">' +\ ' <div class="row">'+\ ' <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-center-content" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ ' <div class="alert alert-info" role="alert">'+\ message_content +'</div>'+\ ' </div>'+\ ' </div>'+\ ' </div>'+\ '</div>' return box_content
def write_func(uid, data, color, minval): """ Draw chart within the card """ funct = ""+\ "<script>"+\ "google.charts.load('current', {packages: ['corechart', 'line']});"+\ "google.charts.setOnLoadCallback(drawChart_"+str(uid)+");"+\ "function drawChart_"+str(uid)+"() {"+\ " var data = new google.visualization.DataTable();"+\ " data.addColumn('date', 'date');"+\ " data.addColumn('number', 'price');"+\ " data.addRows(["+data+"]);"+\ " var options = {"+\ " chartArea:{right: '0', width:'90%',height:'80%' },"+\ " hAxis: {"+\ " textPosition: 'none',"+\ " title: '',"+\ " gridlines: {"+\ " color: 'transparent'"+\ " }"+\ " },"+\ " vAxis: {"+\ " viewWindow:{min:"+ str(minval) +", viewWindowMode: 'explicit'}, "+\ " title: '',"+\ " textStyle: { color:'"+ theme_return_this("#343a40", "#ffffff") +"'},"+\ " gridlines: {"+\ " color: 'transparent'"+\ " }"+\ " },"+\ " colors: ['"+str(color)+"'],"+\ " legend: {position: 'none'},"+\ " lineWidth: 1,"+\ " backgroundColor: 'transparent'"+\ " };"+\ " var chart = new google.visualization.AreaChart(document.getElementById('chart_div_"+\ str(uid)+"'));"+\ " chart.draw(data, options);"+\ " }"+\ " </script>" return funct
def get_portf_alloc(uid, burl): """ xxx """ signal_box = '' pie_chart = '' connection = pymysql.connect(host=DB_SRV, user=DB_USR, password=DB_PWD, db=DB_NAME, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = connection.cursor(pymysql.cursors.SSCursor) sql = "SELECT portfolios.order_type, portfolios.quantity, "+\ "portfolios.symbol, portfolios.entry_level, "+\ "portfolios.expiration, portfolios.alloc_fullname, "+\ "portfolios.strategy_order_type FROM portfolios "+\ "JOIN symbol_list ON symbol_list.symbol = portfolios.portf_symbol "+\ "WHERE symbol_list.uid="+\ str(uid) +" ORDER BY portfolios.symbol" cursor.execute(sql) res = cursor.fetchall() signal_box_data = '' for row in res: order_type = row[0] quantity = row[1] symbol = row[2] entry_price = row[3] trade_expiration = row[4] exp_date_str = trade_expiration.strftime("%d-%b-%Y") symbol_fullname = row[5] strategy_order_type = row[6] cr_s = connection.cursor(pymysql.cursors.SSCursor) sql_s = "SELECT uid FROM symbol_list WHERE symbol = '" + symbol + "'" cr_s.execute(sql_s) rs_s = cr_s.fetchall() for row in rs_s: symbol_uid = row[0] if order_type == 'buy': badge = 'badge-success' else: badge = 'badge-danger' if ((order_type == 'buy' and strategy_order_type == 'short') or\ (order_type == 'sell' and strategy_order_type == 'long')): order_type = 'wait' badge = 'badge-secondary' entry_price = '-' quantity = '-' signal_box_data = signal_box_data + '' +\ ' <tr>'+\ ' <th scope="row"><span class="badge '+\ badge +'">'+\ order_type +'</span></th>'+\ ' <td>'+\ str(quantity) +'</td>'+\ ' <td><a href="'+\ burl +'s/?uid='+\ str(symbol_uid) +'">'+\ symbol_fullname +'</a></td>'+\ ' <td>'+ str(entry_price) +'</td>'+\ ' <td>'+ exp_date_str +'</td>'+\ ' </tr>' cr_s.close() cursor.close() connection.close() signal_box = '' +\ ' <div class="col-lg-7 col-md-7 col-sm-6 col-xs-12">'+\ ' <div class="box-part rounded sa-portf-alloc" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ ' <table class="table table-hover table-sm sa-table-sm">'+\ ' <thead>'+\ ' <tr>'+\ ' <th scope="col">Order</th>'+\ ' <th scope="col">Quantity</th>'+\ ' <th scope="col">Trade</th>'+\ ' <th scope="col">Entry @</th>'+\ ' <th scope="col">Expires on</th>'+\ ' </tr>'+\ ' </thead>'+\ ' <tbody>' signal_box = signal_box + signal_box_data signal_box = signal_box + '' +\ ' </tbody>'+\ ' </table>'+\ ' </div>'+\ ' </div>' connection = pymysql.connect(host=DB_SRV, user=DB_USR, password=DB_PWD, db=DB_NAME, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = connection.cursor(pymysql.cursors.SSCursor) sql = "SELECT count(1) FROM portfolios "+\ "JOIN symbol_list ON portfolios.portf_symbol = symbol_list.symbol "+\ "WHERE symbol_list.uid=" +\ str(uid) cursor.execute(sql) res = cursor.fetchall() num_rec = 0 for row in res: num_rec = row[0] if num_rec != 0: num_rec = round(255 / num_rec, 0) connection = pymysql.connect(host=DB_SRV, user=DB_USR, password=DB_PWD, db=DB_NAME, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = connection.cursor(pymysql.cursors.SSCursor) sql = "SELECT portfolios.alloc_fullname, portfolios.order_type, "+\ "portfolios.dollar_amount, portfolios.symbol, "+\ "portfolios.strategy_order_type "+\ "FROM `portfolios` JOIN symbol_list ON "+\ "portfolios.portf_symbol = symbol_list.symbol "+\ "WHERE symbol_list.uid=" + str(uid) + " "+\ "ORDER BY portfolios.dollar_amount" cursor.execute(sql) res = cursor.fetchall() pie_chart_data = '' pie_chart_option = '' i = 0 count_buy = 0 count_sell = 0 count_wait = 0 sell_color_r = 255 sell_color_g = 0 sell_color_b = 0 buy_color_r = 198 buy_color_g = 255 buy_color_b = 0 wait_color_r = 220 wait_color_g = 220 wait_color_b = 220 for row in res: alloc_fullname = row[0] order_type = row[1] dollar_amount = row[2] alloc_symbol = row[3] strategy_order_type = row[4] if ((order_type == 'buy' and strategy_order_type == 'short') or\ (order_type == 'sell' and strategy_order_type == 'long')): order_type = 'wait' if i == 0: pie_chart_data = '["'+\ alloc_fullname +' ('+\ alloc_symbol +')'+'", '+\ str(dollar_amount) +']' else: pie_chart_data = pie_chart_data + ', ' + '["'+\ alloc_fullname + ' ('+\ alloc_symbol +')' +'", '+\ str(dollar_amount) +']' if order_type == 'buy': if count_buy > 0: if buy_color_b > num_rec: buy_color_r = buy_color_r - num_rec if buy_color_b < (255): buy_color_b = buy_color_b + num_rec count_buy += 1 if i == 0: pie_chart_option = str(i) +\ ':{color:"rgb('+\ str(int(buy_color_r)) +','+\ str(int(buy_color_g)) +','+\ str(int(buy_color_b)) +')"}' else: pie_chart_option = pie_chart_option + ', '+\ str(i) +':{color:"rgb('+\ str(int(buy_color_r)) +','+\ str(int(buy_color_g)) +','+\ str(int(buy_color_b)) +')"}' if order_type == 'sell': if count_sell > 0: if sell_color_b > num_rec: sell_color_r = sell_color_r - num_rec if sell_color_g < (255): sell_color_g = sell_color_g + num_rec if sell_color_b < (255): sell_color_b = sell_color_b + num_rec count_sell += 1 if i == 0: pie_chart_option = str(i) +':{color:"rgb('+\ str(int(sell_color_r)) +','+\ str(int(sell_color_g)) +','+\ str(int(sell_color_b)) +')"}' else: pie_chart_option = pie_chart_option + ', '+\ str(i) +':{color:"rgb('+\ str(int(sell_color_r)) +','+\ str(int(sell_color_g)) +','+\ str(int(sell_color_b)) +')"}' if order_type == 'wait': count_wait += 1 if i == 0: pie_chart_option = str(i) +':{color:"rgb('+\ str(int(wait_color_r)) +','+\ str(int(wait_color_g)) +','+\ str(int(wait_color_b)) +')"}' else: pie_chart_option = pie_chart_option + ', '+\ str(i) +':{color:"rgb('+\ str(int(wait_color_r)) +','+\ str(int(wait_color_g)) +','+\ str(int(wait_color_b)) +')"}' i += 1 cursor.close() connection.close() pie_chart_title = 'Portfolio Allocation' pie_chart_x = "Allocation" pie_chart_y = "Dollar Amount" pie_chart_font_size = 10 pie_chart = '' +\ ' <div class="col-lg-5 col-md-5 col-sm-6 col-xs-12">'+\ ' <div class="box-part rounded sa-portf-alloc" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ ' <script type="text/javascript">'+\ ' google.charts.load("current", {packages:["corechart"]});'+\ ' google.charts.setOnLoadCallback(drawChart);'+\ ' function drawChart() {'+\ ' var data = google.visualization.arrayToDataTable(['+\ ' ["'+ pie_chart_x +'", "'+ pie_chart_y +'"],' pie_chart = pie_chart + pie_chart_data pie_chart = pie_chart + '' +\ ' ]);'+\ ' var options = {'+\ ' title: "'+ pie_chart_title +'",'+\ ' titleTextStyle:{color:'+\ theme_return_this('"black"', '"white"') +'},'+\ ' pieHole: 0.2,'+\ ' legend: {position:"none", textStyle:{color:'+\ theme_return_this('"black"', '"white"') +'} },'+\ ' backgroundColor: "transparent",'+\ ' pieSliceText: "percentage",'+\ ' slices: {' + pie_chart_option + '},'+\ ' legend: {position:"labeled", textStyle: {fontSize: '+\ str(pie_chart_font_size) +', color:'+ theme_return_this('"black"', '"white"') +'} },'+\ ' chartArea:{width:"90%",height:"80%"}'+\ ' };'+\ ' var chart = '+\ 'new google.visualization.PieChart(document.getElementById("portf_alloc_pie_chart"));'+\ ' chart.draw(data, options);'+\ ' }'+\ ' </script>'+\ ' <div id="portf_alloc_pie_chart" class="sa-chart-hw-90"></div>'+\ ' </div>'+\ ' </div>' return signal_box + pie_chart
def get_perf_chart(uid): """ xxx """ l_indexing_in_progress_note = 'Indexing in progress. Data will be available in 10 minutes...' connection = pymysql.connect(host=DB_SRV, user=DB_USR, password=DB_PWD, db=DB_NAME, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = connection.cursor(pymysql.cursors.SSCursor) sql = "SELECT price_close FROM chart_data WHERE uid="+\ str(uid) + " ORDER BY price_close LIMIT 1" cursor.execute(sql) res = cursor.fetchall() minval = -9999 for row in res: minval = row[0] sql = "SELECT chart_data.symbol, chart_data.date, "+\ "chart_data.price_close, instruments.fullname, instruments.unit, "+\ "instruments.account_reference FROM chart_data "+\ "JOIN instruments ON chart_data.symbol = instruments.symbol "+\ "WHERE chart_data.uid=" + str(uid) + " ORDER BY chart_data.date" cursor.execute(sql) res = cursor.fetchall() data = "" price_close = 0 portf_unit = '' for row in res: chart_date = row[1] price_close = row[2] portf_unit = row[4] year = chart_date.strftime("%Y") month = chart_date.strftime("%m") day = chart_date.strftime("%d") if data == "": data = data +\ "[new Date("+\ str(year)+", "+\ str(int(month)-1)+", "+\ str(day)+"),"+str(price_close)+"]" else: data = data +\ ",[new Date("+\ str(year)+", "+\ str(int(month)-1)+", "+\ str(day)+"),"+ str(price_close)+"]" chart_title = "Portfolio 1-Year Performance" haxis = "Date" vaxis = "Price (" + portf_unit + ")" portf_perf_font_size = 10 if minval != -9999: portf_perf_box = '' +\ ' <script>'+\ ' google.charts.load("current", {"packages":["corechart"]});'+\ ' google.charts.setOnLoadCallback(drawChart);'+\ ' function drawChart() {'+\ ' var data = new google.visualization.DataTable();'+\ ' data.addColumn("date", "'+ haxis +'");'+\ ' data.addColumn("number", "'+ vaxis +'");'+\ ' data.addRows(['+data+']);'+\ ' var options = {'+\ ' title: "'+ chart_title +'", '+\ ' titleTextStyle: {color: '+\ theme_return_this('"black"', '"white"') +'},'+\ ' fontSize:'+\ str(portf_perf_font_size) + ', '+\ ' legend: {position: "none", textStyle: {color: '+\ theme_return_this('"black"', '"white"') +'} },'+\ ' backgroundColor: "transparent",'+\ ' vAxis: {viewWindow:{min: '+\ str(minval) +', viewWindowMode: "explicit"}, gridlines: { color: "transparent" }'+\ theme_return_this('', ', textStyle: {color: "white"}') +' },'+\ ' hAxis: { gridlines: { count: 4, color: "transparent" } '+\ theme_return_this('', ', textStyle: {color: "white"}') +' }, '+\ ' series:{0: {areaOpacity: 0.3, color: '+\ theme_return_this('"#17a2b8"', '"#ffffff"') +', lineWidth: 2} },'+\ ' chartArea:{width:"90%",height:"80%"}'+\ ' };'+\ ' var chart = '+\ 'new google.visualization.AreaChart(document.getElementById("portf_perf_chart"));'+\ ' chart.draw(data, options);'+\ ' }'+\ ' </script>'+\ ' <div id="portf_perf_chart" class="sa-chart-hw-90"></div>' else: portf_perf_box = ''+\ '<div class="alert alert-info" role="alert">'+\ l_indexing_in_progress_note +\ '</div>' cursor.close() connection.close() return portf_perf_box
def get_trailing_returns(uid): """ Get trailing return chart """ connection = pymysql.connect(host=DB_SRV, user=DB_USR, password=DB_PWD, db=DB_NAME, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = connection.cursor(pymysql.cursors.SSCursor) sql = "SELECT instruments.fullname, instruments.is_benchmark, "+\ "instruments.market, instruments.symbol, instruments.asset_class "+\ "FROM instruments JOIN symbol_list ON symbol_list.symbol = instruments.symbol "+\ "WHERE symbol_list.uid=" + str(uid) cursor.execute(sql) res = cursor.fetchall() for row in res: fullname = row[0].replace("'", "") is_benchmark = row[1] market = row[2] symbol_is_portf = row[3] asset_class = row[4] if symbol_is_portf.find(get_portf_suffix()) > -1: sql = "SELECT date FROM chart_data WHERE uid=" + str(uid) + " ORDER BY date DESC LIMIT 1" else: sql = "SELECT price_instruments_data.date FROM price_instruments_data JOIN symbol_list "+\ "ON symbol_list.symbol = price_instruments_data.symbol "+\ "WHERE symbol_list.uid=" + str(uid) +" ORDER BY date DESC LIMIT 1" cursor.execute(sql) res = cursor.fetchall() as_date = '' l_as_date = '' for row in res: as_date = row[0] if as_date != '': l_as_date = 'Trailing returns as of '+ as_date.strftime("%d-%b-%Y") font_size = 10 l_y1 = '1-Year' l_m6 = '6-month' l_m3 = '3-month' l_m1 = '1-month' l_w1 = '1-week' minb = 0 mini = 0 maxb = 0 maxi = 0 benchmark_header = '' benchmark_data_y1 = '' benchmark_data_m6 = '' benchmark_data_m3 = '' benchmark_data_m1 = '' benchmark_data_w1 = '' if not is_benchmark: sql = "SELECT symbol_list.uid, instruments.fullname "+\ "FROM symbol_list JOIN instruments "+\ "ON symbol_list.symbol = instruments.symbol "+\ "WHERE instruments.market='"+\ str(market) +"' AND instruments.asset_class='"+\ str(asset_class) +"' AND instruments.is_benchmark=1" cursor.execute(sql) res = cursor.fetchall() benchmark_uid = 0 for row in res: benchmark_uid = row[0] benchmark_fullname = row[1].replace("'", "") if benchmark_uid != 0: benchmark_header = ", ' " +\ benchmark_fullname +\ " ', {type: 'string', role: 'annotation'}" benchmark_data_y1 = ','+ get_chart_data(benchmark_uid, 'y1') benchmark_data_m6 = ','+ get_chart_data(benchmark_uid, 'm6') benchmark_data_m3 = ','+ get_chart_data(benchmark_uid, 'm3') benchmark_data_m1 = ','+ get_chart_data(benchmark_uid, 'm1') benchmark_data_w1 = ','+ get_chart_data(benchmark_uid, 'w1') minb = get_minmax(benchmark_uid, 'min') maxb = get_minmax(benchmark_uid, 'max') data = ''+\ '["'+ l_y1 + '",' + get_chart_data(uid, 'y1') + benchmark_data_y1 +']' + ',' +\ '["'+ l_m6 + '",' + get_chart_data(uid, 'm6') + benchmark_data_m6 + ']' + ',' +\ '["'+ l_m3 + '",' + get_chart_data(uid, 'm3') + benchmark_data_m3 + ']' + ',' +\ '["'+ l_m1 + '",' + get_chart_data(uid, 'm1') + benchmark_data_m1 + ']' + ',' +\ '["'+ l_w1 + '",' + get_chart_data(uid, 'w1') + benchmark_data_w1 + ']' mini = get_minmax(uid, 'min') maxi = get_minmax(uid, 'max') if minb < mini: mini = minb if maxb > maxi: maxi = maxb header = " ['x', ' " +\ fullname + " ', {type: 'string', role: 'annotation'}"+\ benchmark_header +" ]," chart_content = "" +\ "<script>" +\ "google.charts.load('current', {packages: ['corechart', 'bar']});" +\ "google.charts.setOnLoadCallback(drawAnnotations);" +\ "function drawAnnotations() {" +\ " var data = google.visualization.arrayToDataTable([" +\ header +\ data +\ " ]);" +\ " var options = {" +\ " fontSize: "+ str(font_size) + "," +\ " legend: {position:'top', textStyle: {color:"+\ theme_return_this("'black'", "'white'") +"} }," +\ " title: ''," +\ " backgroundColor: 'transparent',"+\ " chartArea: {width: '50%'}," +\ " annotations: {" +\ " alwaysOutside: true," +\ " textStyle: {" +\ " auraColor: 'none'," +\ " color: '#555'" +\ " }," +\ " boxStyle: {" +\ " stroke: '#ccc'," +\ " strokeWidth: 1," +\ " gradient: {" +\ " color1: 'yellow'," +\ " color2: 'white'," +\ " x1: '0%', y1: '0%'," +\ " x2: '100%', y2: '100%'" +\ " }" +\ " }" +\ " }," +\ " series: {0:{color: "+\ theme_return_this("'blue'", "'orange'") +"}, 1:{color: '#c9d6ea'} }," +\ " chartArea: {width:'80%',height:'80%'}," +\ " hAxis: {" +\ " title: '" + l_as_date + "', " +\ " titleTextStyle:{ color:"+\ theme_return_this("'black'", "'white'") +"},"+\ " viewWindow:{min:"+\ str(mini) +",max:"+\ str(maxi) +"}," +\ " gridlines: { color: 'transparent' },"+\ " textStyle: { color: "+\ theme_return_this("'black'", "'white'") +" } "+\ " }," +\ " vAxis: {" +\ " title: '', " +\ " textStyle: { color: "+\ theme_return_this("'black'", "'white'") +" } "+\ " }" +\ " };" +\ " var chart = "+\ "new google.visualization.BarChart(document.getElementById('trail_chart'));" +\ " chart.draw(data, options);" +\ " }" +\ " </script>" +\ " <div id='trail_chart' class='sa-chart-hw-290'></div>" cursor.close() connection.close() return chart_content
def get_details_header(uid, burl): """ xxx """ connection = pymysql.connect(host=DB_SRV, user=DB_USR, password=DB_PWD, db=DB_NAME, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cr_s = connection.cursor(pymysql.cursors.SSCursor) sql_s = "SELECT symbol_list.symbol, feed.short_title, "+\ "feed.content, feed.badge, feed.asset_class, feed.market, symbol_list.isin "+\ "FROM symbol_list "+\ "JOIN feed ON symbol_list.symbol = feed.symbol WHERE symbol_list.uid =" +\ str(uid) + " LIMIT 1" cr_s.execute(sql_s) rs_s = cr_s.fetchall() for row in rs_s: symbol = row[0] instr_name = row[1] content = row[2].replace('{burl}', burl) badge = row[3] asset_class = row[4] market = row[5] isin = row[6] if len(isin) > 1: isin = ' | ISIN: '+ str(isin) else: isin = '' if (badge.find('-0') == -1 and badge.find('-1') == -1 and badge.find('-2') == -1 and badge.find('-3') == -1 and badge.find('-4') == -1 and badge.find('-5') == -1 and badge.find('-6') == -1 and badge.find('-7') == -1 and badge.find('-8') == -1 and badge.find('-9') == -1): badge_class = 'badge badge-success' else: badge_class = 'badge badge-danger' badge_tooltip = 'Expected returns in the next 7 days' header_float_right = '' header_portfolio_info = '' if symbol.find(get_portf_suffix()) == -1: # Strategy porttfolio header_float_right = '<div style="margin: 0px; height: 100%; overflow: hidden;">' +\ get_tradingview_symbol_info(uid) + '</div>' else: # Any other instruments header_portfolio_info = ''+\ ' <span class="title"><font style="font-size: x-large;">'+\ instr_name +' <span class="'+\ badge_class+'" data-toggle="tooltip" data-placement="right" title="'+\ badge_tooltip +'" >'+\ badge+'</span></font></span><br />'+\ ' <span class="text"><span class="desc">'+\ content + ' | ' +\ asset_class +\ market +\ symbol +\ isin +'</span></span>' p_header = '' +\ ' <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ header_float_right +\ header_portfolio_info +\ ' </div>'+\ ' </div>' cr_s.close() connection.close() return p_header
def get_rsi_chart(uid): """ xxx """ l_indexing_in_progress_note = 'Indexing in progress. Data will be available in 10 minutes...' connection = pymysql.connect(host=DB_SRV, user=DB_USR, password=DB_PWD, db=DB_NAME, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = connection.cursor(pymysql.cursors.SSCursor) sql = "SELECT date, rsi, rsi_oversold, rsi_overbought, forecast "+\ "FROM chart_data WHERE uid=" +\ str(uid) + " ORDER BY date" cursor.execute(sql) res = cursor.fetchall() data = '' i = 0 for row in res: rsi_date = row[0] rsi_value = str(row[1]) rsi_oversold = str(row[2]) rsi_overbought = str(row[3]) forecast = str(row[4]) year = rsi_date.strftime("%Y") month = rsi_date.strftime("%m") day = rsi_date.strftime("%d") if rsi_value == '0' or rsi_value == '0.0': rsi_value = 'null' if rsi_oversold == '0' or rsi_oversold == '0.0': rsi_oversold = 'null' if rsi_overbought == '0' or rsi_overbought == '0.0': rsi_overbought = 'null' if forecast == '0' or forecast == '0.0': forecast = 'null' if not forecast == 'null': rsi_value = 'null' if i > 0: data = data + ',' data = data + '[new Date('+\ str(year)+','+\ str(int(month)-1)+', '+\ str(day)+')'+','+\ str(rsi_value) +','+\ str(rsi_overbought) + ',' +\ str(rsi_oversold) + ']' i += 1 cursor.close() connection.close() chart_title = 'rsi14' chart_font_size = 10 l_date = 'date' l_rsi_value = 'rsi14' l_rsi_overbought = 'Overbought' l_rsi_oversold = 'Oversold' if data != '': return_data = "" +\ "<script>"+\ " google.charts.load('current', {'packages':['corechart']});"+\ " google.charts.setOnLoadCallback(drawChart);"+\ " function drawChart() {"+\ " var data = new google.visualization.DataTable();"+\ " data.addColumn('date', '"+ l_date +"');"+\ " data.addColumn('number', '"+ l_rsi_value +"');"+\ " data.addColumn('number', '"+ l_rsi_overbought +"');"+\ " data.addColumn('number', '"+ l_rsi_oversold +"');"+\ " data.addRows(["+data+"]);"+\ ' var options = {'+\ ' title: "'+ chart_title +'", '+\ ' fontSize: '+ str(chart_font_size)+','+\ ' legend: "top",'+\ ' vAxis: { gridlines: { color: "transparent" } '+\ theme_return_this('', ', textStyle: {color: "white"}') + '},'+\ ' hAxis: { gridlines: { count: 4 }' +\ theme_return_this('', ', textStyle: {color: "white"}') + ' }, '+\ ' series:{'+\ ' 0: {areaOpacity: 0.3, color: '+\ theme_return_this('"#17a2b8"', '"#00fbff"') +', lineWidth: 1},'+\ ' 1: {areaOpacity: 0, color: "red", lineWidth: 1},'+\ ' 2: {areaOpacity: 0.05, color: "green", lineWidth: 1}'+\ ' },'+\ ' chartArea:{width:"90%",height:"80%"},'+\ ' backgroundColor: "transparent"'+\ ' };'+\ ' var chart = '+\ 'new google.visualization.AreaChart(document.getElementById("rsi_chart"));'+\ ' chart.draw(data, options);'+\ " }"+\ "</script>"+\ '<div id="rsi_chart" class="sa-chart-hw-100-rsi"></div>' else: return_data = '' +\ '<div class="alert alert-info" role="alert">'+\ l_indexing_in_progress_note +\ '</div>' return return_data
def change_password_form(burl, data): """ xxx """ box_content = '' l_invalid_link_content = 'Olala invalid link :O ' l_section_title = 'Change your password' l_enterpassword_placeholder = 'Enter your new password' l_confirmpassword_placeholder = 'Re-enter your new password' l_password_not_match = 'Password do not match.' l_password_minimun_not_met = 'Password must be minimum 8 characters.' l_btn_label = 'Submit' user_uid = str(data) connection = pymysql.connect(host=DB_SRV, user=DB_USR, password=DB_PWD, db=DB_NAME, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = connection.cursor(pymysql.cursors.SSCursor) sql = 'SELECT uid FROM users WHERE uid="' + str(user_uid) + '"' cursor.execute(sql) res = cursor.fetchall() select_uid = '' for row in res: select_uid = row[0] cursor.close() connection.close() if select_uid == user_uid: validation_script = ' '+\ '<script>'+\ 'function checkPassword() {'+\ ' if (document.getElementById("data").value =='+\ ' document.getElementById("repassword").value) {'+\ ' document.getElementById("message").innerHTML = "";'+\ ' document.getElementById("submitBtn").innerHTML = "'+\ '<button type=\'submit\' '+\ 'class=\'btn btn-info btn-lg btn-block form-resetpassword-btn\'>' +\ l_btn_label + ' <i class=\'fas fa-arrow-right\'></i></button>' +'";'+\ ' } else {'+\ ' document.getElementById("message").innerHTML = "'+\ '<div class=\'alert alert-warning\' role=\'alert\'>'+\ l_password_not_match +'</div>";'+\ ' }'+\ '}'+\ 'function validateForm() {'+\ ' var password = document.forms["passwordForm"]["data"].value;'+\ ' var repassword = document.forms["passwordForm"]["repassword"].value;'+\ ' if (password != repassword) {'+\ ' alert("'+ l_password_not_match +'");'+\ ' return false;'+\ ' }'+\ ' if (password.length < 8) {'+\ ' alert("'+ l_password_minimun_not_met +'");'+\ ' return false;'+\ ' }'+\ '}'+\ '</script>' box_content = validation_script +\ '<div class="box-top">' +\ ' <div class="row">'+\ ' <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-center-content" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +\ '">'+\ ' <span class="sectiont">'+\ l_section_title +'</span>'+\ ' <form name="passwordForm" id="passwordForm" action="'+\ burl+'reset/?step=4" method="post" onsubmit="return validateForm();" '+\ 'style="width: 100%; max-width: 600px; padding: 2%; margin: auto;">'+\ ' <input type="hidden" id="data2" '+\ 'name="data2" value="'+\ user_uid +'">'+\ ' <input type="password" id="data" '+\ 'name="data" class="form-control" aria-label="Large" '+\ 'aria-describedby="inputGroup-sizing-sm" placeholder="'+\ l_enterpassword_placeholder +'" required>'+\ ' <input type="password" id="repassword" '+\ 'name="repassword" onkeyup="checkPassword();" '+\ 'class="form-control" aria-label="Large" '+\ 'aria-describedby="inputGroup-sizing-sm" placeholder="'+\ l_confirmpassword_placeholder +'" required>'+\ ' <span id="message"></span>'+\ ' <span id="submitBtn"></span>'+\ ' </form>'+\ ' </div>'+\ ' </div>'+\ ' </div>'+\ '</div>' else: box_content = '' +\ '<div class="box-top">' +\ ' <div class="row">'+\ ' <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-center-content" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +\ '">'+\ ' <div class="alert alert-danger" role="alert">'+\ l_invalid_link_content +'</div>'+\ ' </div>'+\ ' </div>'+\ ' </div>'+\ '</div>' return box_content
def validate_email_input(burl, data): """ xxx """ box_content = '' l_email_subject = 'Reset your password' l_email_content = 'Hi {name_of_user},\n go to the following link '+\ 'to change your password: {link_to_reset_password}' l_email_not_found = 'Unable to find email: '+\ str(data) +' in the system. Please contact us for assistance.' l_email_sent_notif = 'An email has been sent to your inbox '+\ 'with a link to reset your password. '+\ 'It might take up to 5 minutes to receive it. '+\ 'Please check as well your spam folder in case it lands there :( ' connection = pymysql.connect(host=DB_SRV, user=DB_USR, password=DB_PWD, db=DB_NAME, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = connection.cursor(pymysql.cursors.SSCursor) sql = 'SELECT username, name, uid FROM users WHERE username ="******"' cursor.execute(sql) res = cursor.fetchall() username = '' name = '' uid = '' for row in res: username = row[0] name = row[1] uid = row[2] message_content = l_email_not_found if data.lower() == username.lower(): link = burl + 'reset/?step=3&data=' + str(uid) l_email_content = l_email_content.replace('{name_of_user}', name.title()) l_email_content = l_email_content.replace('{link_to_reset_password}', link) send_email_to_queue(data, l_email_subject, l_email_content, 0) message_content = l_email_sent_notif box_content = ' '+\ '<div class="box-top">' +\ ' <div class="row">'+\ ' <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-center-content" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ ' <div class="alert alert-info" role="alert">'+\ message_content +'</div>'+\ ' </div>'+\ ' </div>'+\ ' </div>'+\ '</div>' cursor.close() connection.close() return box_content
def get_box_list_instr_n_portf(burl, mode, what, step, maxrow, sel): """ xxx """ # mode = 'view', mode = 'portf_select', mode = 'dashboard' # what = 'instr', what = 'portf' # maxrow = numeric number of row ie. 1000 # step = step of portfolio selection box_content = '' if mode == 'portf_select': col_id = 0 else: col_id = 1 box_content = '' +\ '<script>'+\ 'function filterTable() {'+\ ' var input, filter, table, tr, td, i, txtValue;'+\ ' input = document.getElementById("filterInput");'+\ ' filter = input.value.toUpperCase();'+\ ' table = document.getElementById("table_instr_n_portf");'+\ ' tr = table.getElementsByTagName("tr");'+\ ' for (i = 0; i < tr.length; i++) {'+\ ' td = tr[i].getElementsByTagName("td")['+ str(col_id) +'];'+\ ' if (td) {'+\ ' txtValue = td.textContent || td.innerText;'+\ ' if (txtValue.toUpperCase().indexOf(filter) > -1) {'+\ ' tr[i].style.display = "";'+\ ' } else {'+\ ' tr[i].style.display = "none";'+\ ' }'+\ ' }'+\ ' }'+\ '}'+\ '</script>' l_placeholder = "Type to find from the list..." l_your_portfolios = 'Your Portfolio' l_add_portf_link = 'Add to portfolio' l_your_portfolios = l_your_portfolios +\ ' [<a href="'+ burl +'p/?ins=1&step=1" style="font-size: small;">'+ l_add_portf_link +'</a>]' box_div_class = 'col-lg-12 col-md-12 col-sm-12 col-xs-12' portfolio_box_style_dark_mode = theme_return_this('', 'border-style:solid; '+\ 'border-width:thin; border-color:#343a40;') list_title = '' list_class = 'sa-center-content sa-list-select-100pct sa-instr-n-portf-list' search_box = '<div class="sa-cursor">'+\ '<input type="text" id="filterInput" name="filterInput" onkeyup="filterTable()" '+\ 'class="form-control" aria-label="Large" '+\ 'aria-describedby="inputGroup-sizing-sm" style="background: transparent; '+\ theme_return_this('', 'color: white;') +'" placeholder="'+\ l_placeholder +'" autofocus>'+\ '<i></i>'+\ '</div><div> </div>' if mode == 'dashboard': list_title = '<span class="sectiont"><i class="fas fa-chart-pie"></i> '+\ l_your_portfolios +'</span>' search_box = '' list_class = '' box_div_class = 'col-lg-12 col-md-12 col-sm-12 col-xs-12 d-none d-lg-block' box_content = box_content +\ '<div class="box">' +\ ' <div class="row">'+\ ' <div class="'+ box_div_class +'">'+\ ' <div class="box-part rounded '+\ list_class +'" style="'+ portfolio_box_style_dark_mode +'">'+\ search_box +\ list_title +\ gen_instr_n_portf_table(burl, mode, what, step, maxrow, sel) +\ ' </div>'+\ ' </div>'+\ ' </div>'+\ '</div>' return box_content
def get_signal_return_colchart(uid): """ xxx """ return_data = '' chart_id = 'chart_signal_returns_col' title = 'Signal Performance' legend_position = 'none' width = '90%' height = '100px' color_neg = theme_return_this('red', '#d9534f') color_pos = theme_return_this('green', 'lime') data = [] data_label = [] data_color = [] data_annotation = [] l_y1 = '1-year' l_m6 = '6-month' l_m3 = '3-month' l_m1 = '1-month' factor = 1 sep = '' connection = pymysql.connect(host=DB_SRV, user=DB_USR, password=DB_PWD, db=DB_NAME, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = connection.cursor(pymysql.cursors.SSCursor) sql = 'SELECT instruments.y1_signal,instruments.m6_signal,'+\ 'instruments.m3_signal,instruments.m1_signal,instruments.w1_signal, instruments.unit '+\ 'FROM instruments JOIN symbol_list '+\ 'ON symbol_list.symbol = instruments.symbol WHERE symbol_list.uid = '+\ str(uid) cursor.execute(sql) res = cursor.fetchall() for row in res: y_1 = row[0] m_6 = row[1] m_3 = row[2] m_1 = row[3] unit = row[5] if unit == '%': factor = 100 sep = '' else: factor = 1 sep = ' ' data.append(round(y_1 * factor, 1)) data_label.append(l_y1) if y_1 < 0: data_color.append(color_neg) else: data_color.append(color_pos) data_annotation.append(str(round(y_1 * factor, 1)) + sep + unit) data.append(round(m_6 * factor, 1)) data_label.append(l_m6) if m_6 < 0: data_color.append(color_neg) else: data_color.append(color_pos) data_annotation.append(str(round(m_6 * factor, 1)) + sep + unit) data.append(round(m_3 * factor, 1)) data_label.append(l_m3) if m_3 < 0: data_color.append(color_neg) else: data_color.append(color_pos) data_annotation.append(str(round(m_3 * factor, 1)) + sep + unit) data.append(round(m_1 * factor, 1)) data_label.append(l_m1) if m_1 < 0: data_color.append(color_neg) else: data_color.append(color_pos) data_annotation.append(str(round(m_1 * factor, 1)) + sep + unit) return_data = get_gcharts_column(chart_id, data, data_label, data_color, data_annotation, title, legend_position, width, height) cursor.close() connection.close() return return_data
def get_desc_box(uid): """ xxx """ desc_box_title = 'Description & Recommendations' connection = pymysql.connect(host=DB_SRV, user=DB_USR, password=DB_PWD, db=DB_NAME, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = connection.cursor(pymysql.cursors.SSCursor) sql = "SELECT instruments.description, instruments.w_forecast_display_info, "+\ "instruments.account_reference, instruments.unit, instruments.symbol "+\ "FROM instruments JOIN symbol_list "+\ "ON instruments.symbol = symbol_list.symbol WHERE symbol_list.uid=" + str(uid) cursor.execute(sql) res = cursor.fetchall() portf_summary = "" for row in res: portf_summary = row[0] portf_forecast = row[1] portf_account_ref = row[2] portf_unit = row[3] portf_symbol = row[4] slang = get_selected_lang() l_wait = 'wait' sql = "SELECT portf_descr, portf_recomm_buy, portf_recomm_sell "+\ "FROM recommendations WHERE lang ='"+ slang +"' " cursor.execute(sql) res = cursor.fetchall() portf_descr = '' portf_recomm_buy = '' portf_recomm_sell = '' for row in res: portf_descr = row[0] portf_recomm_buy = row[1] portf_recomm_sell = row[2] portf_descr = portf_descr.replace('{account_minimum}', str(int(portf_account_ref))) portf_descr = portf_descr.replace('{unit}', portf_unit) portf_descr = portf_descr.replace('{display_forecast}', str(portf_forecast)) sql = "SELECT price_close FROM chart_data WHERE uid=" + str( uid) + " ORDER by date DESC LIMIT 1" cursor.execute(sql) res = cursor.fetchall() portf_last_price = 0 for row in res: portf_last_price = row[0] portf_recomm = '<br /><br />' sql = 'SELECT order_type, alloc_fullname, entry_level, strategy_order_type FROM portfolios '+\ "WHERE portf_symbol ='"+ portf_symbol +"' ORDER BY alloc_fullname" cursor.execute(sql) res = cursor.fetchall() i = 1 for row in res: alloc_order_type = row[0] alloc_fullname = row[1] alloc_entry_price = row[2] alloc_strategy_order_type = row[3] added_order = False if alloc_order_type.lower() == 'buy' and\ (alloc_strategy_order_type == 'long/short' or\ alloc_strategy_order_type == 'long'): portf_recomm = portf_recomm + str(i)+') ' +\ portf_recomm_buy.replace('{portf_alloc_instr}', alloc_fullname)+ '<br />' added_order = True if alloc_order_type.lower() == 'sell' and\ (alloc_strategy_order_type == 'long/short' or\ alloc_strategy_order_type == 'short'): portf_recomm = portf_recomm + str(i)+') ' +\ portf_recomm_sell.replace('{portf_alloc_instr}', alloc_fullname)+ '<br />' added_order = True if not added_order: portf_recomm = portf_recomm + str( i) + ') ' + l_wait + ' ' + alloc_fullname + '<br />' i += 1 portf_recomm = portf_recomm.replace('{portf_alloc_entry_price}', alloc_entry_price) portf_descr = portf_descr.replace('{portf_recomm}', portf_recomm + '<br />') portf_descr = portf_descr.replace( '{portf_last_price}', str(round(portf_last_price - portf_account_ref, 2))) cursor.close() connection.close() portf_desc_box = '' +\ ' <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">'+\ ' <div class="box-part rounded sa-portf-perf-portf-chart" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ ' <div><h6>'+ desc_box_title +'</h6></div>'+\ ' <div class="sa-descr-box-sm">'+ portf_summary + ' ' + portf_descr +'</div>'+\ ' </div>'+\ ' </div>' return portf_desc_box
def get_sign_ta_chart_alt_orders(uid, burl): """ xxx """ signal_box = '' tech_chart = '' signal_box_title = 'Alternative Orders' indicator_box_height = '400px' signal_box = '' +\ ' <div class="col-lg-3 col-md-6 col-sm-6 col-xs-12">'+\ ' <div class="box-part rounded sa-signal-alt-ord-prf" style="'+\ theme_return_this('', 'border-style:solid; border-width:thin; border-color:#343a40;') +'">'+\ ' <div><h6>'+\ signal_box_title +'</h6></div>'+\ get_alt_orders(uid) +\ ' </div>'+\ ' <div class=" rounded sa-signal-alt-ord-prf sa-signal-indic" '+\ 'style="height: '+ indicator_box_height +'; overflow: hidden;">'+\ get_tradingview_indicators(uid, '100%', '100%') +\ ' </div>'+\ ' </div>' tab_1_label = 'Technical Levels' tab_1_link = '#ta' tab_1_id = 'ta' tab_2_label = 'Chart' tab_2_link = '#chart' tab_2_id = 'chart' tab_3_label = '[FA] Financials' tab_3_link = burl + 'financials/?uid=' + str(uid) tab_4_label = '[PF] Profile' tab_4_link = burl + 'profile/?uid=' + str(uid) tab_5_label = '[AX] Analytics' tab_5_link = '#analytics' tab_6_label = '[TOP] Events/News' tab_6_link = '#events' tech_chart = '' +\ '<div class="col-lg-9 col-md-6 col-sm-6 col-xs-12">'+\ ' <div class="box-part rounded sa-signal-ta-chart">'+\ ''+\ '<ul id="sa-tab-sm" class="nav nav-tabs" role="tablist">'+\ ' <li class="nav-item">'+\ ' <a class="nav-link active" data-toggle="pill" href="'+\ tab_1_link +'">'+ tab_1_label +'</a>'+\ ' </li>'+\ ' <li class="nav-item">'+\ ' <a class="nav-link" data-toggle="pill" href="'+\ tab_2_link +'">'+ tab_2_label +'</a>'+\ ' </li>'+\ ' <li class="nav-item">'+\ ' <a class="nav-link" href="'+\ tab_3_link +'">'+ tab_3_label +'</a>'+\ ' </li>'+\ ' <li class="nav-item">'+\ ' <a class="nav-link" href="'+\ tab_4_link +'">'+ tab_4_label +'</a>'+\ ' </li>'+\ ' <li class="nav-item">'+\ ' <a class="nav-link" href="'+\ tab_5_link +'">'+ tab_5_label +'</a>'+\ ' </li>'+\ ' <li class="nav-item">'+\ ' <a class="nav-link" href="'+\ tab_6_link +'">'+ tab_6_label +'</a>'+\ ' </li>'+\ '</ul>'+\ ''+\ '<div class="tab-content">'+\ ' <div id="'+\ tab_1_id +'" class="tab-pane active" style="'+\ theme_return_this('', 'background-color: #20124d;') +'"><br />'+\ get_ta_chart(uid) +\ get_rsi_chart(uid) +\ ' </div>'+\ ' <div id="'+\ tab_2_id +'" style="height: 520px;" class="tab-pane fade"><br />'+\ ' <div style="height: 510px; width:99%">'+\ get_tradingview_chart(uid, '510', '"100%"','0') +\ ' </div>'+\ ' </div>'+\ '</div>'+\ '</div>'+\ '</div>' #To disable tab: remove the data-toggle="pill" return signal_box + tech_chart
def get_ta_chart(uid): """ xxx """ return_data = '' connection = pymysql.connect(host=DB_SRV, user=DB_USR, password=DB_PWD, db=DB_NAME, charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) cursor = connection.cursor(pymysql.cursors.SSCursor) sql = "SELECT price_close FROM chart_data WHERE uid="+\ str(uid) + " ORDER BY price_close LIMIT 1" cursor.execute(sql) res = cursor.fetchall() minval = -9 for row in res: minval = row[0] if minval != -9: sql = "SELECT symbol, date, price_close, forecast, lt_upper_trend_line, lt_lower_trend_line, "+\ "st_upper_trend_line, st_lower_trend_line, ma200 FROM chart_data WHERE uid=" + str(uid) +" "+\ "ORDER BY date " cursor.execute(sql) res = cursor.fetchall() data = '' i = 0 for row in res: chart_date = row[1] price_close = str(row[2]) forecast = str(row[3]) lt_upper_trend_line = str(row[4]) lt_lower_trend_line = str(row[5]) st_upper_trend_line = str(row[6]) st_lower_trend_line = str(row[7]) ma200 = str(row[8]) year = chart_date.strftime("%Y") month = chart_date.strftime("%m") day = chart_date.strftime("%d") if forecast == '0' or forecast == '0.0': forecast = 'null' if price_close == '0' or price_close == '0.0' or forecast != 'null': price_close = 'null' if lt_upper_trend_line == '0' or lt_upper_trend_line == '0.0': lt_upper_trend_line = 'null' if lt_lower_trend_line == '0' or lt_lower_trend_line == '0.0': lt_lower_trend_line = 'null' if st_upper_trend_line == '0' or st_upper_trend_line == '0.0': st_upper_trend_line = 'null' if st_lower_trend_line == '0' or st_lower_trend_line == '0.0': st_lower_trend_line = 'null' if ma200 == '0' or ma200 == '0.0': ma200 = 'null' if i > 0: data = data + ',' data = data + '[new Date('+\ str(year)+','+\ str(int(month)-1)+', '+\ str(day)+')'+','+\ str(price_close) +','+\ str(forecast) + ','+\ str(lt_upper_trend_line) + ','+\ str(lt_lower_trend_line) + ',' +\ str(st_upper_trend_line) + ','+\ str(st_lower_trend_line) + ',' +\ str(ma200) + ']' i += 1 cursor.close() connection.close() chart_title = 'Technical analysis and Forecast' chart_font_size = 10 l_date = 'Date' l_price_close = "price" l_forecast = 'Forecast' l_lt_up_trend = 'Long-term upper trend line' l_lt_low_trend = 'Long-term lower trend line' l_st_up_trend = 'Short-term upper trend line' l_st_low_trend = 'Short-term lower trend line' l_ma200 = 'MA200' return_data = "" +\ "<script>"+\ " google.charts.load('current', {'packages':['corechart']});"+\ " google.charts.setOnLoadCallback(drawChart);"+\ " function drawChart() {"+\ " var data = new google.visualization.DataTable();"+\ " data.addColumn('date', '"+ l_date +"');"+\ " data.addColumn('number', '"+ l_price_close +"');"+\ " data.addColumn('number', '"+ l_forecast +"');"+\ " data.addColumn('number', '"+ l_lt_up_trend +"');"+\ " data.addColumn('number', '"+ l_lt_low_trend +"');"+\ " data.addColumn('number', '"+ l_st_up_trend +"');"+\ " data.addColumn('number', '"+ l_st_low_trend +"');"+\ " data.addColumn('number', '"+ l_ma200 +"');"+\ " data.addRows(["+data+"]);"+\ ' var options = {'+\ ' title: "'+\ chart_title +'", '+\ ' titleTextStyle: {color: '+\ theme_return_this('"black"', '"white"') +' },'+\ ' fontSize: '+\ str(chart_font_size)+','+\ ' legend: {position:"top" '+\ theme_return_this('', ', textStyle: {color: "white"}') +'},'+\ ' vAxis: { viewWindow:{min: '+\ str(minval) +', viewWindowMode: "explicit"}, gridlines: { color: "transparent" } '+\ theme_return_this('', ', textStyle: {color: "white"}') +' },'+\ ' hAxis: { gridlines: { count: 4, color: "transparent" } '+\ theme_return_this('', ', textStyle: {color: "white"}') +'}, '+\ ' series:{'+\ ' 0: {areaOpacity: 0.3, color: '+\ theme_return_this('"#17a2b8"', '"#ffffff"') +', lineWidth: 2},'+\ ' 1: {areaOpacity: 0.3, color: "#ff9800", lineWidth: 3},'+\ ' 2: {areaOpacity: 0, color: '+\ theme_return_this('"gray"', '"white"') +', lineWidth: 1},'+\ ' 3: {areaOpacity: 0, color: '+\ theme_return_this('"gray"', '"white"') +', lineWidth: 1},'+\ ' 4: {areaOpacity: 0.05, color: '+\ theme_return_this('"#ff3399"', '"yellow"') +', lineWidth: 2, lineDashStyle:[10,2] },'+\ ' 5: {areaOpacity: 0.1, color: '+\ theme_return_this('"#ff3399"', '"yellow"') +', lineWidth: 2, lineDashStyle:[10,2] },'+\ ' 6: {areaOpacity: 0.05, color: '+\ theme_return_this('"red"', '"#00f2ff"') +', lineWidth: 1}'+\ ' },'+\ ' chartArea:{width:"90%",height:"80%"},'+\ ' backgroundColor: "transparent"'+\ ' };'+\ ' var chart = new google.visualization.AreaChart(document.getElementById("ta_chart"));'+\ ' chart.draw(data, options);'+\ " }"+\ "</script>"+\ '<div id="ta_chart" class="sa-chart-hw-100"></div>' return return_data