-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from near-daos/feature/coin_price_history
Introducing coin price history
- Loading branch information
Showing
47 changed files
with
612 additions
and
126 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
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
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
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
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
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
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
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,17 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
import { CoinType, CurrencyType } from '@dao-stats/common/types'; | ||
|
||
export class CoinPriceHistoryResponse { | ||
@ApiProperty() | ||
date: number; | ||
|
||
@ApiProperty() | ||
coin: CoinType; | ||
|
||
@ApiProperty() | ||
currency: CurrencyType; | ||
|
||
@ApiProperty() | ||
price: number; | ||
} |
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 * from './coin-price-history.dto'; |
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,42 @@ | ||
import { Controller, Get, Param, Query } from '@nestjs/common'; | ||
import { | ||
ApiBadRequestResponse, | ||
ApiParam, | ||
ApiResponse, | ||
ApiTags, | ||
} from '@nestjs/swagger'; | ||
|
||
import { CoinType } from '@dao-stats/common/types'; | ||
import { CoinPriceQuery } from '@dao-stats/common/dto'; | ||
|
||
import { MarketService } from './market.service'; | ||
import { NoContractContext } from '../decorators'; | ||
import { MetricQueryPipe } from '../pipes'; | ||
import { CoinPriceHistoryResponse } from './dto'; | ||
|
||
@ApiTags('Market') | ||
@Controller('/api/v1/market') | ||
export class MarketController { | ||
constructor(private readonly marketService: MarketService) {} | ||
|
||
@ApiResponse({ | ||
status: 200, | ||
type: [CoinPriceHistoryResponse], | ||
}) | ||
@ApiBadRequestResponse({ | ||
description: 'Bad Request Response based on the query params set', | ||
}) | ||
@ApiParam({ | ||
name: 'coin', | ||
description: `Coin Type: e.g ${CoinType.Near}`, | ||
enum: Object.values(CoinType), | ||
}) | ||
@NoContractContext() | ||
@Get('/:coin/price') | ||
async coinPrice( | ||
@Param('coin') coin: CoinType = CoinType.Near, | ||
@Query(MetricQueryPipe) query: CoinPriceQuery, | ||
): Promise<CoinPriceHistoryResponse[]> { | ||
return this.marketService.getCoinPriceHistory(coin, query); | ||
} | ||
} |
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,24 @@ | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { CacheModule, Module } from '@nestjs/common'; | ||
|
||
import { CacheConfigService } from '@dao-stats/config/cache'; | ||
import { Contract, CoinPriceHistoryModule } from '@dao-stats/common'; | ||
import { TransactionModule } from '@dao-stats/transaction'; | ||
|
||
import { MarketService } from './market.service'; | ||
import { MarketController } from './market.controller'; | ||
|
||
@Module({ | ||
imports: [ | ||
CacheModule.registerAsync({ | ||
useClass: CacheConfigService, | ||
}), | ||
TypeOrmModule.forFeature([Contract]), | ||
CoinPriceHistoryModule, | ||
TransactionModule, | ||
], | ||
providers: [MarketService], | ||
controllers: [MarketController], | ||
exports: [MarketService], | ||
}) | ||
export class MarketModule {} |
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 { Injectable } from '@nestjs/common'; | ||
import moment from 'moment'; | ||
|
||
import { CoinPriceHistoryService } from '@dao-stats/common'; | ||
import { CoinPriceQuery } from '@dao-stats/common/dto'; | ||
import { CoinType } from '@dao-stats/common/types'; | ||
|
||
import { CoinPriceHistoryResponse } from './dto'; | ||
|
||
@Injectable() | ||
export class MarketService { | ||
constructor( | ||
private readonly coinPriceHistoryService: CoinPriceHistoryService, | ||
) {} | ||
|
||
async getCoinPriceHistory( | ||
coin: CoinType, | ||
query: CoinPriceQuery, | ||
): Promise<CoinPriceHistoryResponse[]> { | ||
const { currency, from, to } = query; | ||
|
||
const history = await this.coinPriceHistoryService.findByDateRange( | ||
coin, | ||
currency, | ||
from, | ||
to, | ||
); | ||
|
||
return history.map((price) => ({ | ||
...price, | ||
date: moment(price.date).valueOf(), | ||
})); | ||
} | ||
} |
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
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
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
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
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
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,12 @@ | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { CoinPriceHistory } from './entities/coin-price-history.entity'; | ||
import { CoinPriceHistoryService } from './coin-price-history.service'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([CoinPriceHistory])], | ||
providers: [CoinPriceHistoryService], | ||
exports: [CoinPriceHistoryService], | ||
}) | ||
export class CoinPriceHistoryModule {} |
Oops, something went wrong.