Created
January 26, 2019 20:06
-
-
Save icehongssii/7ac79713b182341a943f168723c7ed0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
def sendRequest(url): | |
res = requests.get(url) | |
contents = res.content.decode('utf-8') | |
# python2에서는 contents = res.content만 적어도 됩니다. | |
# python2에서는 res.content가 string으로 오지만 | |
# python3에서는 byte로 오기 때문에 디코딩이 필요합니다. | |
# 대부분의 api는 json으로 반환되기 때문에 곧바로 json 라이브러리를 이용해 로드합니다 | |
json_contents = json.loads(contents) | |
return json_contents | |
def getBitmexSymbolList(contents): | |
symbol_list = [ | |
pair['symbol'] | |
for pair in contents | |
] | |
# contents안에 들어있는 각각의 아이템들 중에서 | |
# 키가 symbol인 것들만 리스트에 넣겠다는 뜻 | |
return symbol_list | |
if __name__ == "__main__": | |
symbol_endpoint= "https://www.bitmex.com/api/v1/instrument/active" | |
contents = sendRequest(symbol_endpoint) | |
symbols = getBitmexSymbolList(contents) | |
print(symbols) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment