Skip to content

Commit

Permalink
TW-1194 Replace TZPRO API with Binance API
Browse files Browse the repository at this point in the history
  • Loading branch information
keshan3262 committed Nov 27, 2023
1 parent d1ddaa9 commit 480be5d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 28 deletions.
1 change: 0 additions & 1 deletion .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ THREE_ROUTE_API_AUTH_TOKEN=
REDIS_URL=
ADD_NOTIFICATION_USERNAME=
ADD_NOTIFICATION_PASSWORD=
TZPRO_API_KEY=
3 changes: 1 addition & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export const EnvVars = {
THREE_ROUTE_API_AUTH_TOKEN: getEnv('THREE_ROUTE_API_AUTH_TOKEN'),
REDIS_URL: getEnv('REDIS_URL'),
ADD_NOTIFICATION_USERNAME: getEnv('ADD_NOTIFICATION_USERNAME'),
ADD_NOTIFICATION_PASSWORD: getEnv('ADD_NOTIFICATION_PASSWORD'),
TZPRO_API_KEY: getEnv('TZPRO_API_KEY')
ADD_NOTIFICATION_PASSWORD: getEnv('ADD_NOTIFICATION_PASSWORD')
};

for (const name in EnvVars) {
Expand Down
16 changes: 2 additions & 14 deletions src/interfaces/ticker.interface.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
export interface ITicker {
pair: string;
base: string;
quote: string;
exchange: string;
open: number;
high: number;
low: number;
last: number;
change: number;
vwap: number;
n_trades: number;
volume_base: number;
volume_quote: number;
timestamp: string;
symbol: string;
price: string;
}
15 changes: 4 additions & 11 deletions src/utils/tezos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { tzip12 } from '@taquito/tzip12';
import { tzip16 } from '@taquito/tzip16';
import memoizee from 'memoizee';

import { EnvVars } from '../config';
import { ITicker } from '../interfaces/ticker.interface';
import fetch from './fetch';
import SingleQueryDataProvider from './SingleQueryDataProvider';
Expand Down Expand Up @@ -54,18 +53,12 @@ export const getStorage = memoizee(
);

const getTezExchangeRate = async () => {
const marketTickers = await fetch<Array<ITicker>>(
`https://api.tzpro.io/markets/tickers?api_key=${EnvVars.TZPRO_API_KEY}`
);
const usdTickers = marketTickers.filter(e => e.quote === 'USD' && e.base === 'XTZ');
// price index: use all USD ticker last prices with equal weight
const vol = usdTickers.reduce((s, t) => s + t.volume_base, 0) || null;
const price = vol === null ? 1 : usdTickers.reduce((s, t) => s + (t.last * t.volume_base) / vol, 0);

return price;
const { price: rawPrice } = await fetch<ITicker>('https://api.binance.com/api/v3/ticker/price?symbol=XTZUSDT');

return Number(rawPrice);
};

export const tezExchangeRateProvider = new SingleQueryDataProvider(30000, getTezExchangeRate);
export const tezExchangeRateProvider = new SingleQueryDataProvider(60000, getTezExchangeRate);

export class MetadataParseError extends Error {}

Expand Down

0 comments on commit 480be5d

Please sign in to comment.