3. Pricing - adharapayments/REST-API GitHub Wiki
General Information:
- Streaming pricing/rates service provides a constant flow of ticks when there is a change in the price of selected securities.
- Polling (non-streaming) pricing/rates service provides most current pricing for all selected securities.
- An historical price service provides candles for latest prices.
- The first streaming response will be a message with all prices (a snapshot), so user does not need to call previously the polling service (initial prices).
- Trading strategies should open a single stream to receive all ticks from different trading interfaces.
- Minimum latency is provided by this service to increase execution probability and minimize tick-to-trade time.
- While streaming, JSON heartbeat objects are sent if there is no price change during a second.
- The "granularity" defines the book levels to be returned in the response.
- Maximum granularity depends on the 'maximum subscription mode' configured on each trading interface. If a trading interface is configured in 'top of book' subscription mode, received ticks in the streaming will have a 'top of book' granularity.
- Typically a trading strategy will send new orders when a price change is detected.
Examples
Top of Book (TOB) streaming request
$ curl -i --data '{"getPrice":{"user":"demo","token":"E79133C6902B63D2E5F5D9E9F1E658019F143675","security":["EUR/USD","EUR/GBP"]}}' http://actfx.adhara.io:81/cgi-bin/IHFTRestStreamer/getPrice --header 'Content-Type: application/json'
Date: Wed, 01 Jul 2015 00:00:00 GMT
Server: Apache/2.4.7 (Ubuntu)
Transfer-Encoding: chunked
Content-Type: application/json;charset=iso-8859-1
{ "getPriceResponse": {
"tick": [
{ "security": "EUR/USD",
"tinterface": "TI1",
"price": 1.105680,
"pips": 5,
"liquidity": 1000000,
"side": "ask" },
{ "security": "EUR/USD",
"tinterface": "TI1",
"price": 1.105850,
"pips": 5,
"liquidity": 10000000,
"side": "bid" },
{ "security": "EUR/GBP",
"tinterface": "TI1",
"price": 0.721250,
"pips": 5,
"liquidity": 10000000,
"side": "ask" },
{ "security": "EUR/GBP",
"tinterface": "TI1",
"price": 0.721220,
"pips": 5,
"liquidity": 1000000,
"side": "bid" } ],
"timestamp": "1445950414.901344" }
}
{ "getPriceResponse": {
"heartbeat": {
"security": [ "EUR/USD", "EUR/GBP" ],
"tinterface": [ "TI1" ] },
"timestamp": "1445950415.901413" }
}
... more responses ...
Full Aggregated Book (FAB) streaming request:
$ curl -i --data '{"getPrice":{"user":"demo","token":"E79133C6902B63D2E5F5D9E9F1E658019F143675","security":["EUR/USD"],"granularity":"fab","levels":3}}' http://actfx.adhara.io:81/cgi-bin/IHFTRestStreamer/getPrice --header 'Content-Type: application/json'
HTTP/1.1 200 OK
Date: Wed, 01 Jul 2015 00:00:00 GMT
Server: Apache/2.4.7 (Ubuntu)
Transfer-Encoding: chunked
Content-Type: application/json;charset=iso-8859-1
{ "getPriceResponse":
{ "tick": [
{ "security": "EUR/USD",
"tinterface": "TI1",
"price": 1.105760,
"pips": 5,
"liquidity": 1000000,
"side": "ask" },
{ "security": "EUR/USD",
"tinterface": "TI1",
"price": 1.105770,
"pips": 5,
"liquidity": 1000000,
"side": "ask" },
{ "security": "EUR/USD",
"tinterface": "TI1",
"price": 1.105780,
"pips": 5,
"liquidity": 5000000,
"side": "ask" },
{ "security": "EUR/USD",
"tinterface": "TI1",
"price": 1.105850,
"pips": 5,
"liquidity": 10000000,
"side": "bid" },
{ "security": "EUR/USD",
"tinterface" : "TI1",
"price": 1.105800,
"pips": 5,
"liquidity": 10000000,
"side": "bid" },
{ "security": "EUR/USD",
"tinterface": "TI1",
"price": 1.105690,
"pips": 5,
"liquidity": 1000000,
"side": "bid" } ],
"timestamp": "1445950617.953625" }
}
{ "getPriceResponse": {
"heartbeat": {
"security": [ "EUR/USD" ],
"tinterface": [ "TI1" ] },
"timestamp": "1445950618.953761" }
}
... more responses ...
Top of Book (TOB) polling request
$ curl -i --data '{"getPrice":{"user":"demo","token":"E79133C6902B63D2E5F5D9E9F1E658019F143675","security":["EUR/USD","EUR/GBP"]}}' http://actfx.adhara.io:81/fcgi-bin/IHFTRestAPI/getPrice --header 'Content-Type: application/json'
Date: Wed, 01 Jul 2015 00:00:00 GMT
Server: Apache/2.4.7 (Ubuntu)
Transfer-Encoding: chunked
Content-Type: application/json;charset=iso-8859-1
{ "getPriceResponse": {
"tick": [
{ "security": "EUR/USD",
"tinterface": "TI1",
"price": 1.105680,
"pips": 5,
"liquidity": 1000000,
"side": "ask" },
{ "security": "EUR/USD",
"tinterface": "TI1",
"price": 1.105850,
"pips": 5,
"liquidity": 10000000,
"side": "bid" },
{ "security": "EUR/GBP",
"tinterface": "TI1",
"price": 0.721250,
"pips": 5,
"liquidity": 10000000,
"side": "ask" },
{ "security": "EUR/GBP",
"tinterface": "TI1",
"price": 0.721220,
"pips": 5,
"liquidity": 1000000,
"side": "bid" } ],
"timestamp": "1445950414.901344" }
}
getPrice()
Request: getPrice
-
user: Required. Strategy login assigned by the backend administrator.
-
token: Required. Token obtained during the authentication procedure.
-
security: Required. List of securities/instruments whose prices will be returned.
-
tinterface: Optional. List of trading interfaces whose prices will be returned. Default value: All
-
granularity: Optional. Aggregation level of the prices: "tob" (top of book) "fab" (full aggregated book). Default value: "tob" (top-of-book).
- When TOB granularity is set, single level ASK and BID level are returned.
- When FAB granularity is set, ASK price levels and BID price levels are streamed on any price/liquidity change for selected levels.
-
levels: Optional. Number of prices levels to be returned for ASK and BID rates when a full book granularity is set. Default value: 3
-
interval: Optional. Only available for streaming service. Inter-message time interval (in milliseconds). When defined streamed prices are sent at a given rate to prevent high throughputs and overkilling a mobile data plan. Minimum value: 100, Maximum value: 10000. If a zero value is set, real-time pricing is returned. Default value: 0 (prices are streamed in real-time).
Response: getPriceResponse
getPriceResponse objects can contain a 'tick', a 'heartbeat' and a 'timestamp' object. Heartbeat objects are only returned on streaming services.
-
tick: Price tick object that includes a list of prices with following fields:
- security: Instrument name.
- tinterface: Trading intarface name where price has been reported. Please refer to getInterface() web-service.
- price: Price or "level" of the instrument.
- pips: Number of decimals that defines the "pips" of the price.
- liquidity: Total depth for this level.
- side: "ask" or "bid".
-
heartbeat: Keep alive object which is sent when there is no change in pricing during a second. It includes a list with all securities associated to the streaming with following fields:
- security: List of instrument names.
- tinterface: List of trading intarface names where prices are being reported.
-
timestamp: Epoch time of the tick or heartbeat. Decimals define the number of micro-seconds. Integer part represents the seconds from "epoch" time.
getHistoricalPrice()
Historical price request:
$ curl -i --data '{"getHistoricalPrice":{"user":"demo","token":"E79133C6902B63D2E5F5D9E9F1E658019F143675","security":["EUR/USD","EUR/GBP"],"granularity":"s1","side":"ask","number":2}}' http://actfx.adhara.io:81/fcgi-bin/IHFTRestAPI/getHistoricalPrice --header 'Content-Type: application/json'
HTTP/1.1 200 OK
Date: Wed, 01 Jul 2015 00:00:00 GMT
Server: Apache/2.4.7 (Ubuntu)
Transfer-Encoding: chunked
Content-Type: application/json;charset=iso-8859-1
{ "getHistoricalPriceResponse": {
"candle": [
{ "security": "EUR/USD",
"tinterface": "LMAX_LMAX",
"timestamp": 1536070409,
"side": "ask",
"open": 1.153630,
"high": 1.153630,
"low": 1.153630,
"close": 1.153630,
"ticks": 2 },
{ "security": "EUR/USD",
"tinterface": "LMAX_LMAX",
"timestamp": 1536070404,
"side": "ask",
"open": 1.153610,
"high": 1.153610,
"low": 1.153610,
"close": 1.153610,
"ticks": 1 },
{ "security": "EUR/GBP",
"tinterface": "LMAX_LMAX",
"timestamp": 1536070409,
"side": "ask",
"open": 0.899700,
"high": 0.899700,
"low": 0.899700,
"close": 0.899700,
"ticks": 2 },
{ "security": "EUR/GBP",
"tinterface": "LMAX_LMAX",
"timestamp": 1536070404,
"side": "ask",
"open": 0.899670,
"high": 0.899670,
"low": 0.899670,
"close": 0.899670,
"ticks": 1 } ],
"timestamp": "1536070411.859363" }
}
Request: getHistoricalPrice
- user: Required. Strategy login assigned by the backend administrator.
- token: Required. Token obtained during the authentication procedure.
- security: Required. List of securities/instruments whose prices will be returned.
- tinterface: Optional. List of trading interfaces whose prices will be returned. Default value: All
- granularity: Optional. Type of candles to request: "S1", "S5", "S10", "S30", "M1", "M5", "M10", "M30", "H1", "H2" and "H6".
- side: Optional. "ask", "bid" or "both".
- number: Optional. Number of candles to be returned (from newer to oldest). Default value: 128
- interval: Optional. Only available for streaming service. Inter-message time interval (in milliseconds). When defined streamed prices are sent at a given rate to prevent high throughputs and overkilling a mobile data plan. Minimum value: 100, Maximum value: 10000. If a zero value is set, real-time pricing is returned. Default value: 0 (prices are streamed in real-time).
Response: getHistoricalPriceResponse
getHistoricalPriceResponse objects will contain a 'candle' and a 'timestamp' object.
-
candle: Price candle object that includes a list of candles with following fields:
- security: Instrument name.
- tinterface: Trading intarface name where price has been reported. Please refer to getInterface() web-service.
- timestamp: Candle refers to this 'epoch' time (in seconds).
- side: "ask" or "bid".
- open: Open price in the candle interval.
- high: Highest price in the candle interval.
- low: Lowest price in the candle interval.
- close: Close price in the candle interval.
- ticks: Number of price ticks inside candle interval.
-
timestamp: Epoch time of the tick or heartbeat. Decimals define the number of micro-seconds. Integer part represents the seconds from "epoch" time.