본문 바로가기

VBA/Code

[VBA] 업비트 Open API>주문>주문 가능 정보

반응형

API Reference

HTTP Method API URL
GET https://api.upbit.com/v1/orders/chance

 

QUERY PARAMS

필드명 필수 여부 설명 타입
market Y Market ID String

 

HEADERS

헤더명 필수 여부 설명 타입
Authorization Y Authorization token (JWT) String

 

Request Parameters

필드명 설명 타입
market 마켓 ID String

 

Response

필드명 설명 타입
bid_fee 매수 수수료 비율 NumberString
ask_fee 매도 수수료 비율 NumberString
market 마켓에 대한 정보 Object
market.id 마켓의 유일 키 String
market.name 마켓 이름 String
market.order_types 지원 주문 방식 Array[String]
market.order_sides 지원 주문 종류 Array[String]
market.bid 매수 시 제약사항 Object
market.bid.currency 화폐를 의미하는 영문 대문자 코드 String
market.bit.price_unit 주문금액 단위 String
market.bid.min_total 최소 매도/매수 금액 Number
market.ask 매도 시 제약사항 Object
market.ask.currency 화폐를 의미하는 영문 대문자 코드 String
market.ask.price_unit 주문금액 단위 String
market.ask.min_total 최소 매도/매수 금액 Number
market.max_total 최대 매도/매수 금액 NumberString
market.state 마켓 운영 상태 String
bid_account 매수 시 사용하는 화폐의 계좌 상태 Object
bid_account.currency 화폐를 의미하는 영문 대문자 코드 String
bid_account.balance 주문가능 금액/수량 NumberString
bid_account.locked 주문 중 묶여있는 금액/수량 NumberString
bid_account.avg_buy_price 매수평균가 NumberString
bid_account.avg_buy_price_modified 매수평균가 수정 여부 Boolean
bid_account.unit_currency 평단가 기준 화폐 String
ask_account 매도 시 사용하는 화폐의 계좌 상태 Object
ask_account.currency 화폐를 의미하는 영문 대문자 코드 String
ask_account.balance 주문가능 금액/수량 NumberString
ask_account.locked 주문 중 묶여있는 금액/수량 NumberString
ask_account.avg_buy_price 매수평균가 NumberString
ask_account.avg_buy_price_modified 매수평균가 수정 여부 Boolean
ask_account.unit_currency 평단가 기준 화폐 String

 

VBA Code

Sub Upbit_Orders_Chance()
     
    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 market As String, queryStr As String 
    Dim header As String, payload As String, signature As String, jwt As String 
     
    url = "https://api.upbit.com/v1/orders/chance" 
     
    market = "KRW-BTC" 
    queryStr = "market=" & market 

    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 & """,""query"":""" & queryStr & """}" 
    payload = Base64Encode(StrConv(payload, vbFromUnicode)) 
    signature = Base64Encode(SHA256Encrypt(header & "." & payload, SECRET_KEY)) 
    jwt = header & "." & payload & "." & signature 
     
    With WinHttp 
        .Open "GET", url & "?" & queryStr 
        .SetRequestHeader "Authorization", "Bearer " & jwt 
        .Send 
        .WaitForResponse 
        Debug.Print .ResponseText 
    End With 
     
    Set WinHttp = Nothing 
     
End Sub

 

SHA-256 Encrypt

더보기
 

[VBA] SHA-256 Encrypt

SHA-256 SHA-256은 SHA(Secure Hash Algorithm) 알고리즘의 한 종류로서 256비트로 구성되며 64자리 문자열을 반환한다. SHA-256은 미국의 국립표준기술연구소(NIST; National Institute of Standards and Technol..

xlmaster.tistory.com

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

더보기
 

[VBA] Base64 Encoding/Decoding

Base64 바이너리 데이터를 문자 코드에 영향을 받지 않는 공통 ASCII 문자로 표현하기 위해 만들어진 인코딩이다. ASCII 문자 하나가 64진법의 숫자 하나를 의미하기 때문에 BASE64라는 이름을 가졌다. 데이터를 6..

xlmaster.tistory.com

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

EXCHANGE API 자산 전체 계좌 조회 https://xlmaster.tistory.com/25
주문 주문 가능 정보 https://xlmaster.tistory.com/26
개별 주문 조회 https://xlmaster.tistory.com/32
주문 리스트 조회 https://xlmaster.tistory.com/27
주문 취소 접수 https://xlmaster.tistory.com/28
주문하기 https://xlmaster.tistory.com/29
출금 출금 리스트 조회 https://xlmaster.tistory.com/30
개별 출금 조회 https://xlmaster.tistory.com/31
출금 가능 정보 https://xlmaster.tistory.com/33
코인 출금하기 https://xlmaster.tistory.com/34
원화 출금하기 https://xlmaster.tistory.com/35
입금 입금 리스트 조회 https://xlmaster.tistory.com/36
개별 입금 조회 https://xlmaster.tistory.com/37
입금 주소 생성 요청 https://xlmaster.tistory.com/38
전체 입금 주소 조회 https://xlmaster.tistory.com/39
개별 입금 주소 조회 https://xlmaster.tistory.com/40
QUOTATION API 시세 종목 조회 마켓 코드 조회 https://xlmaster.tistory.com/15
시세 캔들 조회 분(Minute) 캔들 https://xlmaster.tistory.com/16
일(Day) 캔들 https://xlmaster.tistory.com/17
주(Week) 캔들 https://xlmaster.tistory.com/18
월(Month) 캔들 https://xlmaster.tistory.com/19
시세 체결 조회 당일 체결 내역 https://xlmaster.tistory.com/20
시세 Ticker 조회 현재가 정보 https://xlmaster.tistory.com/21
시세 호가 정보(Orderbook) 조회 호가 정보 조회 https://xlmaster.tistory.com/22

 

Upbit Open API v1.0.6

반응형