示例#1
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_cancel_all_my_orders():
    async with Daybit() as daybit:
        quote = 'USDT'
        base = 'BTC'

        tick_price = Decimal((await daybit.markets())['{}-{}'.format(quote, base)]['tick_price'])
        tick_amount = Decimal((await daybit.coins())[base]['tick_amount'])
        price_1 = ((await current_price(daybit, quote, base)) * Decimal(1.2)).quantize(tick_price)
        amount_1 = (Decimal(10.5) / price_1).quantize(tick_amount)

        price_2 = ((await current_price(daybit, quote, base)) * Decimal(1.4)).quantize(tick_price)
        amount_2 = (Decimal(10.5) / price_2).quantize(tick_amount)

        await daybit.create_order(
            sell=True,
            role='both',
            quote=quote,
            base=base,
            price=price_1 * 2,
            amount=amount_1,
            cond_type='none',
        )

        await daybit.create_order(
            sell=True,
            role='both',
            quote=quote,
            base=base,
            price=price_2,
            amount=amount_2,
            cond_type='none',
        )

        response = await daybit.cancel_all_my_orders()
        pprint(response)
示例#2
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_create_order_sell():
    async with Daybit() as daybit:
        quote = 'USDT'
        base = 'BTC'

        tick_price = Decimal((await daybit.markets())['{}-{}'.format(quote, base)]['tick_price'])
        tick_amount = Decimal((await daybit.coins())[base]['tick_amount'])

        # amount * price should be greater than 10 USDT.
        price = ((await current_price(daybit, quote, base)) * Decimal(1.2)).quantize(tick_price)
        amount = (Decimal(10.5) / price).quantize(tick_amount)

        response = await daybit.create_order(
            sell=True,
            role='both',
            quote=quote,
            base=base,
            price=price,
            amount=amount,
            cond_type='none',
        )
        pprint(response)

        with suppress(OrderAlreadyClosed):
            await daybit.cancel_order(response['id'])
示例#3
0
 async def test_subscription_catch_exception(self, daybit_params,
                                             event_loop):
     async with Daybit(daybit_params['url'],
                       params=daybit_params['params'],
                       loop=event_loop) as daybit:
         with pytest.raises(CommunicationError):
             await (daybit.market_summaries / -1)()
示例#4
0
 async def test_api_request_not_existed_coin_symbol(self, daybit_params,
                                                    event_loop):
     async with Daybit(daybit_params['url'],
                       params=daybit_params['params'],
                       loop=event_loop) as daybit:
         with pytest.raises(CommunicationError):
             await (daybit.coin_prices / 'unexisted')()
示例#5
0
async def daybit_order_books():
    async with Daybit() as daybit:
        quote = 'BTC'
        base = 'ETH'
        price_intvl = Decimal(
            (await daybit.markets())['{}-{}'.format(quote,
                                                    base)]['tick_price'])
        orderbook = await (daybit.order_books / quote / base / price_intvl)()
        bid = []
        ask = []

        price_intvl = Decimal(price_intvl)
        for key in sorted(orderbook.keys()):
            range = orderbook[key]
            buy_vol = Decimal(range['buy_vol'])
            sell_vol = Decimal(range['sell_vol'])
            min_price = Decimal(range['min_price']).quantize(price_intvl)
            max_price = Decimal(range['max_price']).quantize(price_intvl)

            if buy_vol > 0:
                bid.append([min_price, buy_vol])
            if sell_vol > 0:
                ask.append([max_price, sell_vol])
        bid = list(reversed(bid))
        spread = str(ask[0][0] - bid[0][0])
        ret = {'bids': bid, 'asks': ask, 'spread': spread}
        pprint(ret)
        return ret
示例#6
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_price_histories():
    async with Daybit() as daybit:
        quote = 'USDT'
        base = 'BTC'
        intvl = sorted((await daybit.price_history_intvls()).keys())[0]
        pprint(
            await (daybit.price_histories / quote / base / intvl)(from_time=int(time.time() * 1000 - intvl * 10 * 1000),
                                                                  to_time=int(time.time() * 1000)))
示例#7
0
 async def test_api_key_denied(self, daybit_params, event_loop):
     with pytest.raises(ConnectionError):
         async with Daybit(daybit_params['url'],
                           params={
                               'api_key': 'THIS-IS-INVALID-KEY',
                               'api_secret': 'THIS-IS-INVALID-SECRET-KEY'
                           },
                           loop=event_loop) as daybit:
             async with daybit.channel('/api'):
                 asyncio.sleep(0.1, loop=event_loop)
示例#8
0
    async def test_rate_limit(self, daybit_params, event_loop):
        async with Daybit(daybit_params['url'],
                          params=daybit_params['params'],
                          loop=event_loop) as daybit:
            market_summary_intvls = list(
                (await daybit.market_summary_intvls()).values())
            if len(market_summary_intvls) >= 2:
                intv1 = market_summary_intvls[0]['seconds']
                intv2 = market_summary_intvls[1]['seconds']
                rate_limit = daybit.rate_limit.get_limit('market_summaries')

                for _ in range(rate_limit):
                    await (daybit.market_summaries / intv1)()
                    await (daybit.market_summaries / intv2)()
                    await asyncio.sleep(1 / rate_limit + 0.05)
示例#9
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_markets():
    async with Daybit() as daybit:
        pprint(await daybit.markets())
示例#10
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_market_summary_intvls():
    async with Daybit() as daybit:
        pprint(await daybit.market_summary_intvls())
示例#11
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_cancel_orders():
    async with Daybit() as daybit:
        my_orders = await daybit.my_orders()
        open_orders = ([my_orders[key]['id'] for key in my_orders if my_orders[key]['status'] == 'placed'])
        pprint(open_orders)
        pprint(await daybit.cancel_orders(open_orders))
示例#12
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_price_history_intvls():
    async with Daybit() as daybit:
        pprint(await daybit.price_history_intvls())
示例#13
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_my_divs():
    async with Daybit() as daybit:
        pprint(await daybit.my_divs())
示例#14
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_quote_coins():
    async with Daybit() as daybit:
        pprint(await daybit.quote_coins())
示例#15
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_coin_prices():
    async with Daybit() as daybit:
        pprint(await daybit.coin_prices())
示例#16
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_create_wdrl():
    async with Daybit() as daybit:
        pprint(await daybit.create_wdrl(coin='BTC', to_addr='fake_address', amount='1'))
示例#17
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_trade_vols():
    async with Daybit() as daybit:
        pprint(await daybit.trade_vols(size=10))
示例#18
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_my_orders():
    async with Daybit() as daybit:
        pprint(await daybit.my_orders(closed=True))
示例#19
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_my_tx_summaries():
    async with Daybit() as daybit:
        pprint(await daybit.my_tx_summaries(type='deposit'))
        pprint(await daybit.my_tx_summaries(type='wdrl'))
示例#20
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_trades():
    async with Daybit() as daybit:
        quote = 'USDT'
        base = 'BTC'
        pprint(await (daybit.trades / quote / base)(size=10))
示例#21
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_market_summaries():
    async with Daybit() as daybit:
        intvls = sorted((await daybit.market_summary_intvls()).keys())
        pprint(await (daybit.market_summaries / intvls[0])())
示例#22
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_get_server_time():
    async with Daybit() as daybit:
        pprint(await daybit.get_server_time())
示例#23
0
 async def test_without_context_manager(self, daybit_params, event_loop):
     daybit = Daybit(daybit_params['url'],
                     params=daybit_params['params'],
                     loop=event_loop)
     await daybit.connect()
     await daybit.disconnect()
示例#24
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_day_avgs():
    async with Daybit() as daybit:
        pprint(await daybit.day_avgs())
示例#25
0
 async def test_api_join(self, daybit_params, event_loop):
     async with Daybit(daybit_params['url'],
                       params=daybit_params['params'],
                       loop=event_loop) as daybit:
         async with daybit.channel('/api'):
             asyncio.sleep(0.1, loop=event_loop)
示例#26
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_div_plans():
    async with Daybit() as daybit:
        pprint(await daybit.div_plans())
示例#27
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_coin_prices_with_sym(sym='ETH'):
    async with Daybit() as daybit:
        pprint(await (daybit.coin_prices / sym)())
示例#28
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_my_trade_vols():
    async with Daybit() as daybit:
        pprint(await daybit.my_trade_vols())
示例#29
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_my_my_airdrop_histories():
    async with Daybit() as daybit:
        pprint(await daybit.my_airdrop_histories())
示例#30
0
文件: apis.py 项目: gyunt/pydaybit
async def daybit_order_books():
    async with Daybit() as daybit:
        quote = 'USDT'
        base = 'BTC'
        price_intvl = Decimal((await daybit.markets())['{}-{}'.format(quote, base)]['tick_price']) * 10
        pprint(await (daybit.order_books / quote / base / price_intvl)())