hbdmapi / huobi_futures_Python

An Asynchronous Event-driven High-frequency Trading System,huobi future,huobi coin margined swap, huobi usdt margined swap included.
MIT License
267 stars 113 forks source link

如何对Kline中2条行情数据的'close'值进行比较 #51

Closed 18728476237 closed 3 years ago

18728476237 commented 3 years ago

对于“huobi_swap” demo 的文件“main.py ”中除了初始化quant.initialize(config_file) initialize()外,就是quant.start(); 跳转到quant.py, start()方法最核心的功能语句是 self.loop.run_forever() ;而run_forever() 是python实现的函数,不是我们自己写的函数,那我要定义一个变量close 来接收每条Kline数据的'close'值(这个值是随时跟下一个close值比较,大于1个usdt就更新,所以不用list),我在哪里初始化这个close变量呢?在main.py中?还是那其它哪个文件的全局,还是哪个类中? 谢谢。

foonsun commented 3 years ago

可以在策略文件比如strategy.py文件,加一个变量,例如:在Init中,定义: self.last_close=None,然后在https://github.com/hbdmapi/huobi_futures_Python/blob/master/examples/huobi_future/strategy.py#L189 1.每次获取到新的close值与self.last_close进行比较。2.比较完再给self.last_close赋值。

18728476237 commented 3 years ago

你好,我根据你的邮件,现在实现了对last_close的获取,非常感谢。但是,还是又以下问题: 我把examples/huobi_future/strategy.py中所有的打印语句,除了async def on_event_kline_update(self, kline: Kline)函数中的logger语句保留外, 我把所有本文件中的logger语句全部注释掉,并且把config.json的Market:channel 修改为 kline "MARKETS": [ { "platform": "huobi_future", "channels":[ "kline" ], "orderbook_length": 10, "orderbooks_length": 100, "klines_length": 100, "trades_length": 100, "wss": "wss://api.hbdm.vn"

}

],

可是终端还是不停打印三种Kline信息,除了update外,剩下的data 和symbol对应的打印信息是怎么打印的呢?怎么才能取消呢?

D [2021-02-08 21:34:52,613] [-] [MyStrategy] kline update: {"platform": "huobi_future", "symbol": "BTC_CQ", "open": "45297.40000000", "high": "45297.40000000", "low": "45191.78000000", "close": "45256.05000000", "volume": "91.20836591", "timestamp": 1612791367886, "kline_type": "kline"}

D [2021-02-08 21:34:52,924] poll 4.701 ms took 0.497 ms: 1 events

D [2021-02-08 21:34:52,926] [-] [HuobiFutureMarket] data: {"ch": "market.BTC_CQ.kline.1min", "ts": 1612791367933, "tick": {"id": 1612791360, "mrid": 124012059620, "open": 45297.4, "close": 45256.05, "high": 45297.4, "low": 45191.78, "amount": 91.36746066467484, "vol": 41342, "count": 365}}

D [2021-02-08 21:34:52,928] [-] [HuobiFutureMarket] symbol: BTC_CQ kline: {"platform": "huobi_future", "symbol": "BTC_CQ", "open": "45297.40000000", "high": "45297.40000000", "low": "45191.78000000", "close": "45256.05000000", "volume": "91.36746066", "timestamp": 1612791367933, "kline_type": "kline"}

谢谢 

------------------ 原始邮件 ------------------ 发件人: "hbdmapi/huobi_futures_Python" <notifications@github.com>; 发送时间: 2021年2月8日(星期一) 下午4:47 收件人: "hbdmapi/huobi_futures_Python"<huobi_futures_Python@noreply.github.com>; 抄送: "宇"<525082270@qq.com>;"Author"<author@noreply.github.com>; 主题: Re: [hbdmapi/huobi_futures_Python] 如何对Kline中2条行情数据的'close'值进行比较 (#51)

可以在策略文件比如strategy.py文件,加一个变量,例如:在Init中,定义: self.last_close=None,然后在https://github.com/hbdmapi/huobi_futures_Python/blob/master/examples/huobi_future/strategy.py#L189 1.每次获取到新的close值与self.last_close进行比较。2.比较完再给self.last_close赋值。

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.