ビットコイン ポジポジ病克服ツール 「猫なで声」liquid版

Bitflyer 用の価格変動音声お知らせツールnekonadegoe.pyを運用していたら、ずっと価格が0。

Bitflyerのメンテナンスらしい。

こんな時に大暴騰や大暴落があっては悔しいので、急遽Liquid版を作った。

1行替えただけですけど。

    ここ url = 'https://api.liquid.com/products/5'
# -*- coding: utf-8 -*-

import time#タイマーとか現在時刻とか
import sys
sys.path.append("C:\config")
from config import Config#規定フォルダのConfig()クラスを読み込む,api_key & api_secretをコードに書かない
import json#データ形式
import requests#APIリクエスト
import datetime#日時ライブラリー
import time, datetime
import os
from class_talk import Talk
sp=Talk()
cfg = Config()#keyとsecretを読み込み、クラスで__init__する

def get_ticker():
    url = 'https://api.liquid.com/products/5'
    res = requests.get(url).json()
    return int((res['market_ask']+res['market_bid'])/2)




'''---------------------------------------------------------------'''
def discord(message):
   # Discordで発行したWebhookのURLを入れる
   discord_webhook_url = cfg.discord_token
   data = {"content": " " + message + " "}
   requests.post(discord_webhook_url, data=data)

#discord('文字列又は変数')

def lineNotify(message):
    line_notify_token = cfg.line_token
    line_notify_api = 'https://notify-api.line.me/api/notify'
    payload = {'message': message}
    headers = {'Authorization': 'Bearer ' + line_notify_token}
    requests.post(line_notify_api, data=payload, headers=headers)

#lineNotify('文字列又は変数')
#---------------------------------------------------'''
def main():
    #ローカル変数
    tick=[]#ticker=値段をためておく
    #set_started()#初期化関数
    interval=3#
    breakout_width=15000
    #決済前記録
    total=0
    s_short=60 #秒、比較する時間(s_short 秒前)
    c_short=int(s_short/interval)#60/3=20count、minits to  , s_short分は何カウントか
    c_mid=int(3*s_short/interval)#3*60/3=60  3分間のカウント数
    c_long=int(15*s_short/interval) #15*60/3=300  15分間のカウント数
    timestamp=''

    #WorkTime=float(input('何時間動かす?'))
    print('1分待機')
    start = time.time()#開始時刻
    recount=0
    maintenance_start = "03:59:30"
    maintenance_end   = "04:10:30"
    bed_inn="00:01:00"
    wake_up="06:31:00"
    
    while True:#time.time() - start <= WorkTime*60*60:#60秒*60分*WorkTime(時間)
        # bed_inn~wake_upまで、就寝中は稼働しない2021/03/28
        st = datetime.datetime.strptime(bed_inn,"%H:%M:%S").strftime("%H:%M:%S")
        et = datetime.datetime.strptime(wake_up, "%H:%M:%S").strftime("%H:%M:%S")
        nt = datetime.datetime.now().strftime("%H:%M:%S")
        if nt>st and nt<et:
            print(timestamp,"メンテナンス時間中のため待機しています")
            time.sleep(600)#30分ごとに確認
            tick.clear()
            recount=0
            continue
        try:
            btc_price=get_ticker()
            tick.append(btc_price)#tick貯蓄
            if recount > c_short :#開始後1分以上経っていたら
                timestamp=datetime.datetime.fromtimestamp(time.time()).strftime(' %H:%M:%S (%Y/%m/%d) ')
                def1c=tick[-1]-tick[-2]#defarence of 1count
                def1m=tick[-1]-tick[-c_short]#defarence of 1m
                message=f'{def1c:>6,.0f} 3s  {def1m:>6,.0f} 1m  {timestamp}'
                #1分間上昇
                if recount > c_long:
                    if tick[-1]-tick[-c_long]>breakout_width*15:#15分
                        sp.talk('大暴騰継続中')
                        sendmsg=f' 大暴騰継続中 {message}'
                        print(sendmsg)
                        lineNotify(sendmsg)
                        discord(sendmsg)
                    elif tick[-1]-tick[-c_long]<-breakout_width*15:#15分
                        sp.talk('大暴落継続中')
                        sendmsg=f' 大暴落継続中 {message}'
                        print(sendmsg)
                        lineNotify(sendmsg)
                        discord(sendmsg)
                    else :
                        pass
                if recount > c_mid:
                    if tick[-1]-tick[-c_mid]>breakout_width*3:
                        sp.talk('暴騰中')
                        sendmsg=f' 暴騰中 {message}'
                        print(sendmsg)
                        lineNotify(sendmsg)
                        discord(sendmsg)
                    elif tick[-1]-tick[-c_mid]< -breakout_width*3:
                        sp.talk('暴落中')
                        sendmsg=f' 暴落中 {message}'
                        print(sendmsg)
                        lineNotify(sendmsg)
                        discord(sendmsg)
                    else :
                        pass
                if tick[-1]-tick[-c_short]>breakout_width:#1分でブレークアウト
                    #sp.talk('上昇中')
                    sendmsg=f' 上昇中 {message}'
                    print(sendmsg)
                    #lineNotify(sendmsg)
                    #discord(sendmsg)
                elif tick[-1]-tick[-c_short] < -breakout_width:
                    #sp.talk('下降中')
                    sendmsg=f' 下降中 {message}'
                    print(sendmsg)
                    #lineNotify(sendmsg)
                    #discord(sendmsg)
                else :
                    print(f'range  {message}')
            recount+=1
            time.sleep(interval)
        except KeyboardInterrupt:
            print('keyboard intterrupted!')
            sys.exit()
if __name__ == '__main__':
   main()

Class_talk.py

import win32com.client
from os import path
import json

class Talk():
    def talk(self,str):
        speaker = win32com.client.Dispatch("SAPI.SpVoice")
        speaker.Speak(str)

左 Bitflyer(BTCJPY)レバ無し  右Liquid(BTCJPY)レバ2倍

コメント

タイトルとURLをコピーしました