9
9
10
10
_LOGGER = logging .getLogger (__name__ )
11
11
12
- EXCHANGE_CURRENCY_LIST = ["KRW" , "USD" , "JPY" ]
12
+ FROM_EXCHANGE_CURRENCIES = ["KRW" , "USD" , "JPY" ]
13
13
14
14
15
15
class CurrencyConnector (BaseConnector ):
@@ -18,34 +18,26 @@ def __init__(self, *args, **kwargs):
18
18
self .today = datetime .utcnow ()
19
19
self .today_date = self .today .strftime ("%Y-%m-%d" )
20
20
self .two_weeks_ago = (self .today - timedelta (days = 14 )).strftime ("%Y-%m-%d" )
21
+ self .currency_date = None
21
22
22
- def add_exchange_rate (self , aggregated_cost_report : dict ) -> dict :
23
- current_currency_dict = aggregated_cost_report . get ( "cost" )
24
- cost = {}
23
+ def add_currency_map_date (self , to_currency : str ) -> tuple [ dict , str ] :
24
+ currency_map = {}
25
+ _currency_date = ""
25
26
26
- for current_currency , current_cost in current_currency_dict .items ():
27
- exchange_rate_cost = self ._calculate_exchange_rate (
28
- current_currency , current_cost
29
- )
30
- cost .update ({current_currency : exchange_rate_cost })
31
-
32
- aggregated_cost_report .update ({"cost" : cost })
33
- return aggregated_cost_report
34
-
35
- def _calculate_exchange_rate (self , from_currency : str , amount : float ) -> float :
36
- exchange_rates = {}
37
-
38
- for to_currency in EXCHANGE_CURRENCY_LIST :
27
+ for from_currency in FROM_EXCHANGE_CURRENCIES :
39
28
if from_currency == to_currency :
40
29
exchange_rate = 1.0
41
30
else :
42
- pair = f"{ from_currency } /{ to_currency } "
43
- exchange_rate_info = fdr .DataReader (
44
- pair , self .two_weeks_ago , self .today_date
45
- )["Close" ].dropna ()
46
- exchange_rate = exchange_rate_info .iloc [- 1 ]
47
-
48
- exchange_rates [to_currency ] = exchange_rate
49
-
50
- exchange_rate_cost = amount * exchange_rates [from_currency ]
51
- return exchange_rate_cost
31
+ pair = f"{ to_currency } /{ from_currency } "
32
+ exchange_rate_info = (
33
+ fdr .DataReader (pair , self .two_weeks_ago , self .today_date )
34
+ .dropna ()
35
+ .reset_index ()[["Date" , "Close" ]]
36
+ )
37
+ _currency_date , exchange_rate = exchange_rate_info .iloc [- 1 ]
38
+ currency_map [from_currency ] = exchange_rate
39
+
40
+ if self .currency_date is None :
41
+ self .currency_date = _currency_date
42
+
43
+ return currency_map , self .currency_date
0 commit comments