# Path: alephnull/protocol.py
# DATASOURCE_TYPE = Enum(
#     'AS_TRADED_EQUITY',
#     'MERGER',
#     'SPLIT',
#     'DIVIDEND',
#     'TRADE',
#     'TRANSACTION',
#     'ORDER',
#     'EMPTY',
#     'DONE',
#     'CUSTOM',
#     'BENCHMARK',
#     'COMMISSION'
# )


import abc
import math
import alephnull.utils.math_utils as zp_math
from copy import copy
from functools import partial
from alephnull.protocol import DATASOURCE_TYPE
    This is intended to be wrapped in a partial, so that the
    slippage and commission models can be enclosed.
    """
    for order, transaction in slippage(event, open_orders):
        if (
            transaction
        and not
        zp_math.tolerant_equals(transaction.amount, 0)
        ):
            direction = math.copysign(1, transaction.amount)
            per_share, total_commission = commission.calculate(transaction)
            transaction.price = transaction.price + (per_share * direction)
            transaction.commission = total_commission
        yield order, transaction


def transact_partial(slippage, commission):
    return partial(transact_stub, slippage, commission)


class Transaction(object):
    def __init__(self, sid, amount, dt, price, order_id=None, commission=None, contract=None):
        self.sid = sid
        if contract is not None:
            self.contract = contract
        self.amount = amount
        self.dt = dt
        self.price = price
        self.order_id = order_id
        self.commission = commission

# Path: alephnull/protocol.py
# DATASOURCE_TYPE = Enum(
#     'AS_TRADED_EQUITY',
#     'MERGER',
#     'SPLIT',
#     'DIVIDEND',
#     'TRADE',
#     'TRANSACTION',
#     'ORDER',
#     'EMPTY',
#     'DONE',
#     'CUSTOM',
#     'BENCHMARK',
#     'COMMISSION'
# )


# Path: alephnull/finance/slippage.py
import abc
import math
import alephnull.utils.math_utils as zp_math
from copy import copy
from functools import partial
from alephnull.protocol import DATASOURCE_TYPE

    This is intended to be wrapped in a partial, so that the
    slippage and commission models can be enclosed.
    """
    for order, transaction in slippage(event, open_orders):
        if (
            transaction
        and not
        zp_math.tolerant_equals(transaction.amount, 0)
        ):
            direction = math.copysign(1, transaction.amount)
            per_share, total_commission = commission.calculate(transaction)
            transaction.price = transaction.price + (per_share * direction)
            transaction.commission = total_commission
        yield order, transaction


def transact_partial(slippage, commission):
    return partial(transact_stub, slippage, commission)


class Transaction(object):
    def __init__(self, sid, amount, dt, price, order_id=None, commission=None, contract=None):
        self.sid = sid
        if contract is not None:
            self.contract = contract
        self.amount = amount
        self.dt = dt
        self.price = price
        self.order_id = order_id
        self.commission = commission

        self.type = DATASOURCE_TYPE.TRANSACTION