Esempio n. 1
0
class SmartGasPrice(GasPrice):
    """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.
    """

    GWEI = 1000000000

    def __init__(self):
        self.gas_station = EthGasStation(refresh_interval=60, expiry=600)

    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=50 * self.GWEI,
                                      increase_by=10 * self.GWEI,
                                      every_secs=60,
                                      max_price=100 *
                                      self.GWEI).get_gas_price(time_elapsed)
Esempio n. 2
0
class SmartGasPrice(GasPrice):
    """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.
    """

    GWEI = 1000000000

    def __init__(self):
        self.gas_station = EthGasStation(refresh_interval=60, expiry=600)

    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=50*self.GWEI,
                                      increase_by=10*self.GWEI,
                                      every_secs=60,
                                      max_price=100*self.GWEI).get_gas_price(time_elapsed)
Esempio n. 3
0
 def __init__(self):
     self.gas_station = EthGasStation(refresh_interval=60, expiry=600)
Esempio n. 4
0
 def __init__(self):
     self.gas_station = EthGasStation(refresh_interval=60, expiry=600)