コード例 #1
0
ファイル: gas.py プロジェクト: cdyfng/auction-keeper
 def __init__(self, arguments):
     self.gas_station = None
     if arguments.ethgasstation_api_key:
         self.gas_station = EthGasStation(
             refresh_interval=60,
             expiry=600,
             api_key=arguments.ethgasstation_api_key)
     elif arguments.etherchain_gas:
         self.gas_station = EtherchainOrg(refresh_interval=60, expiry=600)
     elif arguments.poanetwork_gas:
         self.gas_station = POANetwork(refresh_interval=60,
                                       expiry=600,
                                       alt_url=arguments.poanetwork_url)
コード例 #2
0
    def __init__(self,
                 refresh_interval: int,
                 expiry: int,
                 ethgasstation_api_key=None,
                 poa_network_alt_url=None,
                 etherscan_api_key=None,
                 gasnow_app_name="pygasprice-client"):
        self.clients = [
            EthGasStation(refresh_interval=refresh_interval,
                          expiry=expiry,
                          api_key=ethgasstation_api_key),
            EtherchainOrg(refresh_interval=refresh_interval, expiry=expiry),
            POANetwork(refresh_interval=refresh_interval,
                       expiry=expiry,
                       alt_url=poa_network_alt_url),
            Etherscan(refresh_interval=refresh_interval,
                      expiry=expiry,
                      api_key=etherscan_api_key),
            Gasnow(refresh_interval=refresh_interval,
                   expiry=expiry,
                   app_name=gasnow_app_name)
        ]
        self._safe_low_price = None
        self._standard_price = None
        self._fast_price = None
        self._fastest_price = None

        super().__init__("aggregator", refresh_interval, expiry)
コード例 #3
0
ファイル: gas.py プロジェクト: latetot/thrifty-keeper
 def __init__(self, arguments):
     self.gas_station = None
     self.fixed_gas = None
     if arguments.ethgasstation_api_key:
         self.gas_station = EthGasStation(refresh_interval=60, expiry=600, api_key=arguments.ethgasstation_api_key)
     elif arguments.etherchain_gas:
         self.gas_station = EtherchainOrg(refresh_interval=60, expiry=600)
     elif arguments.poanetwork_gas:
         self.gas_station = POANetwork(refresh_interval=60, expiry=600, alt_url=arguments.poanetwork_url)
     elif arguments.fixed_gas_price:
         self.fixed_gas = int(round(arguments.fixed_gas_price * self.GWEI))
     self.initial_multiplier = arguments.gas_initial_multiplier
     self.reactive_multiplier = arguments.gas_reactive_multiplier
     self.gas_maximum = int(round(arguments.gas_maximum * self.GWEI))
     if self.fixed_gas:
         assert self.fixed_gas <= self.gas_maximum
コード例 #4
0
ファイル: gas.py プロジェクト: reflexer-labs/auction-keeper
 def __init__(self, arguments, web3: Web3):
     assert isinstance(web3, Web3)
     self.gas_station = None
     self.fixed_gas = None
     self.web3 = web3
     if arguments.ethgasstation_api_key:
         self.gas_station = EthGasStation(refresh_interval=60, expiry=600, api_key=arguments.ethgasstation_api_key)
     elif arguments.etherchain_gas:
         self.gas_station = EtherchainOrg(refresh_interval=60, expiry=600)
     elif arguments.poanetwork_gas:
         self.gas_station = POANetwork(refresh_interval=60, expiry=600, alt_url=arguments.poanetwork_url)
     elif arguments.etherscan_gas:
         if arguments.etherscan_key:
             self.gas_station = Etherscan(refresh_interval=60, expiry=600, api_key=arguments.etherscan_key)
         else:
             self.gas_station = Etherscan(refresh_interval=60, expiry=600)
     elif arguments.gasnow_gas:
         if arguments.gasnow_app_name:
             self.gas_station = GasNow(refresh_interval=60, expiry=600, app_name=arguments.gasnow_app_name)
         else:
             self.gas_station = GasNow(refresh_interval=60, expiry=600)
     elif arguments.fixed_gas_price:
         self.fixed_gas = int(round(arguments.fixed_gas_price * self.GWEI))
     self.initial_multiplier = arguments.gas_initial_multiplier
     self.reactive_multiplier = arguments.gas_reactive_multiplier
     self.gas_maximum = int(round(arguments.gas_maximum * self.GWEI))
     if self.fixed_gas:
         assert self.fixed_gas <= self.gas_maximum
コード例 #5
0
ファイル: gas.py プロジェクト: monolithos/auction-keeper
class DynamicGasPrice(GasPrice):

    GWEI = 1000000000

    def __init__(self, arguments):
        self.gas_station = None
        self.fixed_gas = None
        if arguments.ethgasstation_api_key:
            self.gas_station = EthGasStation(
                refresh_interval=60,
                expiry=600,
                api_key=arguments.ethgasstation_api_key)
        elif arguments.etherchain_gas:
            self.gas_station = EtherchainOrg(refresh_interval=60, expiry=600)
        elif arguments.poanetwork_gas:
            self.gas_station = POANetwork(refresh_interval=60,
                                          expiry=600,
                                          alt_url=arguments.poanetwork_url)
        elif arguments.fixed_gas_price:
            self.fixed_gas = int(round(arguments.fixed_gas_price * self.GWEI))
        self.initial_multiplier = arguments.gas_initial_multiplier
        self.reactive_multiplier = arguments.gas_reactive_multiplier
        self.gas_maximum = int(round(arguments.gas_maximum * self.GWEI))
        if self.fixed_gas:
            assert self.fixed_gas <= self.gas_maximum

    def get_gas_price(self, time_elapsed: int) -> Optional[int]:
        # start with fast price from the configured gas API
        fast_price = self.gas_station.fast_price(
        ) if self.gas_station else None

        # if API produces no price, or remote feed not configured, start with a fixed price
        if fast_price is None:
            initial_price = self.fixed_gas if self.fixed_gas else 10 * self.GWEI
        # otherwise, use the API's fast price, adjusted by a coefficient, as our starting point
        else:
            initial_price = int(round(fast_price * self.initial_multiplier))

        return GeometricGasPrice(
            initial_price=initial_price,
            every_secs=30,
            coefficient=self.reactive_multiplier,
            max_price=self.gas_maximum).get_gas_price(time_elapsed)

    def __str__(self):
        retval = ""
        if self.gas_station:
            retval = f"{type(self.gas_station)} fast gas price with initial multiplier {self.initial_multiplier} "
        elif self.fixed_gas:
            retval = f"Fixed gas price {round(self.fixed_gas / self.GWEI, 1)} Gwei "
        else:
            retval = f"Default gas 10 Gwei "

        retval += f"and will multiply by {self.reactive_multiplier} every 30s to a maximum of " \
                  f"{round(self.gas_maximum / self.GWEI, 1)} Gwei"
        return retval

    def __repr__(self):
        return f"DynamicGasPrice({pformat(vars(self))})"
コード例 #6
0
ファイル: gas.py プロジェクト: cdyfng/auction-keeper
class DynamicGasPrice(GasPrice):

    GWEI = 1000000000

    def __init__(self, arguments):
        self.gas_station = None
        if arguments.ethgasstation_api_key:
            self.gas_station = EthGasStation(
                refresh_interval=60,
                expiry=600,
                api_key=arguments.ethgasstation_api_key)
        elif arguments.etherchain_gas:
            self.gas_station = EtherchainOrg(refresh_interval=60, expiry=600)
        elif arguments.poanetwork_gas:
            self.gas_station = POANetwork(refresh_interval=60,
                                          expiry=600,
                                          alt_url=arguments.poanetwork_url)

    def get_gas_price(self, time_elapsed: int) -> Optional[int]:
        # start with standard price plus backup in case gas price API is down, then do fast
        if 0 <= time_elapsed <= 60:
            standard_price = self.gas_station.standard_price(
            ) if self.gas_station else None

            if standard_price is not None:
                return int(standard_price * 1.1)
            else:
                return self.default_gas_pricing(time_elapsed)

        # move to fast after a minute
        else:
            fast_price = self.gas_station.fast_price(
            ) if self.gas_station else None

            if fast_price is not None:
                return int(fast_price * 1.1)
            else:
                return self.default_gas_pricing(time_elapsed)

    # default gas pricing when EthGasStation feed is down
    def default_gas_pricing(self, time_elapsed: int):
        return IncreasingGasPrice(initial_price=5 * self.GWEI,
                                  increase_by=10 * self.GWEI,
                                  every_secs=60,
                                  max_price=100 *
                                  self.GWEI).get_gas_price(time_elapsed)
コード例 #7
0
    def __init__(self, refresh_interval: int, expiry: int, ethgasstation_api_key=None, poa_network_alt_url=None,
                 etherscan_api_key=None, blocknative_api_key=None):
        self.clients = [
            EthGasStation(refresh_interval=refresh_interval, expiry=expiry, api_key=ethgasstation_api_key),
            EtherchainOrg(refresh_interval=refresh_interval, expiry=expiry),
            POANetwork(refresh_interval=refresh_interval, expiry=expiry, alt_url=poa_network_alt_url),
            Etherscan(refresh_interval=refresh_interval, expiry=expiry, api_key=etherscan_api_key)
        ]
        if blocknative_api_key:
            self.clients.append(Blocknative(refresh_interval=refresh_interval, expiry=expiry, api_key=blocknative_api_key))

        super().__init__("aggregator", refresh_interval, expiry)
コード例 #8
0
def test_poanetwork_integration():
    logging.basicConfig(format='%(asctime)-15s %(levelname)-8s %(message)s', level=logging.DEBUG)
    logging.getLogger('urllib3.connectionpool').setLevel(logging.INFO)
    logging.getLogger('requests.packages.urllib3.connectionpool').setLevel(logging.INFO)

    poa = POANetwork(10, 600)

    while True:
        safe_low_price = poa.safe_low_price()
        logging.info(safe_low_price)

        standard_price = poa.standard_price()
        logging.info(standard_price)

        fast_price = poa.fast_price()
        logging.info(fast_price)

        if safe_low_price is not None and standard_price is not None and fast_price is not None:
            break

        time.sleep(1)
コード例 #9
0
def test_custom_poa_url():
    local_poa = POANetwork(10, 600, "http://127.0.0.1:8000")
    assert local_poa.URL == "http://127.0.0.1:8000"

    local_poa = POANetwork(10, 600)
    assert local_poa.URL == "https://gasprice.poa.network"