def client():
    """Client that connects to sandbox API. Relies on authentication information
    provided in api_config.json"""
    with open('api_config.json.example') as file:
        api_config = json.load(file)
    c = AuthenticatedClient(
        api_url='https://api-public.sandbox.pro.coinbase.com', **api_config)

    # Set up account with deposits and orders. Do this by depositing from
    # the Coinbase USD wallet, which has a fixed value of > $10,000.
    #
    # Only deposit if the balance is below some nominal amount. The
    # exchange seems to freak out if you run up your account balance.
    coinbase_accounts = c.get_coinbase_accounts()
    account_info = [x for x in coinbase_accounts
                    if x['name'] == 'USD Wallet'][0]
    account_usd = account_info['id']
    if float(account_info['balance']) < 70000:
        c.coinbase_deposit(10000, 'USD', account_usd)
    # Place some orders to generate history
    c.place_limit_order('BTC-USD', 'buy', 1, 0.01)
    c.place_limit_order('BTC-USD', 'buy', 2, 0.01)
    c.place_limit_order('BTC-USD', 'buy', 3, 0.01)

    return c
    def __init__(
            self, key: str, b64secret: str, passphrase: str,
            api_url="https://api.pro.coinbase.com"):

        super(CBProAuthenticatedClient, self).__init__(
            key, b64secret, passphrase, api_url)

        self.auth_client = AuthenticatedClient(
            key=key,
            b64secret=b64secret,
            passphrase=passphrase,
            api_url=api_url
        )
def client():
    """Client that connects to sandbox API. Relies on authentication information
    provided in api_config.json"""
    with open('api_config.json.example') as file:
        api_config = json.load(file)
    c = AuthenticatedClient(
        api_url='https://api-public.sandbox.pro.coinbase.com', **api_config)

    # Set up account with deposits and orders. Do this by depositing from
    # the Coinbase USD wallet, which has a fixed value of > $10,000.
    #
    # Only deposit if the balance is below some nominal amount. The
    # exchange seems to freak out if you run up your account balance.
    coinbase_accounts = c.get_coinbase_accounts()
    account_info = [x for x in coinbase_accounts
                    if x['name'] == 'USD Wallet'][0]
    account_usd = account_info['id']
    if float(account_info['balance']) < 70000:
        c.coinbase_deposit(10000, 'USD', account_usd)
    # Place some orders to generate history
    c.place_limit_order('BTC-USD', 'buy', 1, 0.01)
    c.place_limit_order('BTC-USD', 'buy', 2, 0.01)
    c.place_limit_order('BTC-USD', 'buy', 3, 0.01)

    return c
def dc():
    """Dummy client for testing."""
    return AuthenticatedClient('test', 'test', 'test')
class CBProAuthenticatedClient(MyAuthenticatedClient):
    def __init__(
            self, key: str, b64secret: str, passphrase: str,
            api_url="https://api.pro.coinbase.com"):

        super(CBProAuthenticatedClient, self).__init__(
            key, b64secret, passphrase, api_url)

        self.auth_client = AuthenticatedClient(
            key=key,
            b64secret=b64secret,
            passphrase=passphrase,
            api_url=api_url
        )

    def get_time(self) -> dict:
        """[summary]

        Returns:
            dict -- Dict {
                'iso': 'YYYY-MM-DDThh:mm:ss.fffZ',
                'epoch': UNIX epoch
                }
        """
        return self.auth_client.get_time()

    def get_accounts(self) -> list:
        """Get a summary of all accounts with different currencies.

        Returns:
            list -- List of dicts containing keys
                            ['id', 'currency' 'balance', 'available']
        """
        return self.auth_client.get_accounts()

    def buy_taker(self, product: str, funds: str) -> dict:
        """Issue a buy order on the taker (market) side.

        Arguments:
            product {str} -- e.g. 'BTC-EUR'
            funds {float} -- The amount of funds in base currency to use

        Returns:
            dict -- with keys ['id', 'product_id', 'side', 'funds',
                'specified_funds', 'executed_value', 'filled_size', 'type',
                'created_at', 'done_at', 'fill_fees', 'status', 'settled']
        """
        return self.auth_client.place_market_order(
            product_id=product,
            side='buy',
            funds=funds
        )

    def buy_maker(self, product: str, price: str, size: str) -> dict:
        """Issue a buy order on the maker (limit) side.

        Arguments:
            product {str} -- [description]
            price {str} -- [description]
            size {str} -- [description]

        Returns:
            dict -- [description]
        """
        pass

    def sell_taker(self, product: str, size: str) -> dict:
        """Issue a sell order on the taker (market) side.

        Arguments:
            product {str} -- e.g. 'BTC-EUR'
            funds {float} -- The amount of funds in base currency to use

        Returns:
            dict -- [description]
        """
        return self.auth_client.place_market_order(
            product_id=product,
            side='sell',
            size=size
        )

    def sell_maker(self, product: str, price: str, size: str) -> dict:
        """Issue a sell order on the maker (limit) side.

        Arguments:
            product {str} -- [description]
            price {str} -- [description]
            size {str} -- [description]

        Returns:
            dict -- [description]
        """
        pass

    def get_order(self, order_id: str) -> dict:
        """Get updated information on a placed order

        Arguments:
            id {str} -- The id by with to identify the order.

        Returns:
            dict -- Dictionary with keys ['id', 'product_id', 'side', 'funds',
                'specified_funds', 'executed_value', 'filled_size', 'type',
                'created_at', 'done_at', 'fill_fees', 'status', 'settled']
        """
        return self.auth_client.get_order(order_id)