# Path: utils.py

# 
# Path: order.py
# class Order(object):
#     def __init__(self, price, volume, type=None, pair=None, orderID=None, timestamp=None):
#         """
#         markets are usually expressed in terms of BASE_ALT where you buy
#         and sell units of BASE with ALT.
#         price = price (in units alt) of 1 unit of base
#         volume = total volume of base desired
#         orderID = necessary for tracking & cancelling & ignoring already executed orders when backtesting
#         """
#         self.p = price
#         self.v = volume
#         self.type = type # buy or sell
#         self.pair = pair # market we are trading on
#         self.id = orderID
#         self.time = timestamp


import config
from utils import total_base_volume
from order import Order
#         padded_buy_vol = min_base_vol * 1.0/(1.0 - askfee)
#         asks = self.clip_orders(asks, padded_buy_vol)
#
#         # check profits
#         bid_alt_recv = (1.0-bidfee) * sum([b.p*b.v for b in bids]) # units of alt to recv
#         ask_alt_give = sum([a.v*a.p for a in asks]) # units of alt to give
#         profit = bid_alt_recv - ask_alt_give
#         if profit > config.PROFIT_THRESH[alt]:
#             print('WOOHOO! Profitable, EXECUTABLE arbitrage detected')
#             bidder_order = (bids[-1].p , min_base_vol) # sell at the "lowest" price of profitable asks to fill as much as possible
#             asker_order  = (asks[-1].p , padded_buy_vol)  # buy at the "highest" price of profitable bids to fill as much as possible
#         else:
#             bidder_order, asker_order, profit = (None, None, profit)
#         return {
#                 "bidder_order":bidder_order,
#                 "asker_order":asker_order,
#                 "profit":profit,
#                 "bidder_recv":bid_alt_recv,
#                 "bidder_give":min_base_vol,
#                 "asker_give":ask_alt_give,
#                 "asker_recv":min_base_vol
#                 }

    def clip_orders(self, orders, desired_volume):
        # given an array of bid or ask orders,
        # and a desired volume, resize the orders so that
        # the total volume == desired_volume
        #total_volume = lambda arr : sum([a.v for a in arr])
        # volume = total_volume(orders) # original volume, in units base
        i = 1

# Path: utils.py

# 
# Path: order.py
# class Order(object):
#     def __init__(self, price, volume, type=None, pair=None, orderID=None, timestamp=None):
#         """
#         markets are usually expressed in terms of BASE_ALT where you buy
#         and sell units of BASE with ALT.
#         price = price (in units alt) of 1 unit of base
#         volume = total volume of base desired
#         orderID = necessary for tracking & cancelling & ignoring already executed orders when backtesting
#         """
#         self.p = price
#         self.v = volume
#         self.type = type # buy or sell
#         self.pair = pair # market we are trading on
#         self.id = orderID
#         self.time = timestamp


# Path: ProfitCalculator.py
import config
from utils import total_base_volume
from order import Order

#         padded_buy_vol = min_base_vol * 1.0/(1.0 - askfee)
#         asks = self.clip_orders(asks, padded_buy_vol)
#
#         # check profits
#         bid_alt_recv = (1.0-bidfee) * sum([b.p*b.v for b in bids]) # units of alt to recv
#         ask_alt_give = sum([a.v*a.p for a in asks]) # units of alt to give
#         profit = bid_alt_recv - ask_alt_give
#         if profit > config.PROFIT_THRESH[alt]:
#             print('WOOHOO! Profitable, EXECUTABLE arbitrage detected')
#             bidder_order = (bids[-1].p , min_base_vol) # sell at the "lowest" price of profitable asks to fill as much as possible
#             asker_order  = (asks[-1].p , padded_buy_vol)  # buy at the "highest" price of profitable bids to fill as much as possible
#         else:
#             bidder_order, asker_order, profit = (None, None, profit)
#         return {
#                 "bidder_order":bidder_order,
#                 "asker_order":asker_order,
#                 "profit":profit,
#                 "bidder_recv":bid_alt_recv,
#                 "bidder_give":min_base_vol,
#                 "asker_give":ask_alt_give,
#                 "asker_recv":min_base_vol
#                 }

    def clip_orders(self, orders, desired_volume):
        # given an array of bid or ask orders,
        # and a desired volume, resize the orders so that
        # the total volume == desired_volume
        #total_volume = lambda arr : sum([a.v for a in arr])
        # volume = total_volume(orders) # original volume, in units base
        i = 1

        while total_base_volume(orders[:i]) < desired_volume: