본문 바로가기
코인/바이비트API

바이비트 API 실시간 현재 거래 시세 엑셀에 정리 - VBA

by 큐브빌드 2021. 7. 22.
반응형

바이 비트에서 제공하는 API를 활용하여 현재 거래 시세 엑셀에 정리하는 코드입니다.

 

일단 바이비트 API 문서를 보시면 아래와 같습니다.

 

요청 시 필요한 파라미터는 Symbol이지만 반드시 요청할 필요는 없습니다.

 

요청 시 돌려주는 값으로는 아래 표와 같습니다. (생각보다 엄청 많은 값들을 돌려주네요.)

 

Parameter Type Comment
symbol string Symbol
bid_price string Purchase price of the first order
ask_price string Selling price of the first order
last_price string Latest transaction price
last_tick_direction string Tick Direction
prev_price_24h string Price of 24 hours ago
price_24h_pcnt string Percentage change of market price relative to 24h
high_price_24h string The highest price in the last 24 hours
low_price_24h string Lowest price in the last 24 hours
prev_price_1h string Hourly market price an hour ago
price_1h_pcnt string Percentage change of market price relative to 1 hour ago
mark_price string Mark price
index_price string Index_price
open_interest number Open interest
open_value string Open position value
total_turnover string Total turnover
turnover_24h string Turnover for 24H
total_volume number Total volume
volume_24h number Trading volume in the last 24 hours
funding_rate string Funding rate
predicted_funding_rate string Predicted funding rate
next_funding_time string Next settlement time of capital cost
countdown_hour number Countdown of settlement capital cost
delivery_fee_rate string Delivery fee rate of Futures contract
predicted_delivery_price string Predicted delivery price of Futures contract
delivery_time string Delivery time of Futures contract

※ 바이비트 사이트 참조

 


VBA 코드

Sub BybitTicket()
Set WH = CreateObject("WinHttp.WinHttpRequest.5.1")


Url = "https://api.bybit.com/v2/public/tickers"

WH.Open "GET", Url
WH.Send
WH.WaitForResponse
 
result1 = Split(WH.ResponseText, "[{")
result2 = Split(result1(1), "},{")

For Each i In result2
    rcnt = rcnt + 1
    ccnt = 0
    For Each ii In Split(i, ",")
        ccnt = ccnt + 1
        Cells(rcnt, ccnt) = ii
    Next
Next

End Sub

이렇게 코드를 실행하시면 됩니다.

 

그러면 아래 이미지와 같이 엑셀에 정리됩니다.

 

추후 조금 더 보기 좋게 수정하셔서 사용하시면 됩니다.

 

그냥 가장 기본적으로 항목까지만 파싱 했습니다.

반응형

댓글