def create_price_feed(arguments, tub: Tub = None) -> PriceFeed: assert (isinstance(tub, Tub) or tub is None) price_feed_argument = arguments.price_feed price_feed_expiry_argument = arguments.price_feed_expiry gdax_ws_url = "wss://ws-feed.gdax.com" if price_feed_argument == 'eth_dai': # main price feed main_price_feed = GdaxPriceFeed(ws_url=gdax_ws_url, product_id="ETH-USD", expiry=price_feed_expiry_argument) # emergency price feed emergency_price_feed = AveragePriceFeed([ SetzerPriceFeed('kraken', expiry=price_feed_expiry_argument), SetzerPriceFeed('gemini', expiry=price_feed_expiry_argument) ]) if tub is not None: # last resort price feed last_resort_price_feed = TubPriceFeed(tub) price_feed = BackupPriceFeed([ main_price_feed, emergency_price_feed, last_resort_price_feed ]) else: price_feed = BackupPriceFeed( [main_price_feed, emergency_price_feed]) elif price_feed_argument == 'btc_dai': return GdaxPriceFeed(ws_url=gdax_ws_url, product_id="BTC-USD", expiry=price_feed_expiry_argument) elif price_feed_argument == 'tub': if tub is not None: price_feed = TubPriceFeed(tub) else: raise Exception( f"'--price-feed tub' cannot be used as this keeper does not know about 'Tub'" ) elif price_feed_argument.startswith("fixed:"): price_feed = FixedPriceFeed( Wad.from_number(price_feed_argument[6:])) elif price_feed_argument.startswith( "ws://") or price_feed_argument.startswith("wss://"): socket_feed = WebSocketFeed(price_feed_argument, 5) socket_feed = ExpiringFeed(socket_feed, price_feed_expiry_argument) price_feed = WebSocketPriceFeed(socket_feed) else: raise Exception(f"'--price-feed {price_feed_argument}' unknown") return price_feed
def create_spread_feed(arguments) -> Feed: if arguments.spread_feed: web_socket_feed = WebSocketFeed(arguments.spread_feed, 5) expiring_web_socket_feed = ExpiringFeed(web_socket_feed, arguments.spread_feed_expiry) return expiring_web_socket_feed else: return EmptyFeed()
def create_control_feed(arguments) -> Feed: if arguments.control_feed: web_socket_feed = WebSocketFeed(arguments.control_feed, 5) expiring_web_socket_feed = ExpiringFeed(web_socket_feed, arguments.control_feed_expiry) return expiring_web_socket_feed else: return FixedFeed({'canBuy': True, 'canSell': True})
def _create_price_feed(price_feed_argument: str, price_feed_expiry_argument: int, tub: Optional[Tub]): assert(isinstance(price_feed_argument, str)) assert(isinstance(price_feed_expiry_argument, int)) assert(isinstance(tub, Tub) or tub is None) if price_feed_argument == 'eth_dai': # main price feed main_price_feed = GdaxPriceFeed(product_id="ETH-USD", expiry=price_feed_expiry_argument) # emergency price feed emergency_price_feed = AveragePriceFeed([SetzerPriceFeed('kraken', expiry=price_feed_expiry_argument), SetzerPriceFeed('gemini', expiry=price_feed_expiry_argument)]) if tub is not None: # last resort price feed last_resort_price_feed = TubPriceFeed(tub) price_feed = BackupPriceFeed([main_price_feed, emergency_price_feed, last_resort_price_feed]) else: price_feed = BackupPriceFeed([main_price_feed, emergency_price_feed]) elif price_feed_argument == 'btc_dai': return GdaxPriceFeed(product_id="BTC-USD", expiry=price_feed_expiry_argument) elif price_feed_argument == 'dai_eth': return ReversePriceFeed(PriceFeedFactory._create_price_feed('eth_dai', price_feed_expiry_argument, tub)) elif price_feed_argument == 'dai_btc': return ReversePriceFeed(PriceFeedFactory._create_price_feed('btc_dai', price_feed_expiry_argument, tub)) elif price_feed_argument == 'tub': if tub is not None: price_feed = TubPriceFeed(tub) else: raise Exception(f"'--price-feed tub' cannot be used as this keeper does not know about 'Tub'") elif price_feed_argument.startswith("fixed:"): price_feed = FixedPriceFeed(Wad.from_number(price_feed_argument[6:])) elif price_feed_argument.startswith("ws://") or price_feed_argument.startswith("wss://"): socket_feed = WebSocketFeed(price_feed_argument, 5) socket_feed = ExpiringFeed(socket_feed, price_feed_expiry_argument) price_feed = WebSocketPriceFeed(socket_feed) else: raise Exception(f"'--price-feed {price_feed_argument}' unknown") return price_feed
def _create_price_feed(price_feed_argument: str, price_feed_expiry_argument: int, tub: Optional[Tub]): assert(isinstance(price_feed_argument, str)) assert(isinstance(price_feed_expiry_argument, int)) assert(isinstance(tub, Tub) or tub is None) if price_feed_argument == 'eth_dai-pair': return GdaxPriceFeed(product_id="ETH-DAI", expiry=price_feed_expiry_argument) if price_feed_argument == 'eth_dai-pair-midpoint': return GdaxMidpointPriceFeed(product_id="ETH-DAI", expiry=price_feed_expiry_argument) if price_feed_argument == 'eth_dai': return GdaxPriceFeed(product_id="ETH-USD", expiry=price_feed_expiry_argument) elif price_feed_argument == 'eth_dai-setzer': return AveragePriceFeed([SetzerPriceFeed('kraken', expiry=price_feed_expiry_argument), SetzerPriceFeed('gemini', expiry=price_feed_expiry_argument)]) elif price_feed_argument == 'eth_rub-setzer': return SetzerPriceFeed('ETHRUB', expiry=price_feed_expiry_argument) elif price_feed_argument == 'mdt_rub-setzer': return SetzerPriceFeed('MDTRUB', expiry=price_feed_expiry_argument) elif price_feed_argument == 'mdt_mcr-setzer': return SetzerPriceFeed('MDTMCR', expiry=price_feed_expiry_argument) elif price_feed_argument == 'eth_dai-tub': if tub is not None: price_feed = TubPriceFeed(tub) else: raise Exception(f"'--price-feed eth_dai-tub' cannot be used as this keeper does not know about 'Tub'") elif price_feed_argument == 'btc_dai': return GdaxPriceFeed(product_id="BTC-USD", expiry=price_feed_expiry_argument) elif price_feed_argument == 'dai_eth': return ReversePriceFeed(PriceFeedFactory._create_price_feed('eth_dai', price_feed_expiry_argument, tub)) elif price_feed_argument == 'dai_eth-pair': return ReversePriceFeed(PriceFeedFactory._create_price_feed('eth_dai-pair', price_feed_expiry_argument, tub)) elif price_feed_argument == 'dai_eth-setzer': return ReversePriceFeed(PriceFeedFactory._create_price_feed('eth_dai-setzer', price_feed_expiry_argument, tub)) elif price_feed_argument == 'dai_eth-tub': return ReversePriceFeed(PriceFeedFactory._create_price_feed('eth_dai-tub', price_feed_expiry_argument, tub)) elif price_feed_argument == 'dai_btc': return ReversePriceFeed(PriceFeedFactory._create_price_feed('btc_dai', price_feed_expiry_argument, tub)) elif price_feed_argument == 'zrx_usd-pair-midpoint': return GdaxMidpointPriceFeed(product_id="ZRX-USD", expiry=price_feed_expiry_argument) elif price_feed_argument == 'bat_usdc-pair-midpoint': return GdaxMidpointPriceFeed(product_id="BAT-USDC", expiry=price_feed_expiry_argument) elif price_feed_argument == 'dai_usdc-pair-midpoint': return GdaxMidpointPriceFeed(product_id="DAI-USDC", expiry=price_feed_expiry_argument) elif price_feed_argument == 'rep_usd-pair-midpoint': return GdaxMidpointPriceFeed(product_id="REP-USD", expiry=price_feed_expiry_argument) elif price_feed_argument.startswith("fixed:"): price_feed = FixedPriceFeed(Wad.from_number(price_feed_argument[6:])) elif price_feed_argument.startswith("ws://") or price_feed_argument.startswith("wss://"): socket_feed = WebSocketFeed(price_feed_argument, 5) socket_feed = ExpiringFeed(socket_feed, price_feed_expiry_argument) price_feed = WebSocketPriceFeed(socket_feed) else: raise Exception(f"'--price-feed {price_feed_argument}' unknown") return price_feed