Skip to content

Commit

Permalink
graphics, SVGs and XeggeX price API
Browse files Browse the repository at this point in the history
  • Loading branch information
koh-gt committed Aug 1, 2024
1 parent 447d385 commit 7269490
Show file tree
Hide file tree
Showing 16 changed files with 224 additions and 21 deletions.
61 changes: 61 additions & 0 deletions backend/src/tasks/price-feeds/xeggex-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { query } from '../../utils/axios-query';
import priceUpdater, { PriceFeed, PriceHistory } from '../price-updater';

interface CandleData {
time: number;
close: number;
open: number;
high: number;
low: number;
volume: number;
}

interface CandleApiResponse {
bars: CandleData[];
}

class XeggexApi implements PriceFeed {
public name: string = 'Xeggex';
public currencies: string[] = ['USDT'];

public url: string = 'https://api.xeggex.com/api/v2/ticker/FEC_USDT';

constructor() {
}

public async $fetchPrice(currency): Promise<number> {
const response = await query(this.url);
if (response && response['lastPrice']) {
return parseFloat(response['last_price']);
} else {
return -1;
}
}

public async $fetchRecentPrice(currencies: string[], type: 'hour' | 'day'): Promise<PriceHistory> {
const priceHistory: PriceHistory = {};

for (const currency of currencies) {
if (this.currencies.includes(currency) === false) {
continue;
}

const url = `https://api.xeggex.com/api/v2/market/candles?symbol=FEC%2FUSDT&resolution=30&countBack=336&firstDataRequest=1`;
const response = await query(url) as CandleApiResponse;

if (response && response.bars) {
for (const bar of response.bars) {
const time = Math.round(bar.time / 1000);
if (priceHistory[time] === undefined) {
priceHistory[time] = priceUpdater.getEmptyPricesObj();
}
priceHistory[time][currency] = bar.close; // Using the 'close' price
}
}
}

return priceHistory;
}
}

export default XeggexApi;
32 changes: 17 additions & 15 deletions backend/src/tasks/price-updater.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import config from '../config';
import logger from '../logger';
import PricesRepository, { ApiPrice, MAX_PRICES } from '../repositories/PricesRepository';
import BitfinexApi from './price-feeds/bitfinex-api';
import CoinbaseApi from './price-feeds/coinbase-api';
import GeminiApi from './price-feeds/gemini-api';
import KrakenApi from './price-feeds/kraken-api';
//import BitfinexApi from './price-feeds/bitfinex-api';
//import CoinbaseApi from './price-feeds/coinbase-api';
//import GeminiApi from './price-feeds/gemini-api';
//import KrakenApi from './price-feeds/kraken-api';
import XeggexApi from './price-feeds/xeggex-api';

export interface PriceFeed {
name: string;
Expand Down Expand Up @@ -33,10 +34,11 @@ class PriceUpdater {
constructor() {
this.latestPrices = this.getEmptyPricesObj();

this.feeds.push(new KrakenApi());
this.feeds.push(new CoinbaseApi());
this.feeds.push(new BitfinexApi());
this.feeds.push(new GeminiApi());
// this.feeds.push(new KrakenApi());
// this.feeds.push(new CoinbaseApi());
// this.feeds.push(new BitfinexApi());
// this.feeds.push(new GeminiApi());
this.feeds.push(new XeggexApi());
}

public getLatestPrices(): ApiPrice {
Expand Down Expand Up @@ -88,14 +90,14 @@ class PriceUpdater {
await this.$insertHistoricalPrices();
}
} catch (e: any) {
logger.err(`Cannot save LTC prices in db. Reason: ${e instanceof Error ? e.message : e}`, logger.tags.mining);
logger.err(`Cannot save FEC prices in db. Reason: ${e instanceof Error ? e.message : e}`, logger.tags.mining);
}

this.running = false;
}

/**
* Fetch last LTC price from exchanges, average them, and save it in the database once every hour
* Fetch last FEC price from exchanges, average them, and save it in the database once every hour
*/
private async $updatePrice(): Promise<void> {
if (this.lastRun === 0 && config.DATABASE.ENABLED === true) {
Expand All @@ -121,14 +123,14 @@ class PriceUpdater {
if (price > -1 && price < MAX_PRICES[currency]) {
prices.push(price);
}
logger.debug(`${feed.name} LTC/${currency} price: ${price}`, logger.tags.mining);
logger.debug(`${feed.name} FEC/${currency} price: ${price}`, logger.tags.mining);
} catch (e) {
logger.debug(`Could not fetch LTC/${currency} price at ${feed.name}. Reason: ${(e instanceof Error ? e.message : e)}`, logger.tags.mining);
logger.debug(`Could not fetch FEC/${currency} price at ${feed.name}. Reason: ${(e instanceof Error ? e.message : e)}`, logger.tags.mining);
}
}
}
if (prices.length === 1) {
logger.debug(`Only ${prices.length} feed available for LTC/${currency} price`, logger.tags.mining);
logger.debug(`Only ${prices.length} feed available for FEC/${currency} price`, logger.tags.mining);
}

// Compute average price, non weighted
Expand All @@ -140,7 +142,7 @@ class PriceUpdater {
}
}

logger.info(`Latest LTC fiat averaged price: ${JSON.stringify(this.latestPrices)}`);
logger.info(`Latest FEC fiat averaged price: ${JSON.stringify(this.latestPrices)}`);

if (config.DATABASE.ENABLED === true) {
// Save everything in db
Expand Down Expand Up @@ -172,7 +174,7 @@ class PriceUpdater {
*/
private async $insertHistoricalPrices(): Promise<void> {
// Insert Kraken weekly prices
await new KrakenApi().$insertHistoricalPrice();
// await new KrakenApi().$insertHistoricalPrice();

// Insert missing recent hourly prices
await this.$insertMissingRecentPrices('day');
Expand Down
146 changes: 143 additions & 3 deletions frontend/src/app/components/svg-images/svg-images.component.html

Large diffs are not rendered by default.

Binary file modified frontend/src/resources/favicons/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/src/resources/favicons/android-chrome-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/src/resources/favicons/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/src/resources/favicons/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/src/resources/favicons/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/src/resources/favicons/mstile-150x150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/src/resources/mempool-logo-bigger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/src/resources/mempool-preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/src/resources/mempool-space-logo-bigger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/src/resources/mempool-space-logo-horizontal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/src/resources/mempool-space-preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/src/resources/mempool-tube.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions unfurler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ class Server {
<head>
<meta charset="utf-8">
<title>${ogTitle}</title>
<meta name="description" content="Ferrite Space - Gateway to Explore Ferrite"/>
<meta name="description" content="Ferrite Mempool - Gateway to Explore Ferrite"/>
<meta property="og:image" content="${ogImageUrl}"/>
<meta property="og:image:type" content="image/png"/>
<meta property="og:image:width" content="${matchedRoute.render ? 1200 : 1000}"/>
<meta property="og:image:height" content="${matchedRoute.render ? 600 : 500}"/>
<meta property="og:title" content="${ogTitle}">
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:site" content="@ferrite">
<meta property="twitter:creator" content="@ferrite">
<meta property="twitter:site" content="@ferritecoin">
<meta property="twitter:creator" content="@ferritecoin">
<meta property="twitter:title" content="${ogTitle}">
<meta property="twitter:description" content="Your Gateway to Explore Ferrite"/>
<meta property="twitter:image:src" content="${ogImageUrl}"/>
Expand Down

0 comments on commit 7269490

Please sign in to comment.