mirror of
https://github.com/Redume/Kekkai.git
synced 2025-02-23 12:43:12 +03:00
feat: CoinAPI cryptocurrency collection has been removed
Some checks are pending
Create and publish a Docker image / build-and-push-server (push) Waiting to run
Create and publish a Docker image / build-and-push-chart (push) Waiting to run
Create and publish a Docker image / build-and-push-CR (push) Waiting to run
Deploy docs / deploy (push) Waiting to run
Some checks are pending
Create and publish a Docker image / build-and-push-server (push) Waiting to run
Create and publish a Docker image / build-and-push-chart (push) Waiting to run
Create and publish a Docker image / build-and-push-CR (push) Waiting to run
Deploy docs / deploy (push) Waiting to run
This commit is contained in:
parent
526d185048
commit
b49bd33a93
6 changed files with 4 additions and 128 deletions
|
@ -3,8 +3,6 @@ const config = require('../shared/config/src/main.js')();
|
|||
const cron = require('cron-validator');
|
||||
|
||||
const save_fiat = require('./save_fiat');
|
||||
const save_crypto = require('./save_crypto');
|
||||
|
||||
const logger = require('../shared/logger/src/main.js');
|
||||
|
||||
async function validateSchedule(schedule) {
|
||||
|
@ -18,7 +16,7 @@ async function initialize() {
|
|||
}
|
||||
|
||||
async function runTasks() {
|
||||
await Promise.all([save_fiat(), save_crypto()]);
|
||||
await Promise.all([save_fiat()]);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
|
|
|
@ -1,89 +0,0 @@
|
|||
const config = require('../shared/config/src/main.js')();
|
||||
const axios = require('axios');
|
||||
const pool = require('../shared/database/src/postgresql.js');
|
||||
const logger = require('../shared/logger/src/main.js');
|
||||
|
||||
const coinapiKeys = config['currency']['coinapiKeys'];
|
||||
let apiKeyIndex = 0;
|
||||
let depth = coinapiKeys.length;
|
||||
|
||||
function save_crypto() {
|
||||
if (!config['currency']['collecting']['crypto']) return;
|
||||
if (coinapiKeys[apiKeyIndex] === undefined) return;
|
||||
|
||||
if (depth <= 0) {
|
||||
logger.info('Rate limit on all coinapi API keys');
|
||||
new Error('Rate limit on all coinapi API keys');
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info(
|
||||
`Active coinapi key: ${coinapiKeys[apiKeyIndex]} (${coinapiKeys.length - 1} / ${apiKeyIndex})`,
|
||||
);
|
||||
|
||||
config['currency']['crypto'].forEach((value) =>
|
||||
config['currency']['crypto'].forEach((pair) => {
|
||||
if (value === pair) return;
|
||||
|
||||
axios
|
||||
.get(
|
||||
`https://rest.coinapi.io/v1/exchangerate/${value}/${pair}`,
|
||||
{
|
||||
timeout: 3000,
|
||||
headers: {
|
||||
'X-CoinAPI-Key': coinapiKeys[apiKeyIndex],
|
||||
},
|
||||
},
|
||||
)
|
||||
.then(async (res) => {
|
||||
const data = res.data;
|
||||
const point = data['rate'].toString().indexOf('.') + 4;
|
||||
|
||||
logger.debug(JSON.stringify(data));
|
||||
|
||||
const db = await pool.query(
|
||||
'SELECT * FROM currency WHERE from_currency = $1 AND conv_currency = $2 AND date = $3',
|
||||
[
|
||||
value,
|
||||
pair,
|
||||
new Date(data['time']).toLocaleDateString(),
|
||||
],
|
||||
);
|
||||
|
||||
if (db['rows'][0]) return;
|
||||
await pool.query(
|
||||
`INSERT INTO currency (from_currency, conv_currency, rate, date)
|
||||
VALUES ($1, $2, $3, $4)`,
|
||||
[
|
||||
value,
|
||||
pair,
|
||||
data['rate'].toString().slice(0, point),
|
||||
new Date(data['time']).toLocaleDateString(),
|
||||
],
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err.response?.data.detail)
|
||||
logger.error(err.response.data.detail);
|
||||
if (err.response?.data.status === 429) {
|
||||
logger.info('CoinAPI rate limited, rotating token');
|
||||
rotate_key(coinapiKeys);
|
||||
depth--;
|
||||
save_crypto();
|
||||
}
|
||||
});
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changing API keys
|
||||
* @param {Array} list - List of all keys
|
||||
* @returns {number} - Outputs the number of the key that should work
|
||||
*/
|
||||
|
||||
function rotate_key(list) {
|
||||
apiKeyIndex = list.indexOf(coinapiKeys[apiKeyIndex]) + 1;
|
||||
}
|
||||
|
||||
module.exports = save_crypto;
|
|
@ -1,5 +1,5 @@
|
|||
# For more information, see the documentation
|
||||
# https://github.com/Redume/Kekkai/wiki
|
||||
# https://kekkai-docs.redume.su/
|
||||
|
||||
database: # Postgresql database data, for connection
|
||||
user: 'DATABASE_USERNAME'
|
||||
|
@ -26,7 +26,6 @@ currency:
|
|||
save: false # Enable or disable saving graphs to an image (Boolean)
|
||||
collecting:
|
||||
fiat: true # Turn off or turn on the collection of the fiat currency rate [Boolean]
|
||||
crypto: false # Turn off or turn on the collection of the cryptocurrency rate [Boolean]
|
||||
schedule: '30 8 * * *' # Currency collection schedule in crontab format [String]
|
||||
fiat: # List of fiat currency to save the exchange rate [Array]
|
||||
- USD
|
||||
|
@ -35,10 +34,3 @@ currency:
|
|||
- UAH
|
||||
- TRY
|
||||
- KZT
|
||||
crypto: # List of cryptocurrency to save the exchange rate [Array]
|
||||
- BTC
|
||||
- ETH
|
||||
coinapiKeys: # List of keys for the coinapi API [Array]
|
||||
- CryptoKey1
|
||||
- CryptoKey2
|
||||
- CryptoKey3
|
|
@ -1,5 +0,0 @@
|
|||
- Go to [coinapi.io](https://www.coinapi.io/get-free-api-key?product_id=market-data-api) website
|
||||
- Enter any name and your current email, where the api keys will be sent
|
||||
- In the `What products are you interested in?` section, you can click from one to four items. I recommend clicking all four, because this affects the number of API keys
|
||||
- Check the email you specified. If there is no letter, then check your spam. You should receive as many keys as you specified in the `What products are you interested in?`
|
||||
- Keys can be specified in the config `currency.coinapiKeys`
|
|
@ -30,7 +30,6 @@ Kekkai can be configured using the `config.yaml` file in the working directory.
|
|||
save: false
|
||||
collecting:
|
||||
fiat: true
|
||||
crypto: false
|
||||
schedule: '30 8 * * *'
|
||||
fiat:
|
||||
- USD
|
||||
|
@ -39,13 +38,6 @@ Kekkai can be configured using the `config.yaml` file in the working directory.
|
|||
- UAH
|
||||
- TRY
|
||||
- KZT
|
||||
crypto:
|
||||
- BTC
|
||||
- ETH
|
||||
coinapiKeys: # List of keys for the coinapi API [Array]
|
||||
- CryptoKey1
|
||||
- CryptoKey2
|
||||
- CryptoKey3
|
||||
```
|
||||
|
||||
## Database
|
||||
|
@ -99,7 +91,7 @@ Kekkai uses [`Plausbile`](https://plausible.io/) as an analyst. Minimal data is
|
|||
- `work`: Enable or disable analytics.
|
||||
|
||||
## Currency
|
||||
`DuckDuckGo` (fiat currency collection) and `CoinAPI` (cryptocurrency collection) are used to collect currency rates.
|
||||
`DuckDuckGo` (fiat currency collection) is used to collect currency rates.
|
||||
|
||||
??? note
|
||||
```yaml
|
||||
|
@ -109,7 +101,6 @@ Kekkai uses [`Plausbile`](https://plausible.io/) as an analyst. Minimal data is
|
|||
save: false
|
||||
collecting:
|
||||
fiat: true
|
||||
crypto: false
|
||||
schedule: '30 8 * * *'
|
||||
fiat:
|
||||
- USD
|
||||
|
@ -118,19 +109,9 @@ Kekkai uses [`Plausbile`](https://plausible.io/) as an analyst. Minimal data is
|
|||
- UAH
|
||||
- TRY
|
||||
- KZT
|
||||
crypto:
|
||||
- BTC
|
||||
- ETH
|
||||
coinapiKeys:
|
||||
- CryptoKey1
|
||||
- CryptoKey2
|
||||
- CryptoKey3
|
||||
...
|
||||
```
|
||||
|
||||
- `currency.chart.save`: Enable or disable saving graphs.
|
||||
- `currency.collecting`: Enable or disable cryptocurrency or fiat currency exchange rate collection.
|
||||
- `currency.schedule`: Currency collection interval (Configurable via cron. It is recommended to use [crontab.guru](https://crontab.guru), not supported in `Non-standard format`, like `@daily`).
|
||||
- `currency.fiat`: A list of fiat currencies that will be saved to the database.
|
||||
- `currency.crypto`: A list of cryptocurrencies that will be saved to the database.
|
||||
- `currency.coinapiKeys`: List of API keys of the coinapi service
|
||||
- `currency.fiat`: A list of fiat currencies that will be saved to the database.
|
|
@ -15,7 +15,6 @@ nav:
|
|||
- Manual: getting-started/manual.md
|
||||
- Contributing: getting-started/contributing.md
|
||||
- Config:
|
||||
- How to create API keys for coinapi: config/coinapi-keys.md
|
||||
- Configure config.yaml: config/config-yaml.md
|
||||
- Configure .env: config/config-env.md
|
||||
- Configure nginx.conf: config/conf-nginx.md
|
||||
|
|
Loading…
Add table
Reference in a new issue