Пример #1
0
        async def run_test():

            lib = BitsgapClient(public_key, private_key)

            result = lib.keys()

            logging.debug(result)

            self.assertTrue(result['status'] == 'ok')
            self.assertIn('data', result)

            data = result['data']

            self.assertIsNotNone(data)

            self.assertTrue(len(data) > 0)

            market = list(data.keys())[0]

            market_data = data[market]

            self.assertIn('key', market_data)
            self.assertIn('status', market_data)
            self.assertIn('uts', market_data)

            await asyncio.sleep(1)
        async def run_test():

            lib = BitsgapClient(public_key, private_key)

            result = lib.messages()

            logging.debug(result)

            self.assertIn('status', result)
            self.assertTrue(result['status'] == 'ok')
            self.assertIn('time', result)

            self.assertIn('data', result)
            data = result['data']

            self.assertIsNotNone(data)
            self.assertTrue(len(data) > 0)

            message = data[0]

            self.assertIn('t', message)
            self.assertIn('type', message)
            self.assertIn('trade', message)
            self.assertIn('text', message)

            await asyncio.sleep(1)
        async def run_test():

            market = 'okex'
            pair = 'ETH_BTC'
            price = '0.015'
            amount = '0.1'
            side = 'buy'
            ord_type = 'limit'

            lib = BitsgapClient(public_key, private_key)

            result = lib.orders_add(market, pair, amount, price, side,
                                    ord_type)

            logging.debug(result)

            self.assertIsNotNone(result)

            self.assertTrue(result['status'] == 'ok')
            self.assertIn('data', result)

            data = result['data'] if 'data' in result else None

            self.assertIsNotNone(data)

            self.assertIn('id', data)
            self.assertIn('price', data)
            self.assertIn('amount', data)
            self.assertIn('pair', data)
            self.assertIn('side', data)
            self.assertIn('type', data)

            await asyncio.sleep(1)
        async def run_test():

            market = 'okex'

            lib = BitsgapClient(public_key, private_key)

            result = lib.orders_open(market)

            logging.debug(result)

            self.assertIn('status', result)
            self.assertTrue(result['status'] == 'ok')
            self.assertIn('time', result)

            if 'message' in result:
                self.assertTrue(result['message'] == 'Data not found') # no open orders
            else:
                self.assertIn('data', result)
                data = result['data']
                self.assertTrue(len(data) > 0)
                # check fields
                self.assertIn('id', data[0])
                self.assertIn('price', data[0])
                self.assertIn('amount', data[0])
                self.assertIn('pair', data[0])
                self.assertIn('amount_init', data[0])
                self.assertIn('state', data[0])
                self.assertIn('type', data[0])
                self.assertIn('side', data[0])
                self.assertIn('uts', data[0])

            await asyncio.sleep(1)
        async def run_test():

            lib = BitsgapClient(public_key, private_key)

            result = lib.demo_balance()

            logging.debug(result)

            self.assertIn('status', result)
            self.assertTrue(result['status'] == 'ok')
            self.assertIn('data', result)
            self.assertIn('time', result)

            data = result['data']

            self.assertIsNotNone(data)

            self.assertTrue(len(data) > 0)

            # get market name
            market = list(data.keys())[0]
            # get information for market from response
            market_data = data[market]
            # check fields
            self.assertIn('balance', market_data)
            self.assertIn('total', market_data)

            await asyncio.sleep(1)
Пример #6
0
        async def run_test():

            market = 'okex'
            pair = 'ETH_BTC'
            start = int(time.time() - 3600)
            end = int(time.time())

            lib = BitsgapClient(public_key, private_key)

            result = lib.ohlc(market, pair, start, end)

            logging.debug(result)

            self.assertTrue(result['status'] == 'ok')
            self.assertIn('data', result)

            data = result['data']

            self.assertTrue(len(data)> 0)

            item = data[0]

            self.assertIn('open', item)
            self.assertIn('high', item)
            self.assertIn('low', item)
            self.assertIn('close', item)
            self.assertIn('time', item)
            self.assertIn('volume', item)

            volume = item['volume']

            self.assertIn('buy', volume)
            self.assertIn('buy', volume)

            await asyncio.sleep(1)
Пример #7
0
        async def run_test():

            market = 'okex'
            pair = 'ETH_BTC'

            lib = BitsgapClient(public_key, private_key)

            result = lib.recent_trades(market, pair)

            logging.debug(result)

            self.assertTrue(result['status'] == 'ok')
            self.assertIn('data', result)

            data = result['data']
            self.assertIsNotNone(data)
            self.assertTrue(len(data) > 0)

            # check time field
            self.assertIn('u', data[0])
            # check amount field
            self.assertIn('am', data[0])
            # check side field
            self.assertIn('s', data[0])
            # check price field
            self.assertIn('p', data[0])

            await asyncio.sleep(1)
Пример #8
0
        async def run_test():

            lib = BitsgapClient(public_key, private_key)

            result = lib.markets()

            logging.debug(result)

            self.assertTrue(result['status'] == 'ok')
            self.assertIn('data', result)

            await asyncio.sleep(1)
Пример #9
0
        async def run_test():

            market = 'okex'

            lib = BitsgapClient(public_key, private_key)

            # get open orders
            result = lib.orders_open(market)

            logging.debug(result)

            self.assertIsNotNone(result)

            self.assertTrue(result['status'] == 'ok')
            self.assertIn('data', result)

            data = result['data']

            self.assertIsNotNone(data)
            self.assertTrue(len(data) > 0)
            self.assertIn('id', data[0])

            id = data[0]['id']
            self.assertIsNotNone(id)

            old_price = data[0]['price']
            self.assertIsNotNone(old_price)
            new_price = float(old_price) * 0.999

            result_move = lib.orders_move(market, id, str(new_price))

            logging.debug(result_move)

            self.assertIn('status', result_move)
            self.assertTrue(result_move['status'] == 'ok')
            self.assertIn('data', result_move)
            self.assertIn('time', result_move)

            data = result_move['data']

            self.assertIsNotNone(data)

            self.assertIn('id', data)
            self.assertIn('price', data)
            self.assertIn('amount_init', data)
            self.assertIn('pair', data)
            self.assertIn('state', data)
            self.assertIn('type', data)
            self.assertIn('side', data)
            self.assertIn('uts', data)
            self.assertIn('amount', data)

            await asyncio.sleep(1)
Пример #10
0
        async def run_test():
            market = 'invalid'
            id = '123'

            lib = BitsgapClient(public_key, private_key)

            result_cancel = lib.demo_orders_cancel(market, id)

            self.assertIn('status', result_cancel)
            self.assertTrue(result_cancel['status'] == 'error')
            self.assertIn('time', result_cancel)
            self.assertIn('message', result_cancel)

            await asyncio.sleep(1)
Пример #11
0
        async def run_test():
            market = 'okex'
            pair = 'no_pair'

            lib = BitsgapClient(public_key, private_key)

            result = lib.recent_trades(market, pair)

            logging.debug(result)

            self.assertTrue(result['status'] == 'error')
            self.assertIn('message', result)

            await asyncio.sleep(1)
Пример #12
0
        async def run_test():

            market = 'okex'

            lib = BitsgapClient(public_key, private_key)

            # get open orders
            result = lib.orders_open(market)

            logging.debug(result)

            self.assertIsNotNone(result)

            self.assertTrue(result['status'] == 'ok')
            self.assertIn('data', result)

            data = result['data']

            self.assertIsNotNone(data)
            self.assertTrue(len(data) > 0)
            self.assertIn('id', data[0])

            id = data[0]['id']

            self.assertIsNotNone(id)

            result_cancel = lib.orders_cancel(market, id)

            logging.debug(result_cancel)

            self.assertIn('status', result_cancel)
            self.assertTrue(result_cancel['status'] == 'ok')
            self.assertIn('data', result_cancel)
            self.assertIn('time', result_cancel)

            data = result_cancel['data']

            self.assertIsNotNone(data)

            self.assertIn('id', data)
            self.assertIn('price', data)
            self.assertIn('amount_init', data)
            self.assertIn('pair', data)
            self.assertIn('state', data)
            self.assertIn('type', data)
            self.assertIn('side', data)
            self.assertIn('uts', data)
            self.assertIn('amount', data)

            await asyncio.sleep(1)
Пример #13
0
        async def run_test():

            market = 'no_market'
            pair = 'ETH_BTC'

            lib = BitsgapClient(public_key, private_key)

            result = lib.last_price(market, pair)

            logging.debug(result)

            self.assertTrue(result['status'] == 'error')
            self.assertIn('message', result)

            await asyncio.sleep(1)
        async def run_test():

            market = 'invalid_market'

            lib = BitsgapClient(public_key, private_key)

            result = lib.orders_open(market)

            logging.debug(result)

            self.assertIn('status', result)
            self.assertTrue(result['status'] == 'error')
            self.assertIn('message', result)
            self.assertIn('time', result)

            await asyncio.sleep(1)
Пример #15
0
        async def run_test():

            market = 'okex'
            pair = 'no_pair'
            start = int(time.time()) - 3600
            end = int(time.time())

            lib = BitsgapClient(public_key, private_key)

            result = lib.ohlc(market, pair, start, end)

            logging.debug(result)

            self.assertTrue(result['status'] == 'error')
            self.assertIn('message', result)

            await asyncio.sleep(1)
        async def run_test():

            market = 'invalid'

            lib = BitsgapClient(public_key, private_key)

            id = 'invalid'
            new_price = '0.01'

            result_move = lib.demo_orders_move(market, id, new_price)

            self.assertIn('status', result_move)
            self.assertTrue(result_move['status'] == 'error')
            self.assertIn('message', result_move)
            self.assertIn('time', result_move)

            await asyncio.sleep(1)
Пример #17
0
        async def run_test():

            market = 'okex'
            pair = 'ETH_BTC'

            lib = BitsgapClient(public_key, private_key)

            result = lib.last_price(market, pair)

            logging.debug(result)

            self.assertTrue(result['status'] == 'ok')
            self.assertIn('data', result)

            data = result['data']

            self.assertIn('ask', data)
            self.assertIn('bid', data)

            await asyncio.sleep(1)
Пример #18
0
        async def run_test():
            market = 'okex'
            pair = 'ETH_BTC'
            price = '0.015'
            amount = '0'
            side = 'buy'
            ord_type = 'limit'

            lib = BitsgapClient(public_key, private_key)

            result = lib.demo_orders_add(market, pair, amount, price, side,
                                         ord_type)

            logging.debug(result)

            self.assertIn('time', result)
            self.assertIn('status', result)
            self.assertTrue(result['status'] == 'error')

            await asyncio.sleep(1)
        async def run_test():
            market = 'okex'
            pair = 'invalid_pair'
            price = '0.015'
            amount = '0.1'
            side = 'buy'
            ord_type = 'limit'

            lib = BitsgapClient(public_key, private_key)

            result = lib.orders_add(market, pair, amount, price, side,
                                    ord_type)

            logging.debug(result)

            self.assertIsNotNone(result)

            self.assertTrue(result['status'] == 'error')
            self.assertIn('message', result)

            await asyncio.sleep(1)
Пример #20
0
        async def run_test():

            market = 'okex'

            lib = BitsgapClient(public_key, private_key)

            # get executed orders
            result = lib.orders_history(market)

            logging.debug(result)

            self.assertIsNotNone(result)

            self.assertTrue(result['status'] == 'ok')
            self.assertIn('data', result)

            data = result['data']

            self.assertIsNotNone(data)
            self.assertTrue(len(data) > 0)
            self.assertIn('id', data[0])

            id = data[0]['id']
            self.assertIsNotNone(id)

            old_price = data[0]['price']
            self.assertIsNotNone(old_price)
            new_price = float(old_price) * 0.999

            result_move = lib.orders_move(market, id, str(new_price))

            logging.debug(result_move)

            self.assertIn('status', result_move)
            self.assertTrue(result_move['status'] == 'error')
            self.assertIn('message', result_move)
            self.assertIn('time', result_move)

            await asyncio.sleep(1)
Пример #21
0
        async def run_test():

            market = 'okex'
            pair = 'ETH_BTC'
            price = '0.015'
            amount = '1'
            side = 'buy'
            ord_type = 'limit'

            lib = BitsgapClient(public_key, private_key)

            result = lib.demo_orders_add(market, pair, amount, price, side,
                                         ord_type)

            logging.debug(result)

            self.assertIn('status', result)
            self.assertTrue(result['status'] == 'ok')
            self.assertIn('time', result)
            self.assertIn('data', result)

            data = result['data']
            self.assertIsNotNone(data)
            # check fields
            self.assertIn('id', data)
            self.assertIn('price', data)
            self.assertIn('amount', data)
            self.assertIn('state', data)
            self.assertIn('pair', data)
            self.assertIn('type', data)
            self.assertIn('side', data)
            self.assertIn('uts', data)
            self.assertIn('state', data)
            if 'state' in data:
                self.assertIn(data['state'], 'opened')

            await asyncio.sleep(1)
Пример #22
0
        async def run_test():

            market = 'okex'

            lib = BitsgapClient(public_key, private_key)

            # get executed orders
            result = lib.orders_history(market)

            logging.debug(result)

            self.assertIsNotNone(result)

            self.assertTrue(result['status'] == 'ok')
            self.assertIn('data', result)

            data = result['data']

            self.assertIsNotNone(data)
            self.assertTrue(len(data) > 0)
            self.assertIn('id', data[0])

            id = data[0]['id']

            self.assertIsNotNone(id)

            result_cancel = lib.orders_cancel(market, id)

            logging.debug(result_cancel)

            self.assertIn('status', result_cancel)
            self.assertTrue(result_cancel['status'] == 'error')
            self.assertIn('message', result_cancel)
            self.assertIn('time', result_cancel)

            await asyncio.sleep(1)