Introduction
Market Alerts is a simple API to calculate market indicators and signals across different timeframes in Commodity, Bonds, Stock Indices and FX markets.
The API works in a REST like manner over HTTP, and covers these areas:
- Market Data
- Download historical open,high,low,close data for various instruments in different timeframes.
- Indicators
- Calculate different technical indicators
- RSI, Moving averages, MACD, Bollinger Bands, Average True Range, Minimum/Maximum/Previous period values.
- Calculate different technical indicators
- Signals
- Test for the existence of market signals, eg:
- close > ema(close,200) # Price closed above 200-day moving average
- crossoverup(rsi(close,14),70) # RSI just went above 70
- Test for the existence of market signals, eg:
Authentication
MarketAlerts is open for beta and does not currently require Authentication.
API Reference
indicators
See also the full indicator function reference
curl \
"http://api.fxhistoricaldata.com/indicators?expression=close,ema(close,200),rsi(close,14)&instruments=USDJPY"
# Example expressions
open,high,low,close
rsi(close,14)
ema(close,200)
rsi(ema(close,20),14)
The above command returns JSON structured like this:
{
results: {
USDJPY: {
data: [
[
"2016-10-07 00:00:00",
"103.1000",
"107.5165",
"57.80"
]
]
}
}
}
This endpoint retrieves market data and calculates technical indicators
HTTP Request
GET http://api.fxhistoricaldata.com/indicators
Query Parameters
Parameter | Required | Default | Description |
---|---|---|---|
expression | Yes | A comma separated list of technical indicators to be calculated. | |
instruments | Yes | A list of instruments for which to calculate the indicators expression. See the list of available instruments. | |
timeframe | No | day | The timeframe of the request. One of '5min', '15min', '30min', 'hour', '2hour', '3hour', '4hour', 'day'. See also available timeframes. |
item_count | No | 10 | The number of data items to return. |
signals
See also the full signal expression reference
curl \
"http://api.fxhistoricaldata.com/signals?expression=close>ema(close,200) and rsi(close,14)<50&s=USDJPY"
# Example expressions
rsi(close,14) > 70
close > ema(close,200)
# Mixed timeframes are also allowed in expressions
day(close > ema(close,200)) and 4hour(close < ema(close,200))
The above command returns JSON structured like this:
{
results: {
USDJPY: {
data: [
[
"2016-10-07 00:00:00"
]
]
}
}
}
This endpoint calculates signals ie: rsi crossed above 70, closing price is above upper bollinger band, etc
HTTP Request
GET http://api.fxhistoricaldata.com/signals
Query Parameters
Parameter | Required | Default | Description |
---|---|---|---|
expression | Yes | The signal expression to be evaluated. | |
instruments | Yes | A list of instruments for which to calculate the signal expression. See the list of available instruments. | |
timeframe | No | day | The timeframe of the request. One of '5min', '15min', '30min', 'hour', '2hour', '3hour', '4hour', 'day'. This is ignored if the expression uses multiple timeframe signals. See also available timeframes. |
item_count | No | 50 | The maximum number of data items to return. |
start_period | No | 3 months ago | A datetime in the UTC timezone representing the date of the earliest signal to be returned |
end_period | No | now | A datetime in the UTC timezone representing the date of the lastest signal to be returned |
Function reference
open,high,low,close
The open, high, low and closing price of the security in the given timeframe.
ema(expression, n)
ema(close,200)
ema(abs(high-low),20)
Exponential moving average of expression of n periods
sma(expression, n)
sma(close,200)
sma(abs(high-low),20)
Simple moving average of expression over n periods
rsi(expression, n)
rsi(close,14)
Relative strength index of expression over n periods
max(expression, n)
max(high,10)
Maximum value of expression over n periods
min(expression, n)
min(low,10)
Minimum value of expression over n periods
tr()
tr()
True range is defined as: max[ (high-low), abs(high - previous_close), abs(low - previous_close) ]
atr(n)
atr(14)
Average true range over n periods (eg: atr(14) )
previous(expression, n)
previous(close, 1)
Value of expression n periods ago, useful to calculate crossover signals
bolhigh(expression, n, y)
bolhigh(close,21,2)
Upper bollinger band of expression
bollow(expression, n, y)
bollow(close, 21, 2)
Lower bollinger band of expression
macd(expression, shortperiod, longperiod, smoothingperiod)
macd(close, 12, 26, 9)
Macd value of expression
macdsig(expression, shortperiod, longperiod, smoothingperiod)
macdsig(close, 12, 26, 9)
Macd signal value of expression
macddiff(expression, shortperiod, longperiod, smoothingperiod)
macddiff(close, 12, 26, 9)
Difference between macd and the macd signal (eg: macddiff(close, 12, 26, 9) )
abs(expression)
abs( close - previous(close,1) )
Returns absolute value of expression (eg: abs(close - previous(close, 1)) )
Signal reference
crossoverup(expression1,expression2)
crossoverup(close,ema(close,200))
True when expression1 goes above expression2.
crossoverdown(expression1,expression2)
crossoverdown(close,ema(close,200))
True when expression1 goes below expression2.
expression1 compare_to expression2
ema(close,50) > ema(close,200)
ema(close,50) >= ema(close,200)
ema(close,50) < ema(close,200)
ema(close,50) <= ema(close,200)
Compares expression1 to expression2, ie, greater, greater than, lesser, lesser than.
Multiple timeframe signals
day(close > ema(close,200)) and 4hour(close < ema(close,200))
Compare signals in different timeframes. When using expressions with multiple timeframe signals, the timeframe querystring parameter is ignored. The following timeframe functions are available:
- 5minute
- 15minute
- 30minute
- hour
- 2hour
- 3hour
- 4hour
- day
Limitations
Unique timeframe functions
This doesn't work
hour(close > ema(close,21)) and hour(ema(close,21) > ema(close,50)) and 2hour(close > ema(close,21))
But this does
hour(close > ema(close,21) and ema(close,21) > ema(close,50)) and 2hour(close > ema(close,21))
A timeframe function can only be called once per expression, however, multiple expressions can exist inside a timeframe function.
Boolean combinations
This doesn't work
hour(signal_expression) and 2hour(signal_expression) or hour(signal_expression)
But these do
hour(signal_expression) and 2hour(signal_expression) and hour(signal_expression)
hour(signal_expression) or 2hour(signal_expression) or hour(signal_expression)
Signal expressions with multiple timeframes are only supported when the different timeframe functions are joined by the same boolean operator (one of 'and','or').
Available timeframes
The list of timeframes available can be retrieved programmatically with a get request to the timeframes endpoint.
curl \
http://api.fxhistoricaldata.com/timeframes
Available markets
The list of instruments available can be retrieved programmatically with a get request to the instruments endpoint.
curl \
http://api.fxhistoricaldata.com/instruments
Forex
- AUD_USD
- AUD_JPY
- AUD_NZD
- CHF_JPY
- EUR_CAD
- EUR_CHF
- EUR_GBP
- EUR_JPY
- EUR_USD
- GBP_CHF
- GBP_JPY
- GBP_NZD
- GBP_USD
- NZD_USD
- NZD_JPY
- USD_CAD
- USD_CHF
- USD_HKD
- USD_JPY
Commodities/Bonds
- XAU_USD
- XAG_USD
- BCO_USD - Brent crude priced in US Dollars
- WTICO_USD
- DE10YB_EUR
- DE10YB_USD - German Bunds priced in US Dollars
Stock Market Indices
- AU200_AUD
- AU200_USD - AUS200 priced in US Dollars
- ES35_EUR
- ES35_USD - ESP35 priced in US Dollars
- FR40_EUR
- FR40_USD - FRA40 priced in US Dollars
- DE30_EUR
- DE30_USD - GER30 priced in US Dollars
- HK33_HKD
- HK33_USD - HKG33 priced in US Dollars
- JP225_JPY
- JP225_USD - JPN225 priced in US Dollars
- NAS100_USD
- SPX500_USD
- UK100_GBP
- UK100_USD - UK100 priced in US Dollars
- US30_USD
Errors
The API returns structured errors that look like:
{
"id": "error_id",
"message": "Error description",
"url": "More detailed information about how to resolve the error"
}
The API uses the following error codes:
Error Code | Meaning |
---|---|
400 | Bad Request -- The input in the request is invalid. Check error message and URL for help fixing the request. |
500 | Internal Server Error -- We had a problem with our server. Try again later. |
503 | Service Unavailable -- We're temporarily offline for maintenance. Please try again later. |