Skip to content

Instantly share code, notes, and snippets.

@tel1214
Created March 25, 2019 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tel1214/fed603a4ee6a0c4a2576ead4a339d54e to your computer and use it in GitHub Desktop.
Save tel1214/fed603a4ee6a0c4a2576ead4a339d54e to your computer and use it in GitHub Desktop.
bitbankから価格情報を取得するbotその2
from datetime import datetime, date
import python_bitbankcc
import time
# get_candlestickに必要な本日日付を取得する関数
def cal_yyyymmdd():
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)
return time_now_int,yyyymmdd_int
while True:
# ロウソク足データを取得
pub = python_bitbankcc.public()
today = datetime.today()
time_now_int=cal_yyyymmdd()[0]
yyyymmdd_int=cal_yyyymmdd()[1]
if time_now_int < 899:
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