def teste_bar(): ev = EventEngine() ev.start() b = Binance(ev) bar = b.get_bar("BTCUSDT", "15m") log.info(bar.tail()) balance = b.get_balnce()
def __init__(self): self.ev = EventEngine() self.maker = BinanceFutures(self.ev) self.taker = Ftx(self.ev) self.maker_price = 0 self.taker_price = 0 self.data = [] RepeatingTimer(1, self.savedb).start()
def test_bar(): ev = EventEngine() ev.start() key = "YdDyZz1sql53yOZF9EDI2oe7H3hLgc8Y" secret = "UxPDjJHpUa9oCLCQbwwpZKU7rSfoSL7ngQFcBfmF87nvPQhh3yLvByG8puKzi3io" b = Bitmax(ev, key, secret) # bar = b.get_bar("BTC/USDT", "15") # log.info(bar.tail()) # data = b.get_balnce() data = b.get_open_order() print(data)
def __init__(self, engine, setting): super().__init__(engine, setting) self.msg = Feishu() self.ev = EventEngine() self.broker = BinanceFutures(self.ev) self.scheduler = BlockingScheduler() self.scheduler.add_job(self.on_bar, 'cron', minute="*/1", second="30") # self.scheduler.add_job(self.on_bar, 'cron', minute="14,29,44,59") # self.scheduler.add_job(self.on_bar, 'cron', second="14,29,44,59") # RepeatingTimer(60,self.on_bar).start()#每秒检查下次挂单情况 self.scheduler.start()
def __init__(self, engine, setting=None): super().__init__(engine, setting) self.ev = EventEngine() self.data = [] self.short: None self.long: None self.fee = 0.001 # 挂单价格增加手续费 # todo 下单数量可以调整为根据盘口以及当前的持仓比例来控制,价差扩大,持仓未达上线,可以增仓 self.qty = 0.001 # 下单BTC数量 反向合约需要换算 self.spreed_position = 0 self.status = False self.spreed_status = 0 #0 没有开仓,没有开单 1 long挂单,short未开单,2 long or short成交有持仓,等待对冲,3 对冲成功,等待回归平仓套利 4 long挂单平仓,5,long平仓,待short对冲平仓 RepeatingTimer(1, self.check_order).start() # 每秒检查下次挂单情况
def test_order(): ev = EventEngine() key = "qer4Udt2tkbfOihvE5zlINiPgfmuC5hbx1SEQmmow8XXiJqZhyGwtF83VRjuIqXN" secret = "X7UOt9wgYNCgjuLwIKX6Taij6afQTj89mKqG4fsYqufnxqrLI2GsV5kTZ7H7u1TL" b = Binance(ev, key, secret) b.start(["BTCUSDT"]) # success,text=b.get_user_account() # success, orderid = b.buy() while True: time.sleep(5) print(b.get_balnce("USDT")) print(b.get_positions("BTCUSDT", Direction.SHORT)) print(b.get_positions("BTCUSDT", Direction.LONG)) pass
def test_order(): ev = EventEngine() key = "qer4Udt2tkbfOihvE5zlINiPgfmuC5hbx1SEQmmow8XXiJqZhyGwtF83VRjuIqXN" secret = "X7UOt9wgYNCgjuLwIKX6Taij6afQTj89mKqG4fsYqufnxqrLI2GsV5kTZ7H7u1TL" b = BinanceFutures(ev, key, secret) # b.start(["BTCUSDT"]) # success,text=b.get_user_account() log.info("开始下单") O = b.buy("BTCUSDT", 0.001) log.info("开始结束。") log.info("获取持仓") pos = b.get_positions("BTCUSDT") log.info("当前持仓") print(pos)
def test_fundingrate(): ev = EventEngine() key = "qer4Udt2tkbfOihvE5zlINiPgfmuC5hbx1SEQmmow8XXiJqZhyGwtF83VRjuIqXN" secret = "X7UOt9wgYNCgjuLwIKX6Taij6afQTj89mKqG4fsYqufnxqrLI2GsV5kTZ7H7u1TL" b = BinanceFutures(ev) b.get_info() rate = [] for i in b.symbols: rate.append([i, float(b.get_fundingrate(i).get("lastFundingRate", 0))]) # print(rate) df = pd.DataFrame(rate) df.columns = ["symbol", "rate"] df = df.sort_values(by="rate", ascending=True) print(df)
def sell(): ev = EventEngine() ev.start() key = "YdDyZz1sql53yOZF9EDI2oe7H3hLgc8Y" # dongjing secret = "UxPDjJHpUa9oCLCQbwwpZKU7rSfoSL7ngQFcBfmF87nvPQhh3yLvByG8puKzi3io" b = Bitmax(ev, key, secret) sw = b.get_balnce() print(sw) symbol = "SRM/USDT" sw = sw["SRM"] print(sw) aty = float(sw.balance) data = b.sell(symbol, aty, 1.2) log.info(data)
def test_order(): ev = EventEngine() ev.start() # key = "YdDyZz1sql53yOZF9EDI2oe7H3hLgc8Y" # dongjing # secret = "UxPDjJHpUa9oCLCQbwwpZKU7rSfoSL7ngQFcBfmF87nvPQhh3yLvByG8puKzi3io" # key = "kFzuMzo2EmHYseOMXPQxiNXUEt9VBkFQ" # shanghai secret = "gAf9eePa3A5a5BLMoS4Yv3ShPdYgobBpF3LxBrLJY966CINeUQMvYmEoMkLcybUF" b = Bitmax(ev, key, secret) # symbol = "BTMX/USDT" symbol = "FIS/USDT" while get_cur_timestamp_ms() < 1599832721000: time.sleep(1) # data=b.buy("SWINGBY/USDT",20000,0.06) max_price = 1 qty = 2000 status = 0 while status == 0: orderlist = b.get_order_book(symbol) data = orderlist.get("data", None) if data: data = data.get("data", None) data = data.get("asks", []) if len(data) > 0: log.info(data) ask = data[0] price = float(ask[0]) if price < max_price: data = b.buy_ioc(symbol, qty, max_price) print(data) if data.get("code") == 0: log.info("下单成功") sw = b.get_balnce() sw = sw["FIS"] aty = round(float(sw.balance)) data = b.sell(symbol, aty, 1.8) log.info(data) status = 1 else: # pass log.info(data) else: log.info(f"{symbol}-no data") time.sleep(0.5)
def __init__(self): self.ev = EventEngine() self.ev.start() self.broke = BinanceFutures(self.ev)
def main(): ev = EventEngine() ev.start() st = Shannon(ev, None)
def __init__(self): self.ev = EventEngine() self.ev.start() self.broke = BinanceFutures(self.ev) self.broke.start("btcusdt", [FORCEORDER]) self.ev.register(FORCEORDER, self.callback)
order = self.broker.sell(symbol=self.symbol, price=price * (1 + self.volt_per), quantity=self.size) self.orders[order.ref] = order def add_bar(self, data): self.data.append(data) data = pd.DataFrame(self.data) volt = (data["high"] - data["low"]) / data["close"] self.volt_per = volt[:, -30].mean() def notify_order(self, order): try: if order.status in [order.Completed]: self.cur_price = order.price self.orders.pop(order.ref) for i in self.orders: self.broker.cancel_order(self.symbol, order.id) if order.status in [order.Canceled]: self.orders.pop(order.ref) except Exception as e: print(e) if __name__ == "__main__": ev = EventEngine() ev.start() st = Grid(ev, None) while True: time.sleep(60)
def main(cfg): ev = EventEngine() ev.start() st = HtStrategy(ev, cfg)
def test_subscribe(): ev = EventEngine() ev.start() b = Bitmax(ev) b.start("btcusdt", [FORCEORDER]) ev.register(FORCEORDER, on_sub)
def main(): ev = EventEngine() ev.start() st = Spike(ev, None)
def __init__(self): self.event=EventEngine() self.strategy=None