Σ

Price equations for Bitcoin advertisements

For most Bitcoin traders, adjusting the price of advertisements by setting a margin works well enough. But if you are a high volume trader the price equation feature allows you more control over your price. This guide explains the fundamentals on how you can use complex price equations to your advantage to beat the competition.

What is a price equation?

Price equations allow you to automatically update your price with the price fluctuations of Bitcoin. They work by taking price information that we automatically fetch from market data sources (Other Bitcoin exchanges) and updating the price of your advertisement as soon as new price information is fetched. To create a custom price equation you select your market data sources and combine or modify them using operators.

The default price equation we use for advertisements uses a special market data source called btc_in_usd and a simple multiplication operator to place a margin on top of the market data price.

The market data source btc_in_usd returns the median price from several different trusted exchanges. This means that even if one or many of the exchanges start giving erroneous information the price source will still give an accurate median price.

Advertisement prices are on average updated once every five minutes. When there is extra load on the service or if an API is slow to respond this process may take longer to run. The final price calculated from the price equation is for 1 BTC. Market data sources also always return the price for 1 BTC.

If the equation returns more than one value or no value, the equation is not valid and won't work. Market data sources may not always return a price if there is, for example, low to no recent volume in that market. If an equation is not valid or does not fully resolve the advertisement will be turned off automatically.

Make your own equation

Step 1: Choose your pricing sources

The first and most important part of your equation is the selection of market price source(s). You should carefully choose which exchange you base your price on, you can find a list of all available market sources at the end of this guide. A simple equation only uses one market data source, the below market source takes the 24 hour average price from the Bitcoin exchange Bitstamp:

bitstampusd_avg

This is already on it's own a working equation, but to make some profit selling Bitcoin you will want to modify this with an operator.

Step 2: Use operators to modify your equation

Operators are different mathematical functions that you can use to adjust and change your price equation to fit your own needs. You can see the operators that are supported in the table below.


Operator Example equation Example value Description
+ 1 + 1 2 Add two values together
- 5 - 1 4 Subtract the right value from the left one
* 2 * 5 10 Multiply two values
/ 5 / 2 2.5 Divide the left value by the right one
min min(25, 100)
25 Minimum gives returns the smaller of the two values inside the parenthesis. You can chain min() inside another to get the smallest value of multiple numbers. e.g.
min(min(25, 100), min(20, 300)) = 20
max max(25, 100)
100 Maximum gives returns the larger of the two values inside the parenthesis. You can chain max() inside another to get the largest value of multiple numbers. e.g.
max(max(25, 100), max(20, 300)) = 300


The simplest equation ads just a percentage markup on top of the market price. To add, for example, a 12% margin on top of the price you need to multiply the market price source by 1.12 to increase the price by 12%. The resulting equation looks like this:

bitstampusd_avg*1.12

If you buy your Bitcoin that you sell from two different exchanges, let's say Bitstamp and Bitfinex, you probably want to make sure that your Bitcoin price is based off of the exchange that has the higher price so that your margin stays correct. Using two market data sources has the added benefit of protecting you in case one exchange experiences a sudden price crash while the other doesn't.

To do this the max() operator is useful. It is used to choose the larger of two values given to it. To use the max() operator you enter two values separated by a comma into the parenthesis. The values entered can be a market data source or any number.

In our example we want to use the higher price of two different exchanges, Bitstamp and Bitfinex. First we search for their market data source name from the table below and then we add _avg after the market data source name to get the 24h average price. We then multiply the whole max() operator with 1.12 to add our margin:

max(bitstampusd_avg, bitfinexusd_avg)*1.12

This equation will first fetch pricing data from the two exchanges, Bitfinex and Bitstamp, and turn it into two numbers. The max() operator then selects the more expensive price of the two. Finally, it multiplies that price with 1.12 to get the final advertisement price.

Step 3: Convert the price to your own currency

If you're using a price source that is not in your own currency the final step is to convert it to the correct currency. For this, you can convert the price from USD to another currency using the USD_in_[currency] data source. For example, if I trade in Euros I would need to convert the example equation in the Step 2 from USD to EUR by multiplying the whole equation by USD_in_EUR. The resulting equation looks like this:

max(bitstampusd_avg, bitfinexusd_avg)*1.12*USD_in_EUR

You can find a list of all of the USD exchange rate sources further down on this page.

Test your equation

You can play around with your own equations using the field below. Choose which currency you trade in and enter any equation to see what the price would be.

Market price sources

We have hundreds of market data sources available to use in your price equations. Here is a table that lists all available market data sources. For most sources we fetch six different prices: high, low, bid, ask, close, and avg. We recommend you use the avg (average) price, the other price types have specific meaning and fluctuate often and can result in your price not being what you expect. Each market data source always gives the price for one whole Bitcoin, this table shows the current price returned from each market data source and price type.

In order to use the market price sources you need to take the data source name from the market column and add to it the price type.
For example, if you want to use the average bitfinexusd price you take the name of the market and add an underline and the text avg.

bitfinexusd_avg

high The highest price of completed trade during the last 24h.
low The lowest price of completed trade during the last 24h.
bid The bid price is the highest price that a buyer is willing to pay.
ask The ask price is the lowest price that a seller is willing to accept.
close The price of the latest completed trade.
avg The average price of completed trades for the last 24 hours.


Market high low bid ask close avg
coinbaseusd 68,576.57 62,949.71 63,678.10
krakenusd 68,075.00 63,010.00 63,648.60 63,652.70 63,640.10 65,895.46
bitstampusd 68,569.00 62,900.00 63,635.00 63,657.00 63,647.00 66,088.00
bitfinexusd 68,574.00 63,036.00 63,637.00 63,650.00 63,612.00 63,643.50
geminiusd 63,603.00 63,662.41 63,683.72
bitvavoeur 62,958.00 57,903.00 58,695.00 58,699.00 58,696.00
krakeneur 62,600.00 58,018.10 58,690.70 58,692.50 58,705.30 60,225.66
coinbaseeur 62,996.23 57,900.02 58,683.77
bitstampeur 62,968.00 57,983.00 58,689.00 58,712.00 58,689.00 60,591.00

Altcoin market price

If you want to trade your bitcoins for altcoins we provide market sources that return the price for one whole Bitcoin in the other cryptocurrency. Below you can find a table that lists all available altcoin market data sources. We fetch three different prices: bid, ask, and close. This table shows the latest price returned from each market data source and price type.

In order to use the market price sources you need to take the data source name from the market column and add to it the price type.
For example, if you want to use the close poloniexeth price you take the name of the market and add an underline and the text close.

poloniexeth_close

bid The bid price is the highest price that a buyer is willing to pay.
ask The ask price is the lowest price that a seller is willing to accept.
close The price of the latest completed trade.


Market close bid ask

USD exchange rates

You can get the exchange rate of 1 USD in other currencies using these data sources. To convert a price from USD simply multiply it with the correct USD_in data source. To convert other currencies into USD, get the inverse e.g. 1/USD_in_EUR and multiply it with your price.

Exchange rate data sources

Altcoin exchange rate data sources