Exemplo n.º 1
0
    def test_buy_price(self):
        exchange = Coinbase(auth=self.auth, sandbox=True)
        receipt = None

        errors = False
        price = 0
        try:
            receipt = exchange.buy(1, 'BTC-USD', price)
        except cbex.InvalidPrice:
            errors = True
        self.assertTrue(receipt is None)
        self.assertTrue(errors)

        errors = False
        price = -1
        try:
            receipt = exchange.buy(1, 'BTC-USD', price)
        except cbex.InvalidPrice:
            errors = True
        self.assertTrue(receipt is None)
        self.assertTrue(errors)

        errors = False
        price = 1000000000000
        try:
            receipt = exchange.buy(1, 'BTC-USD', price)
        except cbex.InternalServerErrror:
            errors = True
        self.assertTrue(receipt is None)
        self.assertTrue(errors)
Exemplo n.º 2
0
 def test_buy_insufficient_funds(self):
     exchange = Coinbase(auth=self.auth, sandbox=True)
     receipt = None
     errors = False
     try:
         receipt = exchange.buy(1, 'BTC-USD', 10000000000)
     except cbex.InsufficientFunds:
         errors = True
     self.assertTrue(errors)
     self.assertTrue(receipt is None)
Exemplo n.º 3
0
 def test_buy_auth(self):
     receipt = None
     errors = False
     exchange = Coinbase(sandbox=True)
     try:
         receipt = exchange.buy(1, 'BTC-USD', 1)
     except cbex.AuthenticationError:
         errors = True
     self.assertTrue(errors)
     self.assertTrue(receipt is None)
Exemplo n.º 4
0
 def test_buy_symbol(self):
     exchange = Coinbase(auth=self.auth, sandbox=True)
     receipt = None
     errors = False
     try:
         receipt = exchange.buy(1, 'BTC', 1)
     except cbex.InvalidSymbol:
         errors = True
     self.assertTrue(receipt is None)
     self.assertTrue(errors)
Exemplo n.º 5
0
    def test_buy_size(self):
        exchange = Coinbase(auth=self.auth, sandbox=True)
        receipt = None
        errors = False
        size = 0
        try:
            receipt = exchange.buy(size, 'BTC-USD', 1)
        except cbex.InvalidSize:
            errors = True
        self.assertTrue(receipt is None)
        self.assertTrue(errors)

        errors = False
        size = 1000000000
        try:
            receipt = exchange.buy(size, 'BTC-USD', 1)
        except cbex.InvalidSize:
            errors = True
        self.assertTrue(receipt is None)
        self.assertTrue(errors)
Exemplo n.º 6
0
    def test_cancel(self):
        exchange = Coinbase(auth=self.auth, sandbox=True)
        buy = exchange.buy(1, self.symbol, 1)
        cancel = exchange.cancel_order(buy['id'])
        self.assertTrue(buy['id'] in cancel)

        error = False
        try:
            cancel = exchange.cancel_order('invalid')
        except cbex.InvalidOrder:
            error = True
        self.assertTrue(error)
Exemplo n.º 7
0
 def test_buy(self):
     exchange = Coinbase(auth=self.auth, sandbox=True)
     receipt = None
     errors = False
     try:
         receipt = exchange.buy(1, 'BTC-USD', 1)
     except cbex.ExchangeError:
         errors = True
     self.assertFalse(errors)
     self.assertTrue(receipt is not None)
     self.assertTrue('id' in receipt)
     self.assertTrue('price' in receipt)
     self.assertTrue('size' in receipt)
     self.assertTrue(receipt['side'] == 'buy')