Last active
November 16, 2019 22:14
-
-
Save tel1214/1c5e3fcd7dac7f6d23e9c43959dffe57 to your computer and use it in GitHub Desktop.
bitbankのAPIから定期的にbtcの価格情報を取得するコードです
This file contains hidden or 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
| from datetime import datetime, date | |
| import python_bitbankcc | |
| import time | |
| while True: | |
| # ロウソク足データを取得 | |
| pub = python_bitbankcc.public() | |
| today = datetime.today() | |
| list_yyyymmdd = str(today).split(" ") | |
| list2_yyyymmdd = str(list_yyyymmdd[0]).split("-") | |
| list3_yyyymmdd = str(list_yyyymmdd[1]).split(".") | |
| list4_yyyymmdd = str(list3_yyyymmdd[0]).split(":") | |
| time_now_str = str(list4_yyyymmdd[0]) + str(list4_yyyymmdd[1]) | |
| time_now_int = int(time_now_str) | |
| yyyymmdd = ( str(list2_yyyymmdd[0]) + str(list2_yyyymmdd[1]) + str(list2_yyyymmdd[2])) | |
| yyyymmdd_int = int(yyyymmdd) | |
| if time_now_int < 900: | |
| yyyymmdd_int -= 1 | |
| value = pub.get_candlestick( 'btc_jpy', '1min', str(yyyymmdd_int) ) | |
| #最後から2番目のローソク足を取り出す | |
| data = value['candlestick'][0]['ohlcv'][-2] | |
| #ローソク足から、日時・始値・終値・高値・安値を取り出す | |
| close_time = datetime.fromtimestamp(data[5]/1000).strftime('%Y/%m/%d %H:%M') | |
| open_price = data[0] | |
| high_price = data[1] | |
| low_price = data[2] | |
| close_price = data[3] | |
| #とりあえず表示 | |
| print("時間:" + close_time | |
| + "初値:" + str(open_price) | |
| + "終値:" + str(close_price) | |
| + "高値:" + str(high_price) | |
| + "低値:" + str(low_price)) | |
| #時間をおく | |
| time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment