반응형
API Reference
HTTP Method | API URL |
GET | https://api.upbit.com/v1/accounts |
HEADERS
헤더명 | 필수 여부 | 설명 | 타입 |
Authorization | Y | Authorization token (JWT) | String |
Response
필드명 | 설명 | 타입 |
currency | 화폐를 의미하는 영문 대문자 코드 | String |
balance | 주문가능 금액/수량 | String |
locked | 주문 중 묶여있는 금액/수량 | String |
avg_buy_price | 매수평균가 | String |
avg_buy_price_modified | 매수평균가 수정 여부 | Boolean |
unit_currency | 평단가 기준 화폐 | String |
VBA Code
Sub Upbit_Accounts()
Const ACCESS_KEY As String = "UPBIT_OPEN_API_ACCESS_KEY"
Const SECRET_KEY As String = "UPBIT_OPEN_API_SECRET_KEY"
Dim WinHttp As New WinHttp.WinHttpRequest
Dim url As String, nonce As String
Dim header As String, payload As String, signature As String, jwt As String
url = "https://api.upbit.com/v1/accounts"
nonce = DateDiff("s", "1/1/1970", Now) & Right(Timer() * 100, 3)
header = Base64Encode(StrConv("{""alg"":""HS256"",""typ"":""JWT""}", vbFromUnicode))
payload = "{""access_key"":""" & ACCESS_KEY & """,""nonce"":""" & nonce & """}"
payload = Base64Encode(StrConv(payload, vbFromUnicode))
signature = Base64Encode(SHA256Encrypt(header & "." & payload, SECRET_KEY))
jwt = header & "." & payload & "." & signature
With WinHttp
.Open "GET", url
.SetRequestHeader "Authorization", "Bearer " & jwt
.Send
.WaitForResponse
Debug.Print .ResponseText
End With
Set WinHttp = Nothing
End Sub
SHA-256 Encrypt
더보기
Function SHA256Encrypt(text As String, Optional secretKey As String = vbNullString) As Byte()
Dim asc As Object, enc As Object
Dim bText() As Byte, bKey() As Byte, bytes() As Byte
Set asc = CreateObject("System.Text.UTF8Encoding")
If secretKey <> vbNullString Then
Set enc = CreateObject("System.Security.Cryptography.HMACSHA256")
bText = asc.Getbytes_4(text)
bKey = asc.Getbytes_4(secretKey)
enc.Key = bKey
bytes = enc.ComputeHash_2(bText)
Else
Set enc = CreateObject("System.Security.Cryptography.SHA256Managed")
bText = asc.Getbytes_4(text)
bytes = enc.ComputeHash_2((bText))
End If
SHA256Encrypt = bytes
Set asc = Nothing
Set enc = Nothing
End Function
Base64 Encode
더보기
Function Base64Encode(ByRef arrData() As Byte) As String
Dim objXML As MSXML2.DOMDocument
Dim objNode As MSXML2.IXMLDOMElement
Set objXML = New MSXML2.DOMDocument
Set objNode = objXML.createElement("b64")
objNode.DataType = "bin.base64"
objNode.nodeTypedValue = arrData
Base64Encode = Replace(objNode.text, Chr(10), vbNullString)
Set objNode = Nothing
Set objXML = Nothing
End Function
업비트 OPEN API
Upbit Open API v1.0.6
반응형
'VBA > Code' 카테고리의 다른 글
[VBA] 업비트 Open API>주문>개별 주문 조회 (0) | 2019.10.04 |
---|---|
[VBA] 업비트 Open API>주문>주문 가능 정보 (0) | 2019.09.30 |
[VBA] 업비트 Open API>시세 호가 정보 조회>호가 정보 조회 (1) | 2019.09.09 |
[VBA] 업비트 Open API>시세 Ticker 조회>현재가 정보 (4) | 2019.09.09 |
[VBA] 업비트 Open API>시세 체결 조회>당일 체결 내역 (0) | 2019.09.09 |