<pre><code>    while amount &gt; 0:
        amount_i = int(mtgox_depth['bids'][index]['amount_int'])
        price_i = int(mtgox_depth['bids'][index]['price_int'])
        if amount_i &lt; amount:
            total_value += amount_i * price_i
            amount -= amount_i
        elif amount_i &gt;= amount:
            total_value += amount * price_i
            amount = 0
        index -= 1
    spot = int(total_value / float(total_amount))
    return spot
</code></pre>

<p>Something like this, where mtgox_depth is a json object of <a href="https://mtgox.com/api/1/BTCUSD/depth?raw" rel="nofollow">https://mtgox.com/api/1/BTCUSD/depth?raw</a>, should work for you.</p>

CC BY-SA 3.0
2012-11-27T07:54:28.457Z
Thanks. I already use code like that right now, but it requires to the download the whole orderbook each time, so I hope there was some API to do this serverside.
Maestro
CC BY-SA 3.0
2012-11-27T17:35:13.117Z
Although I don't have the answer you want, be sure you're not *actually* downloading the whole order book. I believe that link I provided in the answer is only a partial order book, even as it is a lot of orders.
smickles
CC BY-SA 3.0
2012-11-25T23:15:28.167Z
2012-11-25T23:15:28.167Z
smickles
<p>I need to display at my website what a certain amount of Bitcoins will likely cost. I can fetch the latest price using the MtGox API and multiply it by the amount, but for large amounts this is inaccurate because the buy itself will move the price. The only other option seems to fetch the whole orderbook, and calculate it myself each time, but isn't there an API for this?</p>

CC BY-SA 3.0
2012-08-22T21:04:46.100Z
You might want to post this as a feature request for the XChange project in GitHub. See https://github.com/timmolter/XChange
Gary
CC BY-SA 3.0
2012-08-23T17:28:43.953Z
Unless you want to move really big amount of Bitcoins, the order itself shoudldn't move the Bitcoin price too much. You can always go for the current price +- some spread.
ThePiachu
<exchanges><json-rpc><exchange-rate><api><merchants>
Is there an API for price estimation?
Maestro
# Is there an API for price estimation?

(Asked by: username_0 on 2012-08-22)

I need to display at my website what a certain amount of Bitcoins will likely cost. I can fetch the latest price using the MtGox API and multiply it by the amount, but for large amounts this is inaccurate because the buy itself will move the price. The only other option seems to fetch the whole orderbook, and calculate it myself each time, but isn't there an API for this?

**Tags:** exchanges, json-rpc, exchange-rate, api, merchants

> **Comments:**
> **username_1**: You might want to post this as a feature request for the XChange project in GitHub. See https://github.com/timmolter/XChange  
> **username_2**: Unless you want to move really big amount of Bitcoins, the order itself shoudldn't move the Bitcoin price too much. You can always go for the current price +- some spread.  

---

## 1 answers

### Answer by username_3 on 2012-11-25. Score: 3

```
    while amount > 0:
        amount_i = int(mtgox_depth['bids'][index]['amount_int'])
        price_i = int(mtgox_depth['bids'][index]['price_int'])
        if amount_i < amount:
            total_value += amount_i * price_i
            amount -= amount_i
        elif amount_i >= amount:
            total_value += amount * price_i
            amount = 0
        index -= 1
    spot = int(total_value / float(total_amount))
    return spot

```

Something like this, where mtgox\_depth is a json object of <https://mtgox.com/api/1/BTCUSD/depth?raw>, should work for you.

> **Comments:**
> **username_0**: Thanks. I already use code like that right now, but it requires to the download the whole orderbook each time, so I hope there was some API to do this serverside.  
> **username_3**: Although I don't have the answer you want, be sure you're not *actually* downloading the whole order book. I believe that link I provided in the answer is only a partial order book, even as it is a lot of orders.  

---

