# 调整子图的间距,hspace表示高(height)方向的间距 # 设置第一子图的y轴信息及标题 ax.set_ylabel('Close price in ¥') ax.set_title('A_Stock %s ichimoku Indicator' % ("test")) delay_price.plot(ax=ax, color='g', lw=1., legend=True, use_index=False) conversion.plot(ax=ax, color='r', lw=1., legend=True, use_index=False) base.plot(ax=ax, color='b', lw=1., legend=True, use_index=False) leada.plot(ax=ax, color='y', lw=1., legend=True, use_index=False) leadb.plot(ax=ax, color='k', lw=1., legend=True, use_index=False) close.plot(ax=ax, color='c', lw=1., legend=True, use_index=False) # 设置间隔,以便图形横坐标可以正常显示(否则数据多了x轴会重叠) interval = scale // 20 # 设置x轴参数,应用间隔设置 # 时间序列转换,(否则日期默认会显示时分秒数据00:00:00) # x轴标签旋转便于显示 pl.xticks([i for i in range(1, scale + 1, interval)], [datetime.strftime(i, format='%Y-%m-%d') for i in pd.date_range(df.index[0], df.index[-1], freq='%dd' % (interval))], rotation=45) plt.show() if __name__ == "__main__": request = HuobiSwapRequest("https://api.btcgateway.pro", "xxxx", "xxxx") s = "BTC-USD" p = "5min" c = 500 loop = asyncio.get_event_loop() loop.run_until_complete(MatPlot.get_data(s, p, c)) loop.close()
def __init__(self): self.host = config.accounts.get("host") self.mark_wss = config.accounts.get("mark_wss") self.wss = config.accounts.get("trade_wss") self.access_key = config.accounts.get("access_key") self.secret_key = config.accounts.get("secret_key") self.test = config.accounts.get("is_test", True) self.klines_max_size = config.markets.get("klines_max_size") self.depths_max_size = config.markets.get("depths_max_size") self.trades_max_size = config.markets.get("trades_max_size") self.symbol = config.markets.get("symbol") self.mark_symbol = config.markets.get("mark_symbol") self.trade_symbol = config.markets.get("trade_symbol") self.period = config.markets.get("period") self.step = config.markets.get("step") self.lever_rate = config.markets.get("lever_rate") self.price_tick = config.markets.get("price_tick") self.price_offset = config.markets.get("price_offset") self.loop_interval = config.markets.get("loop_interval") self.order_cancel_time = config.markets.get("order_cancel_time") self.auto_curb = config.markets.get("auto_curb") self.trading_curb = config.markets.get("trading_curb") self.long_position_weight_rate = config.markets.get( "long_position_weight_rate") self.short_position_weight_rate = config.markets.get( "short_position_weight_rate") self.long_fixed_position = config.markets.get("long_fixed_position", 0) self.short_fixed_position = config.markets.get("short_fixed_position", 0) self.platform = config.markets.get("platform") e = None if not self.host: e = Error("host miss") if not self.mark_wss: e = Error("mark_wss miss") if not self.wss: e = Error("trade_wss miss") if not self.access_key: e = Error("access_key miss") if not self.secret_key: e = Error("secret_key miss") if not self.platform: e = Error("platform miss") if not self.klines_max_size: e = Error("klines_max_size miss") if not self.depths_max_size: e = Error("depths_max_size miss") if not self.trades_max_size: e = Error("trades_max_size miss") if not self.symbol: e = Error("symbol miss") if not self.mark_symbol: e = Error("mark_symbol miss") if not self.trade_symbol: e = Error("trade_symbol miss") if not self.period: e = Error("period miss") if not self.step: e = Error("step miss") if not self.lever_rate: e = Error("lever_rate miss") if not self.price_tick: e = Error("price_tick miss") if not self.price_offset: e = Error("price_offset miss") if not self.loop_interval: e = Error("loop_interval miss") if not self.order_cancel_time: e = Error("order_cancel_time miss") if not self.trading_curb: e = Error("trading_curb miss") if not self.long_position_weight_rate: e = Error("long_position_weight_rate miss") if not self.short_position_weight_rate: e = Error("short_position_weight_rate miss") if e: logger.error(e, caller=self) return # 市场数据 self.klines = {} self.depths = {} self.trades = {} # 账号数据 self.assets = Asset() self.orders = {} self.position = Position(self.symbol + '/' + self.trade_symbol) self.trade_money = 1 # 10USDT. 每次交易的金额, 修改成自己下单的金额. self.min_volume = 1 # 最小的交易数量(张). self.short_trade_size = 0 self.long_trade_size = 0 self.last_price = 0 self.long_status = 0 # 0不处理 1做多 -1平多 self.short_status = 0 # 0不处理 1做空 -1 平空 self.last_order = {} # 最近下单记录 # 初始http链接 if self.platform == "swap": self.request = HuobiSwapRequest(host=self.host, access_key=self.access_key, secret_key=self.secret_key) else: self.request = HuobiRequest(host=self.host, access_key=self.access_key, secret_key=self.secret_key) self.market = self.init_market() self.trade = self.init_trade() # 运行周期 LoopRunTask.register(self.on_ticker, self.loop_interval)