0

rhino | 项目搭建

 1 year ago
source link: https://benpaodewoniu.github.io/2022/11/20/rhino1/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

rhino | 项目搭建

如何在本地运行 Rhino 整个环境。

Rhino 共需要下面几个 Rhino 必要库

  • RhinoCollect
  • RhinoGateway
  • RhinoLogger
  • RhinoObject
  • RhinoPipe

所有的库都放在线上 devpi 中,需要下载才能使用。

  • python3.9

假设在本地将 devpi 库和其他依赖库都装好了,只需要写一个 main.py 文件,进行开启。

下面举一个简单的例子,是订阅 BINANCE USWAPdogebusddepthtrade 的信息。

from RhinoLogger.RhinoLoggerObject.RhinoLoggerEnum import LoggerLevel
from RhinoLogger.RhinoLoggerObject.RhinoLoggerObject import LoggerConfig
from RhinoObject.Base.BaseEnum import ExchangeSub, DealDataType
from RhinoObject.Rhino.RhinoEnum import MethodEnum
from RhinoObject.Rhino.RhinoObject import SymbolInfo, RedisConfig, SymbolInfos, RhinoConfig

from RhinoCollect.RhinoCollect import RhinoCollect

# proxy = "http://127.0.0.1:1087"
proxy = None
logger_config = LoggerConfig(
cmdlevel=LoggerLevel.DEBUG.value,
filename='RhinoCollectlogs/log.log'
)
rhino_collect_config = RhinoConfig(
collect_type=DealDataType.REDIS.value,
redis_config=RedisConfig(
host=你 redis 的地址,
port=你本地redis的 port,
password="",
is_subscribe=True,
is_async=True
)
)
symbol_infos = SymbolInfos(
subscribes={
ExchangeSub.BINANCEUSWAP.value: True,
},
symbols={
ExchangeSub.BINANCEUSWAP.value:
[
SymbolInfo(
pair="DOGE_BUSD",
real_pair="dogebusd",
proxy=proxy,
symbol_methods=[MethodEnum.GETDEPTHS.value, MethodEnum.GETTRADES.value],
time_out=1,
),
],
}
)

RhinoCollect(logger_config, rhino_collect_config).start(symbol_infos)

你可以使用

nohup python3.9 main.py >/dev/null 2>&1 &

进行后台运行。上面成功运行后,数据就采集到 redischannel 里面了,下面就可以订阅拿数据了。

使用下面代码

import redis

pool = redis.ConnectionPool(host='redis ip',
port=redis port, db="",
password='')
r = redis.StrictRedis(connection_pool=pool)
p = r.pubsub()
p.subscribe("RHINODEPTH", "RHINOTRADE")
for item in p.listen():
print("Listen on channel : %s " % item['channel'].decode())
if item['type'] == 'message':
data = item['data'].decode()
print("From %s get message : %s" % (item['channel'].decode(), item['data'].decode()))

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK