June

Get market list & info

Showing 1 changed file with 28 additions and 9 deletions
1 const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args)); 1 const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));
2 const url = 'https://api.upbit.com/v1/market/all'; 2 const url = 'https://api.upbit.com/v1/market/all';
3 +
3 const options = { method: 'GET', headers: { Accept: 'application/json' } }; 4 const options = { method: 'GET', headers: { Accept: 'application/json' } };
4 const express=require('express'); 5 const express=require('express');
5 const app=express(); 6 const app=express();
6 -async function test() { 7 +
8 +async function get_marketName() {
9 + var data=new Array();
10 + //전체 암호화폐 리스트 불러오기
7 let response= await fetch(url, options) 11 let response= await fetch(url, options)
8 .then(res => res.json()) 12 .then(res => res.json())
9 .then(json => { 13 .then(json => {
10 - console.log(json); 14 + for(i in json){
11 - console.log(json.length); 15 + data.push(json[i].market);
12 - return json; 16 + }
13 }) 17 })
14 - var hello=await (await fetch(url,options)).json(); 18 + return data;
15 - return hello;
16 } 19 }
17 - 20 +async function get_marketInfo(name_list){
18 -app.get('/fetch_test',async (req,res)=>{ 21 + //각 암호화폐 정보 조회
19 - res.json(await test()); 22 + const url=`https://api.upbit.com/v1/ticker/?markets=${name_list}`;
23 + var arr=new Array();
24 + let response2=await fetch(url,options)
25 + .then(res=>res.json())
26 + .then(json=>{
27 + for(i in json){
28 + if(json[i].acc_trade_price_24h>100000000000){
29 + arr.push([json[i].market,json[i].acc_trade_price_24h,json[i].trade_price]);
30 + }
31 + }
32 + })
33 + return arr;
34 +}
35 +app.get('/get_market',async (req,res)=>{
36 + var name_list=(await get_marketName());
37 + var market_info=(await get_marketInfo(name_list));
38 + res.json(market_info);
20 }) 39 })
21 app.listen(5000,()=>{ 40 app.listen(5000,()=>{
22 console.log('server') 41 console.log('server')
......