hello world
업비트의 거래소에서 제공하는 API를 가지고 현재 내 계정의 자산이 어느 정도인지 확인하는 코드를 짜보도록 하자.
코드는 아래 주소에서 그대로 복붙하면 된다.
여기서 24행을 보면 링크걸린 구문에서 .decode('utf-8')
를 제거하였다. 그 구문을 삽입하면 에러가 난다. 검색해보니 pyhon3에서는 이미 utf-8로 디코딩되어 있어서 그 구문이 필요 없다고 한다.
라즈베리파이에 업로드 한 후 실행하면 json 형태로 뭔가 긁어오는 걸 확인할 수 있다. 빨간색 네모칸에 있는 숫자를 기억하자.
결과값으로 받은 빨간색 네모칸은 평균매수 단가를 의미하는 것이었다.
성공했으니 이제 다음 단계로 넘어가면 될 것 같은데...
문제점
라즈베리파이 본연의 문제같은데, 요청과 응답이 너무 느리다. 한번 실행하면 결과를 받아올 때까지 5~6초가 걸린다. 컴퓨터로써는 말도 안되는 수준이다;; 그래도 어떡하겠어 해야지.. ㅠㅠ
그리고 스팀잇에서 소스코드를 쓰려면 < code>
구문 말고 ``` 이걸써야 하는것 같은데 보기가 매우 안좋다.
더 좋은 방법은 없을까?
# Python 3
import os
import jwt
import uuid
import hashlib
from urllib.parse import urlencode
import requests
#access_key = os.environ['UPBIT_OPEN_API_ACCESS_KEY']
#secret_key = os.environ['UPBIT_OPEN_API_SECRET_KEY']
#server_url = os.environ['UPBIT_OPEN_API_SERVER_URL']
access_key = ' '
secret_key = ' '
server_url = ' '
payload = {
'access_key': access_key,
'nonce': str(uuid.uuid4()),
}
jwt_token = jwt.encode(payload, secret_key)
authorize_token = 'Bearer {}'.format(jwt_token)
headers = {"Authorization": authorize_token}
res = requests.get(server_url + "/v1/accounts", headers=headers)
print(res.json())
안녕하세요 pyth0n님
랜덤 보팅!!
소소하게 보팅하고 가요
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
그렇게 반응이 느리면 사고 파는건 힘들겠네요.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
제가 직접 사고파는게 더 느리니까 해볼만할 것 같아요
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit