Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: RoxxR on May 20, 2022, 08:34:21 AM



Title: Getting fee ranges for unconfirmed transactions, a la mempool.space
Post by: RoxxR on May 20, 2022, 08:34:21 AM
Does anyone know how of a mempool.space alternative, or a Python script, to calculate the fee ranges in the next few blocks (highlighted in red in this screenshot)?

https://i.imgur.com/Uo90IPq_d.png?maxwidth=760&fidelity=grand


Title: Re: Getting fee ranges for unconfirmed transactions, a la mempool.space
Post by: NeuroticFish on May 20, 2022, 09:51:48 AM
If you have your own mempool, maybe consecutive calls of estimatesmartfee (https://bitcoincore.org/en/doc/0.16.0/rpc/util/estimatesmartfee/) with increasing (or decreasing) parameter would do.
Or you can find web based mempools that allow API calls like https://mempool.space/api/v1/fees/mempool-blocks and parse/interpret the results, just make sure you're within the allowed amount of API calls for the platform(s).


Title: Re: Getting fee ranges for unconfirmed transactions, a la mempool.space
Post by: ranochigo on May 20, 2022, 02:03:05 PM
You can parse the mempool yourself if you require such data. The range of fees are not fee estimations but rather the range of fees in each segment. If I remember correctly, and from the looks of it they use the range of transaction fee rates within each segment of the mempool. I don't think they account for the growth rate of the mempool with respect to time so take the accuracy of it with a grain of salt (if you're estimating the fees of course).

Anyways, I'm not aware of any current implementations that does things like this. As mentioned, estimatesmartfee is the way to go. If you cannot work with that, then something that could work would be to dump the mempool (getrawmempool), organize the transactions in descending order. Then segment the transactions according to the size, get the boundaries of each segment and you're done.  This shouldn't be too difficult to do, might have some time to do it in the coming weeks but no guarantees.

Edit: There's mempool.observer as well as jochen-hoenicke.de/queue but they are both visual representation.


Title: Re: Getting fee ranges for unconfirmed transactions, a la mempool.space
Post by: n0nce on May 20, 2022, 10:03:46 PM
I needed something like this for my LED Bitcoin Dashboard [weekend project] (https://bitcointalk.org/index.php?topic=5393177.0) and opted to simply use mempool.space's API for it. While I do have a full node on the same network, it was easier and faster to just use an online REST API than building something more custom - after all, it was a weekend project. ;)

The API endpoint I use to get the recommended fee:
Code:
https://mempool.space/api/v1/fees/recommended

Here you have their full API documentation:
https://mempool.space/docs/api/rest

Endpoint for recommended fees:
Endpoint
GET /api/v1/fees/recommended (https://mempool.space/api/v1/fees/recommended)

Description
Returns our currently suggested fees for new transactions.

Code Example
Code:
curl -sSL "https://mempool.space/api/v1/fees/recommended"
Response
Code:
{
  fastestFee: 1,
  halfHourFee: 1,
  hourFee: 1,
  minimumFee: 1
}


Title: Re: Getting fee ranges for unconfirmed transactions, a la mempool.space
Post by: ranochigo on May 23, 2022, 02:28:53 PM
-snip-
I think those are the floating fee estimation which would be okay if OP is trying to estimate the fees for their transactions. I think OP is trying to get the range of fees, mempool.space also offers an API call for that: https://mempool.space/api/v1/fees/mempool-blocks(https://mempool.space/docs/api/rest#get-mempool-blocks-fees). The extremes of each block denotes the range of fees included in that estimated block.


Title: Re: Getting fee ranges for unconfirmed transactions, a la mempool.space
Post by: bitmover on May 23, 2022, 03:19:48 PM
Does anyone know how of a mempool.space alternative, or a Python script, to calculate the fee ranges in the next few blocks (highlighted in red in this screenshot)?


A simple python script using requests library and mempool.space data:

Code:
import requests

r = requests.get('https://mempool.space/api/v1/fees/recommended')

r.status_code
# 200

r.json()
# {'fastestFee': 17, 'halfHourFee': 10, 'hourFee': 1, 'minimumFee': 1}

r.json()['fastestFee']
#17

fastestFee next block
halfHourFee 3 blocks
hourFee 6 blocks


Edit: There's mempool.observer as well as jochen-hoenicke.de/queue but they are both visual representation.
I also made one visual representation (https://bitcoindata.science/plot-your-transaction-in-mempool.html) , few years ago.