7

tomoon | 策略模式

 1 year ago
source link: https://benpaodewoniu.github.io/2022/12/20/tomoon54/
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.
neoserver,ios ssh client

tomoon | 策略模式 | 犀牛的博客

姑苏城外一茅屋,万树梅花月满天

关于策略模式的讲解请参考 策略模式

这是对 RhinoGateway 中交易所的应用。

首先,我会创造一个 Map,使用交易所名字和交易所实例来做对应。

self.gateways[ExchangeSub.BINANCESPOT.value] = BinanceSpotGateway(self.logger, rhino_config, self.loop)
self.gateways[ExchangeSub.BINANCEUSWAP.value] = BinanceUSwapGateway(self.logger, rhino_config, self.loop)
self.gateways[ExchangeSub.MEXCSPOT.value] = MexcSpotGateway(self.logger, rhino_config, self.loop)
self.gateways[ExchangeSub.BSCSPOT.value] = BSCSpotGateway(self.logger, rhino_config, self.loop)

最后通过参数来选择具体使用哪个,比如

self.gateways.get(ExchangeSub).deal() // ExchangeSub 是传进去的交易所名称

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK