async def test_auto_cancel_orders(self):
     response = await self.client.auto_cancel_orders(symbol=Pair(
         'BTC', 'USDT'),
                                                     countdown_time_ms=0)
     self.assertTrue(self.check_positive_response(response))
Beispiel #2
0
 async def test_cancel_batch_spot_order(self):
     response = await self.client.cancel_batch_spot_order(pair = Pair('BTC', 'USDT'))
     self.assertTrue(self.check_response(response, 30000))
Beispiel #3
0
 async def test_get_fees(self):
     response = await self.client.get_fees(pair = Pair('BTC', 'USD'))
     self.assertTrue(self.check_positive_response(response))
Beispiel #4
0
 async def test_cancel_multi_order(self):
     response = await self.client.cancel_multi_order(pair=Pair(
         'ETH', 'BTC'),
                                                     order_ids=["10", "20"])
     self.assertTrue(self.check_positive_response(response))
Beispiel #5
0
 async def test_get_orders(self):
     response = await self.client.get_orders(pair=Pair('ETH', 'BTC'),
                                             order_ids=["1", "2"])
     self.assertTrue(self.check_positive_response(response))
Beispiel #6
0
 async def test_get_ticker(self):
     response = await self.client.get_ticker(pair=Pair('ETH', 'BTC'))
     self.assertTrue(self.check_positive_response(response))
Beispiel #7
0
 async def test_get_candlesticks(self):
     response = await self.client.get_candlesticks(
         pair=Pair('ETH', 'BTC'),
         interval=enums.CandelstickInterval.I_1W,
         size="5")
     self.assertTrue(self.check_positive_response(response))
 async def test_get_api_trading_status(self):
     response = await self.client.get_api_trading_status(
         pair=Pair('BTC', 'USDT'))
     self.assertTrue(self.check_positive_response(response))
 async def test_get_commission_rate(self):
     response = await self.client.get_commission_rate(
         symbol=Pair('BTC', 'USDT'))
     self.assertTrue(self.check_positive_response(response))
 async def test_get_notional_and_leverage_brackets(self):
     response = await self.client.get_notional_and_leverage_brackets(
         pair=Pair('BTC', 'USDT'))
     self.assertTrue(self.check_positive_response(response))
 async def test_get_adl_quantile(self):
     response = await self.client.get_adl_quantile(
         symbol=Pair('BTC', 'USDT'))
     self.assertTrue(self.check_positive_response(response))
 async def test_get_income_history(self):
     response = await self.client.get_income_history(
         symbol=Pair('BTC', 'USDT'))
     self.assertTrue(self.check_positive_response(response))
 async def test_change_init_leverage(self):
     response = await self.client.change_init_leverage(symbol=Pair(
         'BTC', 'USDT'),
                                                       leverage=1)
     self.assertTrue(self.check_positive_response(response))
 async def test_get_all_open_orders(self):
     response = await self.client.get_all_open_orders(
         pair=Pair('BTC', 'USDT'))
     self.assertTrue(self.check_positive_response(response))
Beispiel #15
0
async def run():
    api_key = os.environ['APIKEY']
    sec_key = os.environ['SECKEY']

    client = CryptoXLib.create_binance_client(api_key, sec_key)

    print("Ping:")
    await client.ping()

    print("Server time:")
    await client.get_time()

    print("Exchange info:")
    await client.get_exchange_info()

    print("Order book:")
    await client.get_orderbook(pair=Pair('ETH', 'BTC'),
                               limit=enums.DepthLimit.L_5)

    print("Trades:")
    await client.get_trades(pair=Pair('ETH', 'BTC'), limit=5)

    print("Historical trades:")
    await client.get_historical_trades(pair=Pair('ETH', 'BTC'), limit=5)

    print("Aggregate trades:")
    await client.get_aggregate_trades(pair=Pair('ETH', 'BTC'), limit=5)

    print("Candlesticks:")
    await client.get_candlesticks(pair=Pair('ETH', 'BTC'),
                                  interval=enums.Interval.I_1D,
                                  limit=5)

    print("Average price:")
    await client.get_average_price(pair=Pair('ETH', 'BTC'))

    print("24hour price ticker:")
    await client.get_24h_price_ticker(pair=Pair('ETH', 'BTC'))

    print("Price ticker:")
    await client.get_price_ticker(pair=Pair('ETH', 'BTC'))

    print("Best order book ticker:")
    await client.get_orderbook_ticker(pair=Pair('ETH', 'BTC'))

    print("Create test market order:")
    await client.create_test_order(
        Pair("ETH", "BTC"),
        side=enums.OrderSide.BUY,
        type=enums.OrderType.MARKET,
        quantity="1",
        new_order_response_type=enums.OrderResponseType.FULL)

    print("Create limit order:")
    try:
        await client.create_order(
            Pair("ETH", "BTC"),
            side=enums.OrderSide.BUY,
            type=enums.OrderType.LIMIT,
            quantity="1",
            price="0",
            time_in_force=enums.TimeInForce.GOOD_TILL_CANCELLED,
            new_order_response_type=enums.OrderResponseType.FULL)
    except BinanceException as e:
        print(e)

    print("Cancel order:")
    try:
        await client.cancel_order(pair=Pair('ETH', 'BTC'), order_id="1")
    except BinanceException as e:
        print(e)

    print("Get order:")
    try:
        await client.get_order(pair=Pair('ETH', 'BTC'), order_id=1)
    except BinanceException as e:
        print(e)

    print("Get open orders:")
    await client.get_open_orders(pair=Pair('ETH', 'BTC'))

    print("Get all orders:")
    await client.get_all_orders(pair=Pair('ETH', 'BTC'))

    print("Create OCO order:")
    try:
        await client.create_oco_order(
            Pair("ETH", "BTC"),
            side=enums.OrderSide.BUY,
            quantity="1",
            price="0",
            stop_price="0",
            new_order_response_type=enums.OrderResponseType.FULL)
    except BinanceException as e:
        print(e)

    print("Cancel OCO order:")
    try:
        await client.cancel_oco_order(pair=Pair('ETH', 'BTC'),
                                      order_list_id="1")
    except BinanceException as e:
        print(e)

    print("Get OCO order:")
    try:
        await client.get_oco_order(order_list_id=1)
    except BinanceException as e:
        print(e)

    print("Get open OCO orders:")
    await client.get_open_oco_orders()

    print("Get all OCO orders:")
    await client.get_all_oco_orders()

    print("Account:")
    await client.get_account(recv_window_ms=5000)

    print("Account trades:")
    await client.get_account_trades(pair=Pair('ETH', 'BTC'))

    await client.close()
 async def test_get_order_book(self):
     response = await self.client.get_orderbook(symbol=Pair('BTC', 'USDT'))
     self.assertTrue(self.check_positive_response(response))
Beispiel #17
0
 async def test_find_order(self):
     response = await self.client.find_order(pair=Pair('ETH', 'BTC'),
                                             state=enums.OrderState.PENDING)
     self.assertTrue(self.check_positive_response(response))
 async def test_get_aggregate_trades(self):
     response = await self.client.get_aggregate_trades(
         symbol=Pair('BTC', 'USDT'))
     self.assertTrue(self.check_positive_response(response))
Beispiel #19
0
 async def test_get_trades(self):
     response = await self.client.get_trades(pair=Pair('ETH', 'BTC'),
                                             size="1")
     self.assertTrue(self.check_positive_response(response))
 async def test_get_cont_contract_candlesticks(self):
     response = await self.client.get_cont_contract_candlesticks(
         pair=Pair('BTC', 'USDT'),
         interval=enums.Interval.I_1MIN,
         contract_type=enums.ContractType.PERPETUAL)
     self.assertTrue(self.check_positive_response(response))
Beispiel #21
0
 async def test_create_multi_order(self):
     response = await self.client.create_multi_order(
         Pair("ETH", "BTC"),
         orders=[("1", "1", enums.OrderSide.SELL),
                 ("2", "1", enums.OrderSide.SELL)])
     self.assertTrue(self.check_positive_response(response))
 async def test_get_mark_price_candlesticks(self):
     response = await self.client.get_mark_price_candlesticks(
         symbol=Pair('BTC', 'USDT'), interval=enums.Interval.I_1MIN)
     self.assertTrue(self.check_positive_response(response))
Beispiel #23
0
    async def test_get_order(self):
        with self.assertRaises(BitforexRestException) as cm:
            await self.client.get_order(pair=Pair('ETH', 'BTC'), order_id="1")
        e = cm.exception

        self.assertEqual(e.body['code'], '4004')
 async def test_get_fund_rate_history(self):
     response = await self.client.get_fund_rate_history(
         pair=Pair('BTC', 'USDT'))
     self.assertTrue(self.check_positive_response(response))
Beispiel #25
0
 async def test_create_spot_order(self):
     response = await self.client.create_spot_order(pair = Pair('BTC', 'USDT'), type = enums.OrderType.LIMIT,
                                                    side = enums.OrderSide.BUY, amount = "10000", price = "1")
     self.assertTrue(self.check_response(response))
Beispiel #26
0
 async def test_get_exchange_info3(self):
     response = await self.client.get_exchange_info(pairs = [Pair('BTC', 'USDT'), Pair('BNB', 'USDT')])
     self.assertTrue(self.check_positive_response(response))
Beispiel #27
0
 async def test_get_order_book(self):
     response = await self.client.get_order_book(pair = Pair('BTC', 'USD'), depth = 3)
     self.assertTrue(self.check_positive_response(response))
async def run():
    # to retrieve your API/SEC key go to your bitforex account, create the keys and store them in
    # BITFOREXAPIKEY/BITFOREXSECKEY environment variables
    api_key = os.environ['BITFOREXAPIKEY']
    sec_key = os.environ['BITFOREXSECKEY']

    bitforex = CryptoXLib.create_bitforex_client(api_key, sec_key)

    print("Exchange info:")
    await bitforex.get_exchange_info()

    print("Order book:")
    await bitforex.get_order_book(pair=Pair('ETH', 'BTC'), depth="1")

    print("Ticker:")
    await bitforex.get_ticker(pair=Pair('ETH', 'BTC'))

    print("Single fund:")
    await bitforex.get_single_fund(currency="NOBS")

    print("Funds:")
    await bitforex.get_funds()

    print("Trades:")
    await bitforex.get_trades(pair=Pair('ETH', 'BTC'), size="1")

    print("Candlesticks:")
    await bitforex.get_candlesticks(pair=Pair('ETH', 'BTC'),
                                    interval=enums.CandlestickInterval.I_1W,
                                    size="5")

    print("Create order:")
    try:
        await bitforex.create_order(Pair("ETH", "BTC"),
                                    side=enums.OrderSide.SELL,
                                    quantity="1",
                                    price="1")
    except BitforexException as e:
        print(e)

    print("Create multiple orders:")
    await bitforex.create_multi_order(Pair("ETH", "BTC"),
                                      orders=[("1", "1", enums.OrderSide.SELL),
                                              ("2", "1", enums.OrderSide.SELL)
                                              ])

    print("Cancel order:")
    await bitforex.cancel_order(pair=Pair('ETH', 'BTC'), order_id="10")

    print("Cancel multiple orders:")
    await bitforex.cancel_multi_order(pair=Pair('ETH', 'BTC'),
                                      order_ids=["10", "20"])

    print("Cancel all orders:")
    await bitforex.cancel_all_orders(pair=Pair('ETH', 'BTC'))

    print("Get order:")
    try:
        await bitforex.get_order(pair=Pair('ETH', 'BTC'), order_id="1")
    except BitforexException as e:
        print(e)

    print("Get orders:")
    await bitforex.get_orders(pair=Pair('ETH', 'BTC'), order_ids=["1", "2"])

    print("Find orders:")
    await bitforex.find_order(pair=Pair('ETH', 'BTC'),
                              state=enums.OrderState.PENDING)

    await bitforex.close()
Beispiel #29
0
 async def test_cancel_order(self):
     response = await self.client.cancel_order(pair = Pair('BTC', 'USD'))
     self.assertTrue(self.check_positive_response(response))
    async def test_get_order(self):
        with self.assertRaises(BinanceRestException) as cm:
            await self.client.get_order(symbol=Pair('BTC', 'USDT'), order_id=1)
        e = cm.exception

        self.assertTrue(self.check_error_code(e, '400', '-2013'))