How does the Python Coinbase Pro API calculate executed value of a limit order?

Viewed 494

I'm using the Coinbase Pro API Python SDK. I place a limit buy order like so ...

import cbpro
...
self._get_auth_client(account).place_limit_order(product_id=formatted_name,
                              side='buy',
                              price=fiat_price,
                              size=amount)

When it is filled, I get a result that looks like the below

{
    'id': '1eaa9934-ccef-489d-80d7-540e0b9ef62a', 
    'price': '64262.83000000', 
    'size': '0.01556109', 
    'product_id': 'BTC-USD', 
    'profile_id': 'bb05c122-e394-40a9-b183-60456a67b188', 
    'side': 'buy', 
    'type': 'limit', 
    'time_in_force': 'GTC', 
    'post_only': False, 
    'created_at': '2021-11-14T19:55:03.791866Z', 
    'done_at': '2021-11-14T19:55:08.990951Z', 
    'done_reason': 'filled', 
    'fill_fees': '1.5639532769270500', 
    'filled_size': '0.01556109', 
    'executed_value': '999.8760512847000000', 
    'status': 'done', 
    'settled': True
}

What I don't understand is how do they calculate "executed_value"? Based on the amount purchased times the price minus the fees, (64262.83000000 * 0.01556109 - 1.5639532769270500) I would think the executed value would be 998.435728008, which is less than what is reported. What am I missing?

1 Answers

Based on my interpretation of your Buy API call and this sentence from the Coinbase documentation.

executed_value is the cumulative match size * price and is only present for orders placed after 2016-05-20.

It seems that the executed_value is correct for your trade, because the fill_fees isn't taken into consideration for the executed_value output.

When you query your Order Book you should see the fill_fees extracted from your buy order.

reference: https://help.coinbase.com/en/pro/trading-and-funding/orders/overview-of-order-types-and-settings-stop-limit-market

Related