ofek / bit

Bitcoin made easy.
https://ofek.dev/bit/
MIT License
1.25k stars 216 forks source link

Change fee provider #155

Closed NateNate60 closed 2 years ago

NateNate60 commented 3 years ago

This pull request changes the fee provider from bitcoinfees.earn.com to mempool.space and fixes #152.

The current fee provider (bitcoinfees.earn.com) is often suggesting network fees that are an order of magnitude greater than providers such as Blockchair, Blockstream, Mempool.space, as well as Bitcoin Core. This is unnecessarily wasteful, and even the "slow" network fee is high enough to be a next-block confirmation fee, usually actually two or three times more than the prevailing next-block fee.

I selected Mempool.space because of its seemingly unlimited API limit. At least, I didn't run into its API limit during testing.

NateNate60 commented 3 years ago

I looked into these providers:

Blockchair

https://api.blockchair.com/stats

The desired information is in data["bitcoin"]["data"]["suggested_transaction_fee_per_byte_sat"]. Here's a function that will return its recommended feerate, in sat/B:

def get_fee () -> int :
    return requests.get(URL).json()['data']["bitcoin"]["data"]["suggested_transaction_fee_per_byte_sat"]

During testing, I hit the API limit, so I didn't investigate further.

Blockstream

https://blockstream.info/api/fee-estimates

Returns information in terms of in how many blocks you want the transaction to confirm. Returns float by default so we must cast to int

def get_fee(fast: bool = True) -> int :
    return int(requests.get(URL).json()['1' if fast else '6'])

Blockchain.info

https://api.blockchain.info/mempool/fees

def get_fee(fast:bool = True) -> int :
    return requests.get(URL).json()['priority' if fast else 'regular']
ofek commented 3 years ago

@NateNate60 Thanks!

@bjarnemagnussen wdyt?