-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REFACTOR] #70 - StockChart.js를 MVC 패턴으로
- Loading branch information
Showing
5 changed files
with
184 additions
and
301 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,40 @@ | ||
import { fetchCoinPriceHistories } from '../../model/exchange/StockChartModel'; | ||
|
||
// 코인 가격 데이터 정리 | ||
export function processCoinHistoryData(histories, is10Minute, is30Minute, is1Hour) { | ||
const data = []; | ||
const interval = is10Minute ? 10 : is30Minute ? 30 : 60; | ||
|
||
for (let i = 0; i < histories.length; i += interval) { | ||
data.unshift(histories[i].price); | ||
} | ||
|
||
return data; | ||
} | ||
|
||
// 시간 간격에 따라 데이터를 가져오는 함수 | ||
export async function loadCoinData(coins, chartWidth, setCoinData, token, timeOptions) { | ||
const { is10Minute, is30Minute, is1Hour } = timeOptions; | ||
|
||
const currentDate = new Date(); | ||
const pastDate = new Date(); | ||
const subTime = (chartWidth - 44 - 1) / (88 + 1) + 1; | ||
|
||
if (is10Minute) { | ||
pastDate.setMinutes(pastDate.getMinutes() - (subTime * 10) - 1); | ||
} else if (is30Minute) { | ||
pastDate.setMinutes(pastDate.getMinutes() - (subTime * 30) - 1); | ||
} else if (is1Hour) { | ||
pastDate.setHours(pastDate.getHours() - subTime - 1); | ||
} | ||
|
||
setCoinData({}); // 데이터 초기화 | ||
|
||
const updatedCoinData = {}; | ||
for (let coin of coins) { | ||
const histories = await fetchCoinPriceHistories(coin.id, currentDate, pastDate, token); | ||
updatedCoinData[coin.id] = processCoinHistoryData(histories, is10Minute, is30Minute, is1Hour); | ||
} | ||
|
||
setCoinData(updatedCoinData); | ||
} |
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,26 @@ | ||
import client from 'gamja-backend-client'; | ||
|
||
// API 호출 및 데이터 가공을 담당하는 Model | ||
const host = 'https://api.miruku.dog'; | ||
|
||
const getConnection = (token) => { | ||
return { | ||
host: host, | ||
headers: { | ||
...token ? { 'Authorization': `Bearer ${token}` } : null | ||
} | ||
} | ||
} | ||
|
||
// 코인 가격 기록을 가져오는 함수 | ||
export async function fetchCoinPriceHistories(coinId, currentDate, pastDate, token) { | ||
const response = await client.functional.coin.price_histories.getPriceHistories( | ||
getConnection(token), | ||
coinId, | ||
{ | ||
from: pastDate.toString(), | ||
to: currentDate.toString() | ||
} | ||
); | ||
return response.histories; | ||
} |
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
Oops, something went wrong.