-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
872dadb
commit d9bd07c
Showing
5 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type { RatesProvider } from './ratesProvider'; | ||
export { BinanceRatesProvider } from './binance/index'; | ||
export { KrakenRatesProvider } from './kraken/index'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
export interface KrakenRatesDto { | ||
error: string[]; | ||
result: Record<string, KrakenTickerInfo>; | ||
} | ||
|
||
export interface KrakenTickerInfo { | ||
/** | ||
* Ask | ||
*/ | ||
a: [price: string, wholeLotVolume: string, lotVolume: string]; | ||
|
||
/** | ||
* Bid | ||
*/ | ||
b: [price: string, wholeLotVolume: string, lotVolume: string]; | ||
|
||
/** | ||
* Last trade closed | ||
*/ | ||
c: [price: string, lotVolume: string]; | ||
|
||
/** | ||
* Volume | ||
*/ | ||
v: [today: string, last24Hours: string]; | ||
|
||
/** | ||
* Volume weighted average price | ||
*/ | ||
p: [today: string, last24Hours: string]; | ||
|
||
/** | ||
* Number of trades | ||
*/ | ||
t: [today: number, last24Hours: number]; | ||
|
||
/** | ||
* Low | ||
*/ | ||
l: [today: string, last24Hours: string]; | ||
|
||
/** | ||
* High | ||
*/ | ||
h: [today: string, last24Hours: string]; | ||
|
||
/** | ||
* Today's opening price | ||
*/ | ||
o: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { KrakenRatesProvider } from './krakenRatesProvider'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import BigNumber from 'bignumber.js'; | ||
|
||
import { HttpClient } from '../../../core'; | ||
import type { RatesProvider } from '../ratesProvider'; | ||
import type { KrakenRatesDto } from './dtos'; | ||
|
||
export class KrakenRatesProvider implements RatesProvider { | ||
private static readonly baseUrl = 'https://api.kraken.com'; | ||
|
||
private readonly httpClient: HttpClient; | ||
|
||
constructor() { | ||
this.httpClient = new HttpClient(KrakenRatesProvider.baseUrl); | ||
} | ||
|
||
async getPrice(quoteCurrency: string, baseCurrency: string): Promise<BigNumber | undefined> { | ||
const symbol = `${quoteCurrency}${baseCurrency}`; | ||
const urlPath = `/0/public/Ticker?pair=${symbol}`; | ||
const responseDto = await this.httpClient.request<KrakenRatesDto>({ urlPath }, false); | ||
|
||
return this.mapRatesDtoToPrice(responseDto, symbol); | ||
} | ||
|
||
private mapRatesDtoToPrice(dto: KrakenRatesDto, symbol: string): BigNumber | undefined { | ||
if (dto.error) | ||
return undefined; | ||
|
||
const tickerInfo = dto.result[symbol]; | ||
if (!tickerInfo) | ||
return undefined; | ||
|
||
return new BigNumber(tickerInfo.c[0]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type BigNumber from 'bignumber.js'; | ||
|
||
import type { Currency } from '../../common'; | ||
|
||
export interface RatesProvider { | ||
getPrice(quoteCurrency: Currency['id'], baseCurrency: Currency['id']): Promise<BigNumber | undefined>; | ||
} |