コード例 #1
0
class SmartGasPrice(GasPrice):
    """
    DEPRACATED. This class is maintained for legacy support. All new development should utilize DynamicGasPrice below

    Simple and smart gas price scenario.
    Uses an EthGasStation feed. Starts with fast+10GWei, adding another 10GWei each 60 seconds
    up to fast+50GWei maximum. Falls back to a default scenario (incremental as well) if
    the EthGasStation feed unavailable for more than 10 minutes.
    """
    def __init__(self, api_key: None):
        self.gas_station = EthGasStation(refresh_interval=60,
                                         expiry=600,
                                         api_key=api_key)

    def get_gas_price(self, time_elapsed: int) -> Optional[int]:
        fast_price = self.gas_station.fast_price()
        if fast_price is not None:
            # start from fast_price + 10 GWei
            # increase by 10 GWei every 60 seconds
            # max is fast_price + 50 GWei
            return min(
                int(fast_price * 1.1) + int(time_elapsed / 60) *
                (10 * self.GWEI),
                int(fast_price * 1.1) + (50 * self.GWEI))
        else:
            # default gas pricing when EthGasStation feed is down
            return IncreasingGasPrice(initial_price=20 * self.GWEI,
                                      increase_by=10 * self.GWEI,
                                      every_secs=60,
                                      max_price=100 *
                                      self.GWEI).get_gas_price(time_elapsed)
コード例 #2
0
def test_ethgasstation_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)

    egs = EthGasStation(10, 600)

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

        standard_price = egs.standard_price()
        logging.info(standard_price)

        fast_price = egs.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)