index.js 1.31 KB
const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));
const url = 'https://api.upbit.com/v1/market/all';

const options = { method: 'GET', headers: { Accept: 'application/json' } };
const express=require('express');
const app=express();

async function get_marketName() {
    var data=new Array();
    //전체 암호화폐 리스트 불러오기
    let response= await fetch(url, options)
        .then(res => res.json())
        .then(json => {
            for(i in json){
                data.push(json[i].market);
            }
        })
    return data;
}
async function get_marketInfo(name_list){
    //각 암호화폐 정보 조회
    const url=`https://api.upbit.com/v1/ticker/?markets=${name_list}`;
    var arr=new Array();
    let response2=await fetch(url,options)
        .then(res=>res.json())
        .then(json=>{
            for(i in json){
                if(json[i].acc_trade_price_24h>100000000000){
                    arr.push([json[i].market,json[i].acc_trade_price_24h,json[i].trade_price]);
                }   
            }
        })
    return arr;
}
app.get('/get_market',async (req,res)=>{
    var name_list=(await get_marketName());
    var market_info=(await get_marketInfo(name_list));
    res.json(market_info);
})
app.listen(5000,()=>{
    console.log('server')
})