コード例 #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 __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 プロジェクト: 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
コード例 #4
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)
コード例 #5
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)
コード例 #6
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)
コード例 #7
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
コード例 #8
0
def test_ethgasstation_url():
    egs = EthGasStation(10, 600)
    assert egs.URL == "https://ethgasstation.info/json/ethgasAPI.json"

    egs = EthGasStation(10, 600, "abcdefg")
    assert egs.URL == "https://ethgasstation.info/json/ethgasAPI.json?api-key=abcdefg"
コード例 #9
0
 def __init__(self, api_key: None):
     self.gas_station = EthGasStation(refresh_interval=60,
                                      expiry=600,
                                      api_key=api_key)