<p>It took quite a bit of thinking, but here is how you arrive at a "buy instantly" or "sell instantly" price.</p>

<p>Lets say you have buy orders:</p>

<ol>
<li>buy 100LTC at 5BTC</li>
<li>buy 50LTC at 4BTC</li>
<li>buy 200LTC at 3BTC</li>
</ol>

<p>And sell orders:</p>

<ol>
<li>sell 100LTC at 6BTC</li>
<li>sell 500LTC at 7BTC</li>
<li>sell 100LTC at 8BTC</li>
</ol>

<p>and so on. </p>

<p>We can gain a lot from this simple set of orders. For one, the market depth chart becomes very useful when looking at this data. So, you could say that the market spread is 1BTC in this case, because buy and sell orders are separated by 1BTC</p>

<p>Now, lets say we have 125LTC we want to sell. The way you would pick the best sell instant price is to look at the buy orders. Looks like you could sell your first 100LTC at 5BTC and the remaining 25LTC at 4BTC. So, 5BTC should be your max rate. Depending on the API you are using, you might want to place two separate orders at different prices or place one with the max price assumed. </p>

<p>It works the same way with buying. IF you want to buy 650LTC, you would be able to buy the first 100LTC at 6BTC, and then the next 500LTC at 7BTC and the last 50LTC at 8BTC. So, your max price would be 8BTC. Although your actual price would vary quite a lot. It depends on what service and API you're using as to how to best place such an order spanning prices. </p>

<p>For Cryptsy you would place such a buy order as just one order of 650LTC at 8BTC. Crypsty automatically chooses the best price for you, so you would have this effect. However, it's not guaranteed to work this way. If you got the order list, and someone was to buy up 50BTC at 6BTC, then your expected price would end up being wrong. If you want a price guarantee, you should place exact matching orders to the order book. Following this method though, you have a high likelyhood of an order not completing as well, or taking longer than expected, such as if you buy 100LTC at 6BTC, but someone bought 50LTC already. Crypsty by default would wait a while before completing the partial order. (assuming no other sell orders were placed at that price) </p>

<p>It's actually a really simple concept, but it took me a few days to actually wrap my head around it for some reason. Hopefully if other people have the same problem, maybe this post will clear things up for them</p>

CC BY-SA 3.0
2014-02-03T21:50:21.823Z
2014-02-03T21:50:21.823Z
Earlz
<p>I had been thinking about this lately and haven't explored this option at ALL but I'm thinking out loud here because nobody has replied in 8 days.</p>

<p>So what if you took the average of the top orders 1 - 5, then the average of the top orders 2 - 6, the average of 3 - 7, ect. Out of THOSE orders you then calculated the average again to arrive at your sell point? The process could be repeated as nessecary to find an average of averages that hover around the top of the buy points.</p>

<p>Thoughts?</p>

CC BY-SA 3.0
2014-02-03T21:52:04.863Z
Look at my answer. The key is not just the price, but the volume of the order, and the volume that you are wanting to trad
Earlz
CC BY-SA 3.0
2014-02-03T21:27:50.960Z
2014-02-03T21:27:50.960Z
ChrisSavoie
<p>A market maker will always match orders. You must have someone who wants to buy at the price you wish to sell, and visa-versa. If you put in a low price to sell at, you aren't guaranteed to sell at that price. Granted, the market maker may fill other buy orders that are higher than what you are asking, but, again, it's not guaranteed.</p>

<p>The key to high-volume buy-sell bots is to look for volume. More volume means a bigger market and more opportunities to buy and sell. There are a number of websites, like <a href="https://www.cluedex.com/trends" rel="nofollow noreferrer">Cluedex.com</a>, that rank markets and determine which are trending at any given time, and also give some indication of momentum. Using this data, you can determine which markets you are more likely to trade more quickly. Then, it's just a matter of getting the bid/ask price and selling/buying on those prices. </p>

CC BY-SA 3.0
2018-04-05T06:50:04.650Z
2018-04-05T06:50:04.650Z
Laser-Lance
<p>I'm using the Cryptsy API with a bot. So far, my bot's problem is that when it decides it needs to buy or sell a coin (not just bitcoin), I always seem to compute a price that is way too low or high. The data I have access to is:</p>

<ol>
<li>The currently outstanding buy orders (though a few seconds old and without timestamps)</li>
<li>The currently outstanding sell orders</li>
<li>The previous 20 trades that were executed on the market</li>
</ol>

<p>From all of this data, is there an existing algorithm to compute a price that will almost always buy or sell? My bot's priority is to have fast trades(like, less than a minute for execution), even if the price is not the best. </p>

<p>Cryptsy themselves compute a pretty good number in their web UI (the default ask/bid price), but I don't see that value exposed in their API. Where does this ask/bid price come from? </p>

<p>For reference, I've tried a few things with little success</p>

<ol>
<li>Highest buy price/Lowest sell price -- This tends to catch outliers and results in me placing an overly optimistic bid that only one buyer/seller was willing to pay (and because my data is seconds old, apparently somone else picks it up) </li>
<li>An average of 3 lowest/highest -- This had the same problem with outliers</li>
<li>Lowest buy price/Highest sell price -- This is extremely pessimistic and results in me paying ridiculous prices that are unreasonable </li>
</ol>

<p>How can I compute a good ask/bid price from this set of data I have? </p>

<trading><market><bots><cryptsy>
Given a list of buy/sell orders and previous trades, compute a buy/sell price
Earlz
# Given a list of buy/sell orders and previous trades, compute a buy/sell price

(Asked by: username_0 on 2014-01-26)

I'm using the Cryptsy API with a bot. So far, my bot's problem is that when it decides it needs to buy or sell a coin (not just bitcoin), I always seem to compute a price that is way too low or high. The data I have access to is:

1. The currently outstanding buy orders (though a few seconds old and without timestamps)
2. The currently outstanding sell orders
3. The previous 20 trades that were executed on the market

From all of this data, is there an existing algorithm to compute a price that will almost always buy or sell? My bot's priority is to have fast trades(like, less than a minute for execution), even if the price is not the best.

Cryptsy themselves compute a pretty good number in their web UI (the default ask/bid price), but I don't see that value exposed in their API. Where does this ask/bid price come from?

For reference, I've tried a few things with little success

1. Highest buy price/Lowest sell price -- This tends to catch outliers and results in me placing an overly optimistic bid that only one buyer/seller was willing to pay (and because my data is seconds old, apparently somone else picks it up)
2. An average of 3 lowest/highest -- This had the same problem with outliers
3. Lowest buy price/Highest sell price -- This is extremely pessimistic and results in me paying ridiculous prices that are unreasonable

How can I compute a good ask/bid price from this set of data I have?

**Tags:** trading, market, bots, cryptsy


---

## 3 answers

### Answer by username_0 on 2014-02-03. Score: 0

It took quite a bit of thinking, but here is how you arrive at a "buy instantly" or "sell instantly" price.

Lets say you have buy orders:

1. buy 100LTC at 5BTC
2. buy 50LTC at 4BTC
3. buy 200LTC at 3BTC

And sell orders:

1. sell 100LTC at 6BTC
2. sell 500LTC at 7BTC
3. sell 100LTC at 8BTC

and so on.

We can gain a lot from this simple set of orders. For one, the market depth chart becomes very useful when looking at this data. So, you could say that the market spread is 1BTC in this case, because buy and sell orders are separated by 1BTC

Now, lets say we have 125LTC we want to sell. The way you would pick the best sell instant price is to look at the buy orders. Looks like you could sell your first 100LTC at 5BTC and the remaining 25LTC at 4BTC. So, 5BTC should be your max rate. Depending on the API you are using, you might want to place two separate orders at different prices or place one with the max price assumed.

It works the same way with buying. IF you want to buy 650LTC, you would be able to buy the first 100LTC at 6BTC, and then the next 500LTC at 7BTC and the last 50LTC at 8BTC. So, your max price would be 8BTC. Although your actual price would vary quite a lot. It depends on what service and API you're using as to how to best place such an order spanning prices.

For Cryptsy you would place such a buy order as just one order of 650LTC at 8BTC. Crypsty automatically chooses the best price for you, so you would have this effect. However, it's not guaranteed to work this way. If you got the order list, and someone was to buy up 50BTC at 6BTC, then your expected price would end up being wrong. If you want a price guarantee, you should place exact matching orders to the order book. Following this method though, you have a high likelyhood of an order not completing as well, or taking longer than expected, such as if you buy 100LTC at 6BTC, but someone bought 50LTC already. Crypsty by default would wait a while before completing the partial order. (assuming no other sell orders were placed at that price)

It's actually a really simple concept, but it took me a few days to actually wrap my head around it for some reason. Hopefully if other people have the same problem, maybe this post will clear things up for them


---

### Answer by username_1 on 2014-02-03. Score: 0

I had been thinking about this lately and haven't explored this option at ALL but I'm thinking out loud here because nobody has replied in 8 days.

So what if you took the average of the top orders 1 - 5, then the average of the top orders 2 - 6, the average of 3 - 7, ect. Out of THOSE orders you then calculated the average again to arrive at your sell point? The process could be repeated as nessecary to find an average of averages that hover around the top of the buy points.

Thoughts?

> **Comments:**
> **username_0**: Look at my answer. The key is not just the price, but the volume of the order, and the volume that you are wanting to trad  

---

### Answer by username_2 on 2018-04-05. Score: 0

A market maker will always match orders. You must have someone who wants to buy at the price you wish to sell, and visa-versa. If you put in a low price to sell at, you aren't guaranteed to sell at that price. Granted, the market maker may fill other buy orders that are higher than what you are asking, but, again, it's not guaranteed.

The key to high-volume buy-sell bots is to look for volume. More volume means a bigger market and more opportunities to buy and sell. There are a number of websites, like [Cluedex.com](https://www.cluedex.com/trends), that rank markets and determine which are trending at any given time, and also give some indication of momentum. Using this data, you can determine which markets you are more likely to trade more quickly. Then, it's just a matter of getting the bid/ask price and selling/buying on those prices.


---

