3

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?

Mahrkeenerh
  • 1,104
  • 1
  • 9
  • 25
Dave
  • 15,639
  • 133
  • 442
  • 830
  • My guess would be - they have a minimal unit that you can buy or sell, and your order is then rounded to the lower value, leaving you with some extra original currency and a little less target currency. This doesn't really sound like a question for SO though. – Mahrkeenerh Nov 18 '21 at 11:27
  • I've been looking through the [Coinbase documentation](https://developers.coinbase.com/api/v2) and the [source code](https://github.com/danpaquin/coinbasepro-python). Since your buy was a limit order at this price *64262.83000000* did you get BTC at a lesser price? That is what it looks like based on *executed_value*. If so, that is the reason for the discrepancy. – Life is complex Nov 20 '21 at 23:26

1 Answers1

3

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

Life is complex
  • 15,374
  • 5
  • 29
  • 58
  • Even without the "fill_fees," how is the value of "executed_value" right? My size is 0.01556109, the price is 64262.83000000 . Multiply those two things together gives me 999.999681285 . This is not the same as "executed_value", above, which is 999.8760512847000000. Am I miscalculating something? – Dave Nov 18 '21 at 16:57
  • I don't think that you are miscalculating anything. I note in the Coinbase documentation that the order book is the true source for any transaction and that there can be a discrepancy in the buy response, based on time of execution. It makes no sense why there should be a discrepancy at all. – Life is complex Nov 19 '21 at 00:26
  • It's is unclear why the *executed_value* is off by 0.1236300003. Based on the documentation it seems that something changed in the milliseconds related to the buy and the response. Did the BTC price decrease by pennies in those milliseconds? Have you cross-referenced this *Buy Order* with your *Order Book*? – Life is complex Nov 19 '21 at 13:21
  • When I was reading the [trading rules](https://www.coinbase.com/legal/trading_rules) it seems that that *Order Book* will reflect the correct trade details. I'm still trying to determine what this means in relation to a *Limit Order* -- "Open orders may change state between the request and the response depending on market conditions." – Life is complex Nov 20 '21 at 17:18
  • I don't have experience on Coinbase but from my understanding, if your limit bid was above the current offer, then you pay the offer price not your limit price. It sounds like that may be what happened here: by the time the submitted bid registered the ask price had dropped marginally below the bid. If that's the case then your price would be `executed_value / filled_size` or about $64,254.885. – ramzeek Nov 24 '21 at 19:24
  • @wikikikitiki from my interpretation of *Limit Orders.* A buyer sets a buy price and the service (Coinbase) will either buy at that price or a lower one. I think the buy price was lower than the limit price. Again the *Order Book* has the true history of this trade. – Life is complex Nov 26 '21 at 14:12