交易视图 - 单个合约的 bscscan/ethereum 图表

时间:2021-06-04 15:59:15

标签: javascript html ethereum tradingview-api bscscan

不幸的是,我在为单个令牌实施图表时有点愚蠢。

我使用以下脚本通过 html 调用 Tradinview:

/**
 * Determine if an SQL statement could potentially alter the database in any way.
 * @param string $sql - An SQL statement
 * @return boolean - True if query could alter the database, else false
 */
function isDangerousQuery($sql){
    $sql = trim($sql);

    // Irrelevant tokens to be parsed out of the query
    // A comment or string may contain a word like "drop"
    // so comments and strings need to be removed from the query
    $token_types = [
        [   'name' => 'Single-Line Comment',
            'start' => "--",
            'end' => "\n"   ],
        [   'name' => 'Multi-Line Comment',
            'start' => "/*",
            'end' => "*/"   ],
        [   'name' => 'Double-quoted String',
            'start' => "\"",
            'end' => "\""   ],
        [   'name' => 'Single-quoted String',
            'start' => "'",
            'end' => "'"    ]
    ];
    
    // This array will contain every character that is not part
    // of one of the above described irrelevant tokens
    $keywords_buffer = [];
    
    // If we are currently parsing one of the above token types
    // it's index is held here, else this will be false
    $current_token_type_index = false;
    
    // Loop through each character and reconstruct the query without the 
    // irrelevant token types. We need to loop rather than use a regex
    // because there could be quotes nested in comments and things like that
    // that would "trick" our regex
    $length = strlen($sql);
    for ($index = 0; $index < $length; $index++) {
        $chunk = substr($sql, $index);

        // If the current char is an escape char, skip the next char
        if($sql[$index] === '\\'){
            $index++;
            continue;
        }

        // Looking for all starting tokens
        if(false === $current_token_type_index){

            foreach($token_types as $token_type_index => $token_type){
                if(0 === strpos($chunk, $token_type['start'])){
                    $current_token_type_index = $token_type_index;
                }
            }

            if(false === $current_token_type_index){
                $keywords_buffer[] = $sql[$index];
            }

        // Looking for ending token
        }else if(0 === strpos($chunk, $token_types[$current_token_type_index]['end'])){

            $index += strlen($token_types[$current_token_type_index]['end']);
            if(strpos($token_types[$current_token_type_index]['end'], "\n") !== false) $keywords_buffer[] = "\n";
            $current_token_type_index = false;

        }

    }
    
    // Reconstruct the sql without the irrelevant tokens
    $sql_cleaned = implode('', $keywords_buffer);
    
    // Remove all symbols from the sql leaving only keywords and numbers
    $sql_keywords_only = preg_replace("/[^a-zA-Z_0-9\s]/", ' ', $sql_cleaned);
    
    // Create an array of unique keywords in upper-case
    $sql_keywords = array_unique(preg_split("/\s+/", strtoupper($sql_keywords_only)));
    
    // Filter out numbers and empty strings to get actual keywords
    $sql_keywords_filtered = [];
    foreach($sql_keywords as $keyword){
        if(!empty($keyword) && !is_numeric($keyword)){
            $sql_keywords_filtered[] = $keyword;
        }
    }
    
    // list of forbidden/dangerous keywords
    $dangerous_keywords = [
        'INSERT',
        'UPDATE',
        'DELETE',
        'RENAME',
        'DROP',
        'CREATE',
        'TRUNCATE',
        'ALTER',
        'COMMIT',
        'ROLLBACK',
        'MERGE',
        'CALL',
        'EXPLAIN',
        'LOCK',
        'GRANT',
        'REVOKE',
        'SAVEPOINT',
        'TRANSACTION',
        'SET'
    ];
    
    // Contains an array of dangerous keywords found
    // If this array is empty, query is safe
    $found_dangerous_keywords = array_intersect($dangerous_keywords, $sql_keywords_filtered);
    
    return count($found_dangerous_keywords) > 0;
}
`       <script type="text/javascript" src="../tv/public/charting_library/charting_library.standalone.js"></script>
        <script type="text/javascript" src="../tv/public/datafeeds/udf/dist/polyfills.js"></script>
        <script type="text/javascript" src="../tv/public/datafeeds/udf/dist/bundle.js"></script>
function getParameterByName(name) {
                name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
                var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
                    results = regex.exec(location.search);
                return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
            }

            function initOnReady() {
                var widget = window.tvWidget = new TradingView.widget({
                    // debug: true, // uncomment this line to see Library errors and warnings in the console
                    fullscreen: true,
                 debug: false,
   symbol: 'Coinbase:BTC/USD',

   interval: '15',
                    container_id: "tv_chart_container",
                    range: "YTD",
                    //  BEWARE: no trailing slash is expected in feed URL
                    datafeed: new Datafeeds.UDFCompatibleDatafeed(""),
                    library_path: "../tv/public/charting_library/",
                    locale: getParameterByName('lang') || "en",

                    disabled_features: ["left_toolbar", "border_around_the_chart", "header_saveload", "header_symbol_search", "cropped_tick_marks"],
                    enabled_features: [],
                    charts_storage_url: 'https://saveload.tradingview.com',
                    charts_storage_api_version: "1.1",
                    client_id: 'tradingview.com',
                    user_id: 'public_user_id',
                                        theme: 'dark',
                                        loading_screen: { backgroundColor: "#000000" },
                    // custom_css_url should be related to library_path

overrides: {
    "paneProperties.background": "#111111",
    "paneProperties.vertGridProperties.color": "#111111",
    "paneProperties.horzGridProperties.color": "#131722",
    "symbolWatermarkProperties.transparency": 90,
    "scalesProperties.textColor" : "#AAA",
    "mainSeriesProperties.candleStyle.wickUpColor": '#336854',
    "mainSeriesProperties.candleStyle.wickDownColor": '#7f323f',

   }
                });
            };

            window.addEventListener('DOMContentLoaded', initOnReady, false);

现在我的问题:

如何显示单个图表(例如来自代币/合约 - 0x7726cd4813e4d99bb38649d039fcb55ef0977e79)?我需要更改哪些内容以及通过哪个 API 获取所需数据?

感谢您的时间,

亲切的问候,本

0 个答案:

没有答案