Nhận nguồn cung tiền tệ

Tool Extent-API
Ngày tạo: 2018-10-18 15:21:42 sửa đổi lần cuối: 2019-07-03 16:33:08
sao chép: 16 Số nhấp chuột: 1982
3
tập trung vào
1444
Người theo dõi

Sử dụng giao diện API cung cấp bởi coinmarketcap để thu thập lượng cung cấp và lưu hành đồng tiền, có thể được sử dụng để tính toán tổng giá trị thị trường

Mã nguồn chiến lược
function GetSupply(symbol, max){
    var ids = null
    if(_G('ids')){
        ids = _G('ids')
    }else{
        ids = JSON.parse(HttpQuery('https://api.coinmarketcap.com/v2/listings/')).data
        _G('ids', ids)
    }
    var coinId = null
    for (var i=0; i<ids.length; i++){
        if(ids[i].symbol.toLowerCase() == symbol.toLowerCase() ){
            coinId = ids[i].id
            break
        }
    }
    if(coinId){
        var ticker = JSON.parse(HttpQuery('https://api.coinmarketcap.com/v2/ticker/'+ coinId + '/')).data
        return parseFloat(max == undefined ? ticker.total_supply: ticker.max_supply)
    }else{
        throw 'symbol not found'
    }
}
function main() {
    Log(GetSupply('BTC')) // Get total current supply
    Log(GetSupply('BTC', true)) // Get max supply
}