Class JsonPriceFeed
java.lang.Object
com.codename1.crypto.market.JsonPriceFeed
- All Implemented Interfaces:
PriceFeed
A feed over any HTTP API that answers one price in JSON. The URL is a template in which
{base}/{quote} become the lower-case tickers and {BASE}/{QUOTE} the upper-case ones;
the path names the price in the reply, member names and array indices separated by dots.
// Coinbase: {"data":{"amount":"67187.33","base":"BTC","currency":"USD"}}
RpcTransport transport = new NetworkTransport();
PriceFeed coinbase = new JsonPriceFeed(transport,
"https://api.coinbase.com/v2/prices/{BASE}-{QUOTE}/spot", "data.amount", "coinbase");
// Kraken: {"result":{"XXBTZUSD":{"c":["67187.30000","0.01"]}}} -- the pair key varies, so
// pass a path per pair or use a feed that knows the exchange.
The price may be a JSON number or a numeric string.
-
Constructor Summary
ConstructorsConstructorDescriptionJsonPriceFeed(RpcTransport transport, String urlTemplate, String pricePath, String name) A feed. -
Method Summary
-
Constructor Details
-
JsonPriceFeed
A feed.
Parameters
transport: how to send the requesturlTemplate: the URL with{base},{quote},{BASE},{QUOTE}placeholderspricePath: where the price is in the reply, such asdata.amountname: the source name the quotes carry
-
-
Method Details
-
getQuote
Description copied from interface:PriceFeedThe price of
baseinquote, by ticker (BTC,ETH,USD,EUR); case does not matter.Throws
IOException: when the source cannot be reached or does not know the pair
- Specified by:
getQuotein interfacePriceFeed- Throws:
IOException
-