1. Node 프로젝트 만들기
[Node.js] Express로 프로젝트 만들기, Express-generator
1. Express란? 웹 서버에서 필요한 기능들을 미리 구현된 웹 프레임워크 이다. (라우팅, 세션, 템플릿 등) 2. Express-generator? Express만 설치할 수도 있는데 (ex npm install express --save) Express-generat..
developer-mango.tistory.com
2. node-binance-api 설치
npm install node-binance-api --save
아래 sample code로 이해 가능하면 아래걸 보는것도 추천
github.com/binance-exchange/node-binance-api
binance-exchange/node-binance-api
Node Binance API is an asynchronous node.js library for the Binance API designed to be easy to use. - binance-exchange/node-binance-api
github.com
3. 코드 작성
app.js 에 아래 코드 넣고 실행
APIKEY, APISECRET에는 각자의 key를 넣어야 함 - binance에서 만들 수 있음
아래 코드는 비트코인 선물 3분봉을 가져오는 코드임
//node api import
const Binance = require('node-binance-api');
//api 생성한것 입력 - key는 사이트에서 각자의 key 생성
let binance = new Binance().options({
  APIKEY: '------------------------------',
  APISECRET: '---------------------------',
});
//futuresCandles 는 선물 candle 정보를 가져 오는 api
async function getFutureCandle(symbol) {
  try {
    let candles = await binance.futuresCandles(symbol, "3m");
    console.log(candles);
  } catch (err) {
    console.log(err)
  }
  return "done";
}
//비트 코인에 대한 candle 정보 가져오기
getFutureCandle('BTCUSDT');4. 실행 결과
아래와 같이 json 형식으로 data가 옴
[
  [
    1618639020000,   '62203.69',
    '62239.00',      '62176.40',
    '62238.99',      '130.987',
    1618639199999,   '8148674.49390',
    2115,            '65.656',
    '4084550.41406', '0'
  ],
  [
    1618639200000,   '62238.99',
    '62250.28',      '62165.53',
    '62170.49',      '200.926',
    1618639379999,   '12496619.71472',
    2723,            '81.043',
    '5040309.39572', '0'
  ],
  [
    1618639380000,   '62170.49',
    '62187.52',      '62135.00',
    '62182.20',      '145.360',
    1618639559999,   '9035458.51588',
    2262,            '71.275',
    '4430490.97307', '0'
  ],
  [
    1618639560000,   '62182.20',
    '62198.86',      '62073.29',
    '62122.91',      '229.674',
    1618639739999,   '14269676.89837',
    3223,            '86.042',
    '5345861.24288', '0'
  ],
다른 api도 동일하게 사용하면 됨
api들은 아래 sample 코드 참조
github.com/binance-exchange/node-binance-api
binance-exchange/node-binance-api
Node Binance API is an asynchronous node.js library for the Binance API designed to be easy to use. - binance-exchange/node-binance-api
github.com
'Develop > Nodejs' 카테고리의 다른 글
| nodejs 현재 시간 가져오기 hh:mm:ss 형식 (0) | 2023.02.28 | 
|---|---|
| [Nodejs] Nodejs 로 Firestore에 정보 저장하기(Firebase 연동) (0) | 2022.02.25 | 
| [Node] post 구현 (0) | 2021.04.18 | 
| [Node.js] java의 class 처럼 모듈 빼서 사용하기 (0) | 2021.03.07 | 
| [Node.js] Express로 프로젝트 만들기, Express-generator (0) | 2021.02.19 | 

 
										
									 
										
									 
										
									 
										
									
댓글