# Path: OnePy/builtin_module/backtest_forex/calculate_func.py
# def dollar_per_pips(ticker, cur_price):
#     """外汇专用"""
# 
#     if ticker[:3] == 'USD':
#         return 10/cur_price
#     elif ticker[-3:] == 'USD':
#         return 10
#     else:
#         raise Exception("Could only backtest in USD currency pairs.")
# 
# def market_value_multiplayer(ticker, cur_price):
#     """外汇专用"""
# 
#     if ticker[:3] == 'USD':
#         return 1
#     elif ticker[-3:] == 'USD':
#         return cur_price
#     else:
#         raise Exception("Could only backtest in USD currency pairs.")
# 
# Path: OnePy/constants.py
# class ActionType(Enum):
# 
#     Buy = 'Buy'
#     Sell = 'Sell'
#     Short = 'Short'
#     Cover = 'Cover'
# 
#     Exit_all = 'Exit_all'
#     Cancel = 'Cancel'
# 
# Path: OnePy/sys_module/models/base_series.py
# class CommissionSeriesBase(SeriesBase):
#     name = 'commission'
# 
#     @abc.abstractmethod
#     def update_order(self, ticker, size, execute_price, action_type,
#                      last_commission,  long_or_short='long'):
#         raise NotImplementedError
# 
# class HoldingPnlSeriesBase(SeriesBase):
#     name = 'holding_pnl'
# 
#     @abc.abstractmethod
#     def update_order(self, ticker, cur_price, new_avg_price,
#                      new_position, long_or_short='long'):
#         raise NotImplementedError
# 
#     @abc.abstractmethod
#     def update_barly(self, order_executed: bool):
#         raise NotImplementedError
# 
# class MarginSeriesBase(SeriesBase):
#     name = 'margin'
# 
#     @abc.abstractmethod
#     def update_order(self, ticker, long_or_short='long'):
#         raise NotImplementedError
# 
#     @abc.abstractmethod
#     def update_barly(self):
#         raise NotImplementedError
# 
# class MarketValueSeriesBase(SeriesBase):
#     name = 'market_value'
# 
#     @abc.abstractmethod
#     def update_order(self, ticker, cur_price, new_position,
#                      long_or_short='long'):
# 
#         raise NotImplementedError
# 
#     @abc.abstractmethod
#     def update_barly(self, order_executed: bool):
#         raise NotImplementedError
# 
# class RealizedPnlSeriesBase(SeriesBase):
#     name = 'realized_pnl'
# 
#     @abc.abstractmethod
#     def update_order(self, ticker, size, execute_price, action_type,
#                      last_avg_price, long_or_short='long'):
#         raise NotImplementedError


from OnePy.builtin_module.backtest_forex.calculate_func import (dollar_per_pips,
                                                                market_value_multiplayer)
from OnePy.constants import ActionType
from OnePy.sys_module.models.base_series import (CommissionSeriesBase,
                                                 HoldingPnlSeriesBase,
                                                 MarginSeriesBase,
                                                 MarketValueSeriesBase,
                                                 RealizedPnlSeriesBase)


class RealizedPnlSeries(RealizedPnlSeriesBase):
    name = 'realized_pnl'

    def update_order(self, ticker, size, execute_price, action_type,
                     last_avg_price, long_or_short='long'):
        new_value = None

        if action_type == ActionType.Sell:
            new_value = (self.latest(ticker, long_or_short) +
                         (execute_price - last_avg_price) * size *
                         dollar_per_pips(ticker, execute_price))

# Path: OnePy/builtin_module/backtest_forex/calculate_func.py
# def dollar_per_pips(ticker, cur_price):
#     """外汇专用"""
# 
#     if ticker[:3] == 'USD':
#         return 10/cur_price
#     elif ticker[-3:] == 'USD':
#         return 10
#     else:
#         raise Exception("Could only backtest in USD currency pairs.")
# 
# def market_value_multiplayer(ticker, cur_price):
#     """外汇专用"""
# 
#     if ticker[:3] == 'USD':
#         return 1
#     elif ticker[-3:] == 'USD':
#         return cur_price
#     else:
#         raise Exception("Could only backtest in USD currency pairs.")
# 
# Path: OnePy/constants.py
# class ActionType(Enum):
# 
#     Buy = 'Buy'
#     Sell = 'Sell'
#     Short = 'Short'
#     Cover = 'Cover'
# 
#     Exit_all = 'Exit_all'
#     Cancel = 'Cancel'
# 
# Path: OnePy/sys_module/models/base_series.py
# class CommissionSeriesBase(SeriesBase):
#     name = 'commission'
# 
#     @abc.abstractmethod
#     def update_order(self, ticker, size, execute_price, action_type,
#                      last_commission,  long_or_short='long'):
#         raise NotImplementedError
# 
# class HoldingPnlSeriesBase(SeriesBase):
#     name = 'holding_pnl'
# 
#     @abc.abstractmethod
#     def update_order(self, ticker, cur_price, new_avg_price,
#                      new_position, long_or_short='long'):
#         raise NotImplementedError
# 
#     @abc.abstractmethod
#     def update_barly(self, order_executed: bool):
#         raise NotImplementedError
# 
# class MarginSeriesBase(SeriesBase):
#     name = 'margin'
# 
#     @abc.abstractmethod
#     def update_order(self, ticker, long_or_short='long'):
#         raise NotImplementedError
# 
#     @abc.abstractmethod
#     def update_barly(self):
#         raise NotImplementedError
# 
# class MarketValueSeriesBase(SeriesBase):
#     name = 'market_value'
# 
#     @abc.abstractmethod
#     def update_order(self, ticker, cur_price, new_position,
#                      long_or_short='long'):
# 
#         raise NotImplementedError
# 
#     @abc.abstractmethod
#     def update_barly(self, order_executed: bool):
#         raise NotImplementedError
# 
# class RealizedPnlSeriesBase(SeriesBase):
#     name = 'realized_pnl'
# 
#     @abc.abstractmethod
#     def update_order(self, ticker, size, execute_price, action_type,
#                      last_avg_price, long_or_short='long'):
#         raise NotImplementedError


# Path: OnePy/builtin_module/backtest_forex/forex_recorder_series.py
from OnePy.builtin_module.backtest_forex.calculate_func import (dollar_per_pips,
                                                                market_value_multiplayer)
from OnePy.constants import ActionType
from OnePy.sys_module.models.base_series import (CommissionSeriesBase,
                                                 HoldingPnlSeriesBase,
                                                 MarginSeriesBase,
                                                 MarketValueSeriesBase,
                                                 RealizedPnlSeriesBase)



class RealizedPnlSeries(RealizedPnlSeriesBase):
    name = 'realized_pnl'

    def update_order(self, ticker, size, execute_price, action_type,
                     last_avg_price, long_or_short='long'):
        new_value = None

        if action_type == ActionType.Sell:
            new_value = (self.latest(ticker, long_or_short) +
                         (execute_price - last_avg_price) * size *
                         dollar_per_pips(ticker, execute_price))

        elif action_type == ActionType.Cover: