Skip to content

Commit bf44b0a

Browse files
committed
Replace 'alphavantage-sdr' with 'alphachain' adapter
1 parent 49cf8af commit bf44b0a

File tree

11 files changed

+133
-93
lines changed

11 files changed

+133
-93
lines changed

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ jobs:
7474
marketstack,
7575
nikkei,
7676
binance-dex,
77-
alphavantage-sdr,
7877
nomics,
7978
1forge,
79+
alphachain,
8080
alphavantage,
8181
amberdata,
8282
bravenewcoin,

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
### Changed
10+
11+
- Replaced `alphavantage-sdr` with `alphachain` adapter
12+
913
## [0.1.1] - 2020-09-18
1014

1115
### Added

alphachain/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Chainlink External Adapter for AlphaChain (SDR)
2+
3+
## Input Params
4+
5+
- `base`, `from`, or `coin`: The symbol of the currency to query
6+
- `quote`, `to`, or `market`: The symbol of the currency to convert to
7+
8+
## Output
9+
10+
```json
11+
{
12+
"jobRunID": "1",
13+
"data": {
14+
"data": {
15+
"from_symbol": "ETH",
16+
"last_refreshed": "2020-05-29 08:45:03 +0000 UTC",
17+
"rate": 301.3654364,
18+
"time_zone": "UTC",
19+
"to_symbol": "SDR"
20+
},
21+
"jobRunID": "",
22+
"result": 301.3654364,
23+
"status": "200"
24+
},
25+
"result": 301.3654364,
26+
"statusCode": 200
27+
}
28+
```

alphavantage-sdr/adapter.js alphachain/adapter.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ const customParams = {
1313
const createRequest = (input, callback) => {
1414
const validator = new Validator(callback, input, customParams)
1515
const jobRunID = validator.validated.id
16-
const url = 'https://us-central1-alpha-chain-api.cloudfunctions.net/test-api'
16+
const url = 'https://alpha-chain2.p.rapidapi.com/data-query'
17+
const host = 'alpha-chain2.p.rapidapi.com'
18+
const headers = {
19+
'content-type': 'application/octet-stream',
20+
'x-rapidapi-host': host,
21+
'x-rapidapi-key': process.env.API_KEY,
22+
useQueryString: true
23+
}
1724
const base = validator.validated.data.base.toUpperCase()
1825
const quote = validator.validated.data.quote.toUpperCase()
1926

@@ -25,17 +32,18 @@ const createRequest = (input, callback) => {
2532

2633
const config = {
2734
url,
28-
params
35+
params,
36+
headers
2937
}
3038

3139
Requester.request(config, customError)
32-
.then(response => {
33-
response.data.result = Requester.validateResultNumber(response.data, ['result'])
40+
.then((response) => {
41+
response.data.result = Requester.validateResultNumber(response.data, [
42+
'result'
43+
])
3444
callback(response.status, Requester.success(jobRunID, response))
3545
})
36-
.catch(error => {
37-
callback(500, Requester.errored(jobRunID, error))
38-
})
46+
.catch((error) => callback(500, Requester.errored(jobRunID, error)))
3947
}
4048

4149
module.exports.createRequest = createRequest
File renamed without changes.

alphavantage-sdr/package.json alphachain/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "alphavantage-sdr",
2+
"name": "alphachain",
33
"version": "0.1.0",
44
"license": "MIT",
55
"main": "index.js",

alphachain/test/adapter_test.js

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const { assert } = require('chai')
2+
const { createRequest } = require('../adapter')
3+
4+
describe('createRequest', () => {
5+
const jobID = '1'
6+
7+
context('successful calls', () => {
8+
const requests = [
9+
{
10+
name: 'id not supplied',
11+
testData: { data: { base: 'ETH', quote: 'XDR' } }
12+
},
13+
{
14+
name: 'base/quote',
15+
testData: { id: jobID, data: { base: 'ETH', quote: 'XDR' } }
16+
},
17+
{
18+
name: 'from/to',
19+
testData: { id: jobID, data: { from: 'ETH', to: 'XDR' } }
20+
},
21+
{
22+
name: 'coin/market',
23+
testData: { id: jobID, data: { coin: 'ETH', market: 'XDR' } }
24+
}
25+
]
26+
27+
requests.forEach((req) => {
28+
it(`${req.name}`, (done) => {
29+
createRequest(req.testData, (statusCode, data) => {
30+
assert.equal(statusCode, 200)
31+
assert.equal(data.jobRunID, jobID)
32+
assert.isNotEmpty(data.data)
33+
assert.isAbove(data.result, 0)
34+
assert.isAbove(data.data.result, 0)
35+
done()
36+
})
37+
})
38+
})
39+
})
40+
41+
context('error calls', () => {
42+
const requests = [
43+
{ name: 'empty body', testData: {} },
44+
{ name: 'empty data', testData: { data: {} } },
45+
{
46+
name: 'base not supplied',
47+
testData: { id: jobID, data: { quote: 'XDR' } }
48+
},
49+
{
50+
name: 'quote not supplied',
51+
testData: { id: jobID, data: { base: 'ETH' } }
52+
},
53+
{
54+
name: 'unknown base',
55+
testData: { id: jobID, data: { base: 'not_real', quote: 'XDR' } }
56+
},
57+
{
58+
name: 'unknown quote',
59+
testData: { id: jobID, data: { base: 'ETH', quote: 'not_real' } }
60+
}
61+
]
62+
63+
requests.forEach((req) => {
64+
it(`${req.name}`, (done) => {
65+
createRequest(req.testData, (statusCode, data) => {
66+
assert.equal(statusCode, 500)
67+
assert.equal(data.jobRunID, jobID)
68+
assert.equal(data.status, 'errored')
69+
assert.isNotEmpty(data.error)
70+
done()
71+
})
72+
})
73+
})
74+
})
75+
})

alphavantage-sdr/README.md

-28
This file was deleted.

alphavantage-sdr/test/adapter_test.js

-51
This file was deleted.

alphavantage/adapter.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ const createRequest = (input, callback) => {
3535
params
3636
}
3737
Requester.request(config, customError)
38-
.then(response => {
39-
response.data.result = JSON.parse(Requester.validateResultNumber(
40-
response.data, ['Realtime Currency Exchange Rate', '5. Exchange Rate']))
38+
.then((response) => {
39+
response.data.result = JSON.parse(
40+
Requester.validateResultNumber(response.data, [
41+
'Realtime Currency Exchange Rate',
42+
'5. Exchange Rate'
43+
])
44+
)
4145
callback(response.status, Requester.success(jobRunID, response))
4246
})
43-
.catch(error => {
47+
.catch((error) => {
4448
callback(500, Requester.errored(jobRunID, error))
4549
})
4650
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
"marketstack",
1313
"nikkei",
1414
"binance-dex",
15-
"alphavantage-sdr",
1615
"nomics",
1716
"external-adapter",
1817
"example",
1918
"1forge",
19+
"alphachain",
2020
"alphavantage",
2121
"amberdata",
2222
"bravenewcoin",

0 commit comments

Comments
 (0)