user1380: Having this Graphql query I know how many blocks this pool has produced on this epoch.
query stakePoolById($poolId: StakePoolID!) #$epochId: Int
{
  stakePools(where: { id: { _eq: $poolId } }) {
    url
    margin
    fixedCost
    blocks {
      epoch {
        number
        fees
      }
    }
  }
}

The problem is that I don't know how much a pool get for each block produced. I guess that knowing that constant I can sum all the blocks produced and subtract the margin and the fixedCost.
Is this the right approach?

user103: It is not a per-block constant. Reward calculation certainly is based on the number of blocks a pool makes, but along with a set of parameters and complex algorithm.
The reward calculation is done based on the below params,

the monetary expansion ratio
fees collected during an epoch
TAU - the percentage of rewards to go into the treasury
slot-co-eff and number of slots per epoch
total number of blocks minted by all pools in an epoch
total stake in the epoch by all pools
total stake controlled by a pool
pledge of the stake pool

Plus, the calculation also includes all these parameters based on epoch snapshots. The full calculation is quite big. But I hope I could give you a path to start with. You can find the documentation regarding the same at the below link,
https://docs.cardano.org/en/latest/explore-cardano/understanding-pledging-and-rewards.html
Also, these parameters and snapshots are not available in graphQL, you can use ledger state dump for rewards calculation.

1380: <p>Having this Graphql query I know how many blocks this pool has produced on this epoch.</p>
<pre><code>query stakePoolById($poolId: StakePoolID!) #$epochId: Int
{
  stakePools(where: { id: { _eq: $poolId } }) {
    url
    margin
    fixedCost
    blocks {
      epoch {
        number
        fees
      }
    }
  }
}
</code></pre>
<p>The problem is that I don't know how much a pool get for each block produced. I guess that knowing that constant I can sum all the blocks produced and subtract the margin and the fixedCost.</p>
<p>Is this the right approach?</p>
 103: <p>It is not a per-block constant. Reward calculation certainly is based on the number of blocks a pool makes, but along with a set of parameters and complex algorithm.</p>
<p>The reward calculation is done based on the below params,</p>
<ol>
<li>the monetary expansion ratio</li>
<li>fees collected during an epoch</li>
<li>TAU - the percentage of rewards to go into the treasury</li>
<li>slot-co-eff and number of slots per epoch</li>
<li>total number of blocks minted by all pools in an epoch</li>
<li>total stake in the epoch by all pools</li>
<li>total stake controlled by a pool</li>
<li>pledge of the stake pool</li>
</ol>
<p>Plus, the calculation also includes all these parameters based on epoch snapshots. The full calculation is quite big. But I hope I could give you a path to start with. You can find the documentation regarding the same at the below link,</p>
<p><a href="https://docs.cardano.org/en/latest/explore-cardano/understanding-pledging-and-rewards.html" rel="nofollow noreferrer">https://docs.cardano.org/en/latest/explore-cardano/understanding-pledging-and-rewards.html</a></p>
<p>Also, these parameters and snapshots are not available in graphQL, you can use ledger state dump for rewards calculation.</p>
