BitFlyerのSFDBotです.30分ぐらいで書いたのでかなり適当ですが.乖離9.95%以下で買って,10.05%以上で売ります.どう使っていただいてもかまいません.(自己責任で)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
import pybitflyer from pubnub.callbacks import SubscribeCallback from pubnub.enums import PNStatusCategory from pubnub.pnconfiguration import PNConfiguration from pubnub.pubnub_tornado import PubNubTornado from pubnub.pnconfiguration import PNReconnectionPolicy from tornado import gen import time import threading import numpy as np class Order(object): def __init__(self): self.product_code = "FX_BTC_JPY" self.key = "Your key" self.secret = "Your secret" self.api = pybitflyer.API(self.key, self.secret) def market(self, side, size, minute_to_expire= None): print("Side : {}".format(side)) print(self.api.sendchildorder(product_code=self.product_code, child_order_type="MARKET", side=side, size=size, minute_to_expire = minute_to_expire)) c = PNConfiguration() c.subscribe_key = 'sub-c-52a9ab50-291b-11e5-baaa-0619f8945a4f' c.reconnect_policy = PNReconnectionPolicy.LINEAR pubnub = PubNubTornado(c) api = pybitflyer.API() fx_price = api.ticker(product_code="FX_BTC_JPY")["ltp"] btc_price = api.ticker(product_code="BTC_JPY")["ltp"] disparity_list = [] order = Order() lot = 0.001 maxlot = 0.01 pos = 0 @gen.coroutine def main(channels): class Callback(SubscribeCallback): def message(self, pubnub, message): global disparity_list global fx_price global btc_price FX_CHANNEL = 'lightning_executions_FX_BTC_JPY' BTC_CHANNEL = 'lightning_executions_BTC_JPY' if message.channel == FX_CHANNEL: fx_price = message.message[0]["price"] elif message.channel == BTC_CHANNEL: btc_price = message.message[0]["price"] price_disparity = fx_price/btc_price * 100 - 100 disparity_list.append(price_disparity) return price_disparity s = Callback() pubnub.add_listener(s) pubnub.subscribe().channels(channels).execute() if __name__ == '__main__': channels = [ 'lightning_executions_FX_BTC_JPY', 'lightning_executions_BTC_JPY' ] main(channels) pubnub_thread = threading.Thread(target=pubnub.start) pubnub_thread.start() while len(disparity_list) == 0: continue while True: health = api.gethealth(product_code="FX_BTC_JPY") healthy = health != "SUPER BUSY" and health != "STOP" present_lot = pos * lot if disparity_list[-1] > 10.05 and present_lot > -maxlot and healthy: order.market(side="SELL", size=lot) pos -= 1 elif disparity_list[-1] < 9.95 and present_lot < maxlot and healthy: order.market(side="BUY", size=lot) pos += 1 #superbusyのとき強制決済 elif healthy != True: present_lot = api.getpositions(product_code="FX_BTC_JPY") pos_sum = 0 for i in present_lot: if i["side"] == "BUY": pos_sum += i["size"] elif i["side"] == "SELL": pos_sum -= i["size"] if pos_sum > 0: order.market(side="SELL", size=pos_sum) elif pos_sum < 0: order.market(side="BUY", size=pos_sum) else: pass time.sleep(1) |
コメント
はじめまして。
このSFDのBotは
self.key = “Your key”
self.secret = “Your secret”
Your keyとYour secretを自分のAPIに変えると動きますか?
素人な質問ですみません。
そうですね.それで動きます.ただし,このままだと儲けは出ませんから工夫してみてください(^^)