Obtain Technical Indicators from TechFlare Chainlink Oracle
Oracles allow us obtain external data out of blockchain into smart contracts where we can’t take data outside a blockchain directly. A blockchain with smart contract capability can manage only on-chain state and virtual machine in its underlying infrastructure, but that is not the world other systems such as web, financial information, contructual agreements are related to.
We “TechFlare” are running a Chainlink Oracle node and provide the core adapters and the external adapter that calculates technical indicators for TA and trading, arbitrage, collateral swaps especially in DeFi. We’ve developed an API endpoint and expose it to the internet so our external adapter can query to obtain technical indicators from the oracle to your smart contract.
We’re looking for a financial expert(TA), a backend engineer to improve our service and add more technical indicators and financial information in an extensive area not only crypto data but also commodity, bonds, derivatives.
Contact us at our twitter account , DM: https://twitter.com/TechFlareNode
We’ll look through how to test our API endpoint and call the oracle from your smart contract in Ethereum mainnet in this article. At this stage we’re using only single data provider (CoinGecko) as a source, however we aim to be providing more reliable data from multiple sources with robust and resilient infrastructure.
Before jump in the content, these articles about oracle service and the industry standard oracle “chainlink” might be captivating you. It’s worth to look through [1] [2] [3] [4].
We cover 2 things in this article.
- Test our staging API endpoint
- Write a smart contract in prod
When we developed our external adapter that you can retrieve technical indicators of crypto assets, we exposed a testing endpoint in the internet. This endpoint has a rate-limit configured so it can’t be used for production use actually, but you can confirm data reliability and credibility by calling the endpoint. It supports multiple crypto assets, technical indicators with various time periods (as of now we are maintaining minute, hourly, daily tables). We support:
- Simple Moving Average (sma)
- Exponential Moving Average (ema)
- Momentum
- Return
- Standard Deviation (std)
- Disparity
The supported crypto assets and technical indicators are changing, please visit the official TechFlare External Adapter page for the latest information. Currently these crypto assets are callable on the endpoint as follows. [5]
btc
eth
ltc
bch
ada
bnb
dot
link
Let’s take a look an example. You can use query strings n
for an asset type and p
for a period. If you need to look up bitcoin’s sma from hourly data, a query string should be ?n=btc&p=h
and the calling URL would need to be https://3t9jjasu58.execute-api.ap-northeast-1.amazonaws.com/Stage/chainlink?n=btc&p=h
as a result. Please note that this endpoint has a rate-limit configured and also some other restrictions in AWS. You can use this raw staging API endpoint for testing purpose only.
As you noticed already it returned all technical indicators of crypto asset with various data points. If you called the hourly table of the target asset, the number under the bracket of each technical indicator shows hourly data points result. So a simple moving average of bitcoin from the recent 5 hours data points can be fed like below. When you use a smart contract to retrieve data you must use one of the core adapters copyPath
to parse out in the returned JSON object data. Let’s see an example of smart contract in Kovan test network next.
As this staging endpoint is exposed in public so you can call this endpoint from any Ethereum network with a HTTP Get request in your contract. Your contract must inherit from ChainlinkClient
and the contract exposes a struct called Chainlink.Request
and a request is made including the oracle address, the job id, the fee, adapter parameters, and the callback function signature.
I created a sample smart contract that calls the aforementioned staging endpoint and retrieved a simple moving average in 5 hours data points in Kovan network. This smart contract worked well. Please be careful that the decimals were removed by multiplying the given data by 1000000000000000000 in place.
Next we introduce how to use the external adapter in a smart contract for Ethereum mainnet. To avoid tedious works such as adding a URL, or other adapter parameters by searching in web, you can use a oracle job and that’s why we developed our external adapter to use a job for this purpose. This makes your smart contract code more succinct. To see an example of a contract using an existing job, please check the official page below. [6]
Let’s move on to an example smart contract using our oracle job to do the same in Ethereum mainnet. We can use request.add
to add a query parameter on the external adapter, this example is equivalent to pass "data": {"n": "btc", "p":"h"}
so the first task techflarebridge returns the expected result in a JSON format to parse out in the following task. As of now, the fee is set to 0.1 LINK. Please do not forget to transfer your LINK more than 0.1 to the deployed smart contract before calling the function.
/**
* Network: Mainnet
* Oracle:
* Name: TechFlare
* Listing URL: https://market.link/nodes/0c4cdcd0-f09b-4b63-a8ac-17ba06c3f838/metrics?network=1
* Address: 0xb25FCb293571ba083bc33dA71159ed2a39A051A1
* Job:
* Name: TechFlare API
* Listing URL: https://market.link/jobs/48eaf76d-fd2b-43b0-aae3-91087902c760/spec?network=1
* ID: 4144bfcb058245ecbbd746044d49762f
* Fee: 0.1 LINK
*/
Blockchain oracles are the key to unleash the power of blockchain in real world with off-chain data. We are improving our service and line-up of crypto financial data and revamp the product for users with reliable and creadible data in a sustainable way. If you have any questions, please contact us at our twitter account , DM: https://twitter.com/TechFlareNode.