# Path: myutils.py
# def get_swapped_order(order):
#     # given a bid/ask price and volume being bought/sold,
#     # return the same order but as units of the reverse market.
#     c = copy.copy(order)
#     alts_per_base = c.p
#     vol_base = c.v
#     c.v = vol_base * alts_per_base
#     c.p = 1.0/alts_per_base
#     return c


import sys
from myutils import get_swapped_order
# class for Broker

class Broker(object):
    def __init__(self, mode, xchg):
        super(Broker, self).__init__()
        self.mode = mode # TRADING mode (PAPER or LIVE)
        self.xchg = xchg

        # stores live balances
        self.balances = {}

        #  self. depth consists of keys = the bases that I define in config, and each lists buy/sell orders
        #  for that market. However, the exchange subclass implementation should take care of whether I
        #  flip my market slugs or not.
        self.depth = {}
        self.orders = [] # list of outstanding orders

    def get_highest_bid(self, pair):
        base, alt = pair
        slug = base + "_" + alt
        if slug in self.depth and len(self.depth[slug]['bids']) > 0:
            return self.depth[slug]['bids'][0].p
        swapped_slug = alt + "_" + base
        if swapped_slug in self.depth and len(self.depth[swapped_slug]['asks']) > 0:
            print('WEIRD, this shouldn\'t being getting called!')
            ask = self.rates[swapped_slug]['asks'][0]

# Path: myutils.py
# def get_swapped_order(order):
#     # given a bid/ask price and volume being bought/sold,
#     # return the same order but as units of the reverse market.
#     c = copy.copy(order)
#     alts_per_base = c.p
#     vol_base = c.v
#     c.v = vol_base * alts_per_base
#     c.p = 1.0/alts_per_base
#     return c


# Path: Broker.py
import sys
from myutils import get_swapped_order

# class for Broker

class Broker(object):
    def __init__(self, mode, xchg):
        super(Broker, self).__init__()
        self.mode = mode # TRADING mode (PAPER or LIVE)
        self.xchg = xchg

        # stores live balances
        self.balances = {}

        #  self. depth consists of keys = the bases that I define in config, and each lists buy/sell orders
        #  for that market. However, the exchange subclass implementation should take care of whether I
        #  flip my market slugs or not.
        self.depth = {}
        self.orders = [] # list of outstanding orders

    def get_highest_bid(self, pair):
        base, alt = pair
        slug = base + "_" + alt
        if slug in self.depth and len(self.depth[slug]['bids']) > 0:
            return self.depth[slug]['bids'][0].p
        swapped_slug = alt + "_" + base
        if swapped_slug in self.depth and len(self.depth[swapped_slug]['asks']) > 0:
            print('WEIRD, this shouldn\'t being getting called!')
            ask = self.rates[swapped_slug]['asks'][0]

            return get_swapped_order(ask).p