<commit_before>import pytz
import math

from functools import partial

import zipline.protocol as zp

def transact_stub(slippage, commission, open_orders, events):
    """
    This is intended to be wrapped in a partial, so that the
    slippage and commission models can be enclosed.
    """
    transaction = slippage.simulate(open_orders, events)
    if transaction:
        per_share, total_commission = commission.calculate(transaction)
        transaction.price = transaction.price + per_share
        transaction.commission = total_commission
    return transaction


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

def create_transaction(sid, amount, price, dt):

    txn = {'sid'            : sid,
                'amount'        : int(amount),
                'dt'            : dt,
                'price'         : price,
          }

    transaction = zp.ndict(txn)
    return transaction


class VolumeShareSlippage(object):<commit_msg>fixed bug where commission ignored order direction<commit_after>import pytz
import math

from functools import partial

import zipline.protocol as zp

def transact_stub(slippage, commission, open_orders, events):
    """
    This is intended to be wrapped in a partial, so that the
    slippage and commission models can be enclosed.
    """

    transaction = slippage.simulate(open_orders, events)
    if transaction and transaction.amount != 0:
        direction = abs(transaction.amount) / transaction.amount
        per_share, total_commission = commission.calculate(transaction)
        transaction.price = transaction.price + (per_share * direction)
        transaction.commission = total_commission
    return transaction


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

def create_transaction(sid, amount, price, dt):

    txn = {'sid'            : sid,
                'amount'        : int(amount),
                'dt'            : dt,
                'price'         : price,
          }

    transaction = zp.ndict(txn)
    return transaction


class VolumeShareSlippage(object):
{'fraction_non_alphanumeric': 0.07724523033969288, 'fraction_numerical': 0.00046533271288971617, 'mean_word_length': 2.739130434782609, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4199341', 'n_tokens_mistral': 589, 'n_tokens_neox': 580, 'n_words': 168}