def __init__(self, args: list, **kwargs): parser = argparse.ArgumentParser(prog='tethfinex-market-maker-keeper') parser.add_argument("--rpc-host", type=str, default="localhost", help="JSON-RPC host (default: `localhost')") parser.add_argument("--rpc-port", type=int, default=8545, help="JSON-RPC port (default: `8545')") parser.add_argument("--rpc-timeout", type=int, default=10, help="JSON-RPC timeout (in seconds, default: 10)") parser.add_argument( "--eth-from", type=str, required=True, help="Ethereum account from which to send transactions") parser.add_argument( "--eth-key", type=str, nargs='*', help= "Ethereum private key(s) to use (e.g. 'key_file=aaa.json,pass_file=aaa.pass')" ) parser.add_argument( "--exchange-address", type=str, required=True, help="Ethereum address of the 0x Exchange contract") parser.add_argument("--tub-address", type=str, required=False, help="Ethereum address of the Tub contract") parser.add_argument( "--tethfinex-api-server", type=str, default='https://api.ethfinex.com', help= "Address of the Trustless Ethfinex API server (default: 'https://api.ethfinex.com')" ) parser.add_argument( "--tethfinex-timeout", type=float, default=9.5, help="Timeout for accessing the IDEX API (in seconds, default: 9.5)" ) parser.add_argument( "--pair", type=str, required=True, help="Token pair (sell/buy) on which the keeper will operate") parser.add_argument("--config", type=str, required=True, help="Bands configuration file") parser.add_argument("--price-feed", type=str, required=True, help="Source of price feed") parser.add_argument( "--price-feed-expiry", type=int, default=120, help="Maximum age of the price feed (in seconds, default: 120)") parser.add_argument("--spread-feed", type=str, help="Source of spread feed") parser.add_argument( "--spread-feed-expiry", type=int, default=3600, help="Maximum age of the spread feed (in seconds, default: 3600)") parser.add_argument("--control-feed", type=str, help="Source of control feed") parser.add_argument( "--control-feed-expiry", type=int, default=86400, help="Maximum age of the control feed (in seconds, default: 86400)" ) parser.add_argument("--order-history", type=str, help="Endpoint to report active orders to") parser.add_argument( "--order-history-every", type=int, default=30, help= "Frequency of reporting active orders (in seconds, default: 30)") parser.add_argument("--gas-price", type=int, default=0, help="Gas price (in Wei)") parser.add_argument( "--smart-gas-price", dest='smart_gas_price', action='store_true', help= "Use smart gas pricing strategy, based on the ethgasstation.info feed" ) parser.add_argument("--ethgasstation-api-key", type=str, default=None, help="ethgasstation API key") parser.add_argument( "--refresh-frequency", type=int, default=3, help="Order book refresh frequency (in seconds, default: 3)") parser.add_argument("--debug", dest='debug', action='store_true', help="Enable debug output") parser.set_defaults(cancel_on_shutdown=False, withdraw_on_shutdown=False) self.arguments = parser.parse_args(args) setup_logging(self.arguments) self.web3 = kwargs['web3'] if 'web3' in kwargs else Web3( HTTPProvider( endpoint_uri= f"http://{self.arguments.rpc_host}:{self.arguments.rpc_port}", request_kwargs={"timeout": self.arguments.rpc_timeout})) self.web3.eth.defaultAccount = self.arguments.eth_from self.our_address = Address(self.arguments.eth_from) register_keys(self.web3, self.arguments.eth_key) tub = Tub(web3=self.web3, address=Address(self.arguments.tub_address)) \ if self.arguments.tub_address is not None else None self.sai = ERC20Token(web3=self.web3, address=tub.sai()) self.price_feed = PriceFeedFactory().create_price_feed( self.arguments, tub) self.bands_config = ReloadableConfig(self.arguments.config) self.gas_price = GasPriceFactory().create_gas_price( self.web3, self.arguments) self.spread_feed = create_spread_feed(self.arguments) self.control_feed = create_control_feed(self.arguments) self.order_history_reporter = create_order_history_reporter( self.arguments) self.history = History() self.tethfinex_exchange = ZrxExchange( web3=self.web3, address=Address(self.arguments.exchange_address)) self.tethfinex_api = TEthfinexApi( self.tethfinex_exchange, self.arguments.tethfinex_api_server, timeout=self.arguments.tethfinex_timeout) config = self.tethfinex_api.get_config()['0x'] self.fee_address = Address(config['ethfinexAddress']) token_registry = config['tokenRegistry'] token_sell = self.token_sell() token_buy = self.token_buy() self.token_sell_wrapper = TEthfinexToken( self.web3, Address(token_registry[token_sell]['wrapperAddress']), token_sell) self.token_buy_wrapper = TEthfinexToken( self.web3, Address(token_registry[token_buy]['wrapperAddress']), token_buy) pair = self.pair() self.order_book_manager = OrderBookManager( refresh_frequency=self.arguments.refresh_frequency, max_workers=1) self.order_book_manager.get_orders_with( lambda: self.tethfinex_api.get_orders(pair)) self.order_book_manager.cancel_orders_with( lambda order: self.tethfinex_api.cancel_order(order.order_id)) self.order_book_manager.enable_history_reporting( self.order_history_reporter, self.our_buy_orders, self.our_sell_orders) self.order_book_manager.start()
from pymaker.keys import register_key_file from pymaker.zrx import ZrxExchange logging.basicConfig(format='%(asctime)-15s %(levelname)-8s %(message)s', level=logging.INFO) web3 = Web3( HTTPProvider("http://localhost:8545", request_kwargs={"timeout": 600})) web3.eth.defaultAccount = sys.argv[1] EXCHANGE_ADDRESS = Address("0xdcdb42c9a256690bd153a7b409751adfc8dd5851") DAI_ADDRESS = Address("0xd9ebebfdab08c643c5f2837632de920c70a56247") ETH_ADDRESS = Address("0xaa7427d8f17d87a28f5e1ba3adbb270badbe1011") FEE_ADDRESS = Address("0x61b9898c9b60a159fc91ae8026563cd226b7a0c1") dai_wrapper = TEthfinexToken(web3, DAI_ADDRESS, "DAI") # print(dai_wrapper.balance_of(Address(web3.eth.defaultAccount))) # print(dai_wrapper.deposit(Wad.from_number(15)).transact()) # print(dai_wrapper.balance_of(Address(web3.eth.defaultAccount))) # ethfinex_trustless = TEthfinexToken(web3, EXCHANGE_ADDRESS) zrx_exchange = ZrxExchange(web3=web3, address=EXCHANGE_ADDRESS) ethfinex_trustless_api = TEthfinexApi(zrx_exchange, 'https://api.ethfinex.com', 15.5) # print(ethfinex_trustless_api.get_symbols()) # print(ethfinex_trustless_api.get_config()) # placed_order = ethfinex_trustless_api.place_order(False, # DAI_ADDRESS, # Wad.from_number(86.4), # ETH_ADDRESS,
DAI_TOKEN_ADDRESS = Address(ethfinex_config['tokenRegistry']['DAI']['tokenAddress']) ETH_WRAPPER_ADDRESS = Address(ethfinex_config['tokenRegistry']['ETH']['wrapperAddress']) MKR_WRAPPER_ADDRESS = Address(ethfinex_config['tokenRegistry']['MKR']['wrapperAddress']) MKR_TOKEN_ADDRESS = Address(ethfinex_config['tokenRegistry']['MKR']['tokenAddress']) OMG_WRAPPER_ADDRESS = Address(ethfinex_config['tokenRegistry']['OMG']['wrapperAddress']) # DAI dai_token = ERC20Token(web3, DAI_TOKEN_ADDRESS) # you have to approve each token if it is its first time use dai_approve = dai_token.approve(DAI_WRAPPER_ADDRESS) print(dai_approve.transact()) dai_wrapper = TEthfinexToken(web3, DAI_WRAPPER_ADDRESS, "DAI") # lock token amount on wrapper dai_transact = dai_wrapper.deposit(Wad.from_number(0.40), 1) print(dai_transact.transact()) print(dai_wrapper.balance_of(Address(web3.eth.defaultAccount))) # MKR mkr_token = ERC20Token(web3, MKR_TOKEN_ADDRESS) mkr_approve = mkr_token.approve(MKR_WRAPPER_ADDRESS) print(mkr_approve.transact()) mkr_wrapper = TEthfinexToken(web3, MKR_WRAPPER_ADDRESS, "MKR") # lock token mkr_transact = mkr_wrapper.deposit(Wad.from_number(0.001), 1) print(mkr_transact.transact()) print(mkr_wrapper.balance_of(Address(web3.eth.defaultAccount)))