Esempio n. 1
0
 def test_cancel_order_order_id_no_prefix(self):
     order = create_order('helper', 100, 0.1, 'BTC_USD', 'bid', session=tp.session, submit=False)
     assert isinstance(order.id, int)
     assert isinstance(order.price, Amount)
     assert order.price == Amount("100 USD")
     assert order.state == 'pending'
     tp.session.close()
     submit_order('helper', order.id)
     oorder = get_orders(oid=order.id, session=tp.session)
     countdown = 30
     while oorder[0].state == 'pending' and countdown > 0:
         countdown -= 1
         oorder = get_orders(oid=order.id, session=tp.session)
         if oorder[0].state == 'pending':
             time.sleep(0.01)
             tp.session.close()
     assert len(oorder) == 1
     assert oorder[0].state == 'open'
     assert 'helper|' in oorder[0].order_id
     tp.session.close()
     cancel_orders('helper', order_id=oorder[0].order_id.split("|")[1])
     corder = get_orders(oid=oorder[0].id, session=tp.session)
     while (len(corder) == 0 or corder[0].state != 'closed') and countdown > 0:
         countdown -= 1
         corder = get_orders(oid=oorder[0].id, session=tp.session)
         if corder[0].state != 'closed':
             time.sleep(0.01)
             tp.session.close()
     assert len(corder) == 1
     assert corder[0].state == 'closed'
Esempio n. 2
0
    def test_cancel_order_order_id(self):
        bitfinex.sync_orders()
        order = create_order('bitfinex', 100, 0.01, 'BTC_USD', 'bid', session=bitfinex.session, expire=time.time()+60)
        assert isinstance(order.id, int)
        assert isinstance(order.price, Amount)
        assert order.price == Amount("100 USD")
        assert order.state == 'pending'
        oorder = get_orders(oid=order.id, session=bitfinex.session)
        countdown = 1000
        while oorder[0].state == 'pending' and countdown > 0:
            countdown -= 1
            oorder = get_orders(oid=order.id, session=bitfinex.session)
            if oorder[0].state == 'pending':
                time.sleep(0.01)
                bitfinex.session.close()

        assert len(oorder) == 1
        assert oorder[0].state == 'open'
        print oorder[0].order_id
        bitfinex.session.close()
        cancel_orders('bitfinex', order_id=oorder[0].order_id)
        corder = get_order_by_order_id(oorder[0].order_id, 'bitfinex', bitfinex.session)
        countdown = 1000
        while (corder is None or corder.state != 'closed') and countdown > 0:
            countdown -= 1
            corder = get_order_by_order_id(oorder[0].order_id, 'bitfinex', bitfinex.session)
            if (corder is None or corder.state != 'closed'):
                time.sleep(0.01)
                bitfinex.session.close()

        assert corder.state == 'closed'
Esempio n. 3
0
 def test_order_lifecycle(self):
     order = create_order('kraken', 100, 0.01, 'BTC_USD', 'bid', session=kraken.session, expire=time.time()+60)
     assert isinstance(order.id, int)
     assert isinstance(order.price, Amount)
     assert order.price == Amount("100 USD")
     assert order.state == 'pending'
     oorder = get_orders(oid=order.id, session=kraken.session)
     countdown = 1000
     while oorder[0].state == 'pending' and countdown > 0:
         countdown -= 1
         oorder = get_orders(oid=order.id, session=kraken.session)
         if oorder[0].state == 'pending':
             time.sleep(0.01)
             kraken.session.close()
     assert len(oorder) == 1
     assert oorder[0].state == 'open'
     kraken.session.close()
     cancel_orders('kraken', oid=order.id)
     countdown = 1000
     corder = get_orders('kraken', order_id=oorder[0].order_id, session=kraken.session)
     while corder[0].state != 'closed' and countdown > 0:
         countdown -= 1
         corder = get_orders('kraken', order_id=oorder[0].order_id, session=kraken.session)
         if corder[0].state != 'closed':
             time.sleep(0.01)
             kraken.session.close()
     assert len(corder) == 1
     assert corder[0].state == 'closed'
Esempio n. 4
0
 def test_order_lifecycle(self):
     order = create_order('helper', 100, 0.1, 'BTC_USD', 'bid', session=tp.session, submit=False)
     assert isinstance(order.id, int)
     assert isinstance(order.price, Amount)
     assert order.price == Amount("100 USD")
     assert order.state == 'pending'
     porder = get_orders(oid=order.id, session=tp.session)
     assert len(porder) == 1
     assert porder[0].state == 'pending'
     tp.session.close()
     submit_order('helper', order.id)
     oorder = get_orders(oid=order.id, session=tp.session)
     countdown = 300
     while (len(oorder) == 0 or oorder[0].state != 'open') and countdown > 0:
         countdown -= 1
         oorder = get_orders(oid=order.id, session=tp.session)
         if oorder[0].state != 'open':
             time.sleep(0.01)
             tp.session.close()
     assert len(oorder) == 1
     assert oorder[0].state == 'open'
     tp.session.close()
     cancel_orders('helper', oid=order.id)
     countdown = 30
     corder = get_orders('helper', order_id=oorder[0].order_id, session=tp.session)
     while corder[0].state != 'closed' and countdown > 0:
         countdown -= 1
         corder = get_orders('helper', order_id=oorder[0].order_id, session=tp.session)
         if corder[0].state != 'closed':
             time.sleep(0.01)
             tp.session.close()
     assert len(corder) == 1
     assert corder[0].state == 'closed'
Esempio n. 5
0
    def test_cancel_order_order_id_no_prefix(self):
        kraken.sync_orders()
        order = create_order('kraken', 100, 0.1, 'BTC_USD', 'bid', session=kraken.session, expire=time.time()+60)
        assert isinstance(order.id, int)
        assert isinstance(order.price, Amount)
        assert order.price == Amount("100 USD")
        assert order.state == 'pending'
        oorder = get_orders(oid=order.id, session=kraken.session)
        countdown = 1000
        while oorder[0].state == 'pending' and countdown > 0:
            countdown -= 1
            oorder = get_orders(oid=order.id, session=kraken.session)
            if oorder[0].state == 'pending':
                time.sleep(0.01)
                kraken.session.close()

        assert len(oorder) == 1
        assert oorder[0].state == 'open'
        print oorder[0].order_id.split("|")[1]
        cancel_orders('kraken', order_id=oorder[0].order_id.split("|")[1])
        #corder = get_orders(oid=order.id, session=kraken.session)
        corder = get_order_by_order_id(oorder[0].order_id, 'kraken', kraken.session)
        countdown = 1000
        while (corder is None or corder.state != 'closed') and countdown > 0:
            countdown -= 1
            #corder = get_orders(oid=order.id, session=kraken.session)
            corder = get_order_by_order_id(oorder[0].order_id, 'kraken', kraken.session)
            if (corder is None or corder.state != 'closed'):
                time.sleep(0.01)
                kraken.session.close()

        assert corder.state == 'closed'
Esempio n. 6
0
def handle_get_order(argv, parsers, session=ses):
    oparser = argparse.ArgumentParser(parents=parsers)
    oparser.add_argument("--oid", help='The order id.')
    oparser.add_argument("--order_id", help='The order order_id.')
    oparser.add_argument("-m", help='The order market.')
    oparser.add_argument("-e", help='The order exchange.')
    args = oparser.parse_args(argv)
    return get_orders(exchange=args.e, market=args.m, oid=args.oid, order_id=args.order_id, session=session)
 def sync_orders(self):
     oorders = self.get_open_orders()
     dboorders = get_orders(exchange='bitfinex',
                            state='open',
                            session=self.session)
     for dbo in dboorders:
         if dbo not in oorders:
             dbo.state = 'closed'
     self.session.commit()
Esempio n. 8
0
    def test_order_lifecycle(self):
        order = str(handle_command(['order', 'create', 'bid', '100', '0.1', 'BTC_USD', 'helper'], session=tp.session))
        order_id = order[order.find("order_id") + 10: order.find("state") - 3]
        exporder = "<LimitOrder(price=0.10000000 USD, amount=100.00000000 BTC, exec_amount=0.00000000 BTC, " \
                   "market='BTC_USD', side='bid', exchange='helper', order_id='{0}', state='pending', " \
                   "create_time=".format(order_id)
        assert exporder in order
        gotorder = str(handle_command(['order', 'get', '-e', 'helper', '--order_id', order_id], session=tp.session))
        assert exporder in order
        assert exporder in gotorder

        order_id = order_id.replace('tmp', 'helper')
        exporder = exporder.replace("pending", "open").replace('tmp', 'helper')
        tp.session.close()
        oorder = get_orders('helper', order_id=order_id, session=tp.session)
        countdown = 30
        while (len(oorder) == 0 or oorder[0].state != 'open') and countdown > 0:
            countdown -= 1
            oorder = get_orders('helper', order_id=order_id, session=tp.session)
            if len(oorder) == 0 or oorder[0].state != 'open':
                time.sleep(0.01)
                tp.session.close()
        assert len(oorder) == 1
        assert oorder[0].state == 'open'
        clioorder = str(
            handle_command(['order', 'get', '-e', 'helper', '--order_id', order_id.split("|")[1]], session=tp.session))
        assert exporder in clioorder.strip('[]')
        handle_command(['order', 'cancel', 'helper', '--order_id', order_id.replace('tmp', 'helper').split("|")[1]],
                       session=tp.session)
        exporder = exporder.replace("open", "closed")
        countdown = 30
        tp.session.close()
        corder = get_orders('helper', order_id=oorder[0].order_id, session=tp.session)
        while corder[0].state != 'closed' and countdown > 0:
            countdown -= 1
            corder = get_orders('helper', order_id=oorder[0].order_id, session=tp.session)
            if corder[0].state != 'closed':
                time.sleep(0.01)
                tp.session.close()
        assert len(corder) == 1
        assert corder[0].state == 'closed'
        clicorder = str(
            handle_command(['order', 'get', '-e', 'helper', '--order_id', order_id.split("|")[1]], session=tp.session))
        assert exporder in clicorder.strip('[]')
Esempio n. 9
0
 def test_cancel_orders_by_side(self):
     create_order('helper', 100, 0.1, 'BTC_USD', 'bid', session=tp.session, submit=False)
     create_order('helper', 100, 0.1, 'BTC_USD', 'bid', session=tp.session, submit=False)
     obids = len(get_orders(side='bid', exchange='helper', state='pending', session=tp.session))
     assert obids >= 2
     create_order('helper', 100, 0.1, 'BTC_USD', 'ask', session=tp.session, submit=False)
     create_order('helper', 100, 0.1, 'BTC_USD', 'ask', session=tp.session, submit=False)
     oasks = len(get_orders(side='ask', exchange='helper', state='pending', session=tp.session))
     assert oasks >= 2
     tp.session.close()
     cancel_orders('helper', side='bid')
     bids = len(get_orders(side='bid', exchange='helper', state='pending', session=tp.session))
     countdown = 30
     while bids != 0 and countdown > 0:
         countdown -= 1
         bids = len(get_orders(side='bid', exchange='helper', state='pending', session=tp.session))
         if bids != 0:
             time.sleep(0.01)
             tp.session.close()
     assert bids == 0
     tp.session.close()
     asks = len(get_orders(side='ask', exchange='helper', state='pending', session=tp.session))
     countdown = 30
     while asks != 0 and countdown > 0:
         countdown -= 1
         asks = len(get_orders(side='ask', exchange='helper', state='pending', session=tp.session))
         if asks != 0:
             time.sleep(0.01)
             tp.session.close()
     assert asks > 0
     assert oasks == asks
Esempio n. 10
0
    def test_cancel_order_order_id_no_prefix(self):
        bitfinex.sync_orders()
        order = create_order('bitfinex',
                             100,
                             0.1,
                             'BTC_USD',
                             'bid',
                             session=bitfinex.session,
                             expire=time.time() + 60)
        assert isinstance(order.id, int)
        assert isinstance(order.price, Amount)
        assert order.price == Amount("100 USD")
        assert order.state == 'pending'
        oorder = get_orders(oid=order.id, session=bitfinex.session)
        countdown = 1000
        while oorder[0].state == 'pending' and countdown > 0:
            countdown -= 1
            oorder = get_orders(oid=order.id, session=bitfinex.session)
            if oorder[0].state == 'pending':
                time.sleep(0.01)
                bitfinex.session.close()

        assert len(oorder) == 1
        assert oorder[0].state == 'open'
        print oorder[0].order_id.split("|")[1]
        cancel_orders('bitfinex', order_id=oorder[0].order_id.split("|")[1])
        #corder = get_orders(oid=order.id, session=bitfinex.session)
        corder = get_order_by_order_id(oorder[0].order_id, 'bitfinex',
                                       bitfinex.session)
        countdown = 1000
        while (corder is None or corder.state != 'closed') and countdown > 0:
            countdown -= 1
            #corder = get_orders(oid=order.id, session=bitfinex.session)
            corder = get_order_by_order_id(oorder[0].order_id, 'bitfinex',
                                           bitfinex.session)
            if (corder is None or corder.state != 'closed'):
                time.sleep(0.01)
                bitfinex.session.close()

        assert corder.state == 'closed'
Esempio n. 11
0
 def test_cancel_orders_by_market(self):
     bitfinex.sync_orders()
     assert create_order('bitfinex', 100, 0.1, 'BTC_USD', 'bid', session=bitfinex.session, expire=time.time()+60) is not None
     last = create_order('bitfinex', 100, 0.1, 'BTC_USD', 'bid', session=bitfinex.session, expire=time.time() + 60)
     got = get_order_by_order_id(last.order_id, 'bitfinex', session=bitfinex.session)
     countdown = 1000
     while (got is None or got.state != 'open') and countdown > 0:
         countdown -= 1
         got = get_order_by_order_id(last.order_id, 'bitfinex', session=bitfinex.session)
         time.sleep(0.01)
         bitfinex.session.close()
     obids = len(get_orders(side='bid', state='open', session=bitfinex.session))
     assert obids >= 2
     assert create_order('bitfinex', 1000, 0.1, 'BTC_USD', 'ask', session=bitfinex.session, expire=time.time()+60) is not None
     assert create_order('bitfinex', 1000, 0.1, 'BTC_USD', 'ask', session=bitfinex.session, expire=time.time()+60) is not None
     last = create_order('bitfinex', 1000, 0.1, 'ETH_BTC', 'ask', session=bitfinex.session, expire=time.time()+60)
     got = get_order_by_order_id(last.order_id, 'bitfinex', session=bitfinex.session)
     countdown = 1000
     while (got is None or got.state != 'open') and countdown > 0:
         countdown -= 1
         got = get_order_by_order_id(last.order_id, 'bitfinex', session=bitfinex.session)
         time.sleep(0.01)
         bitfinex.session.close()
     oasks = len(get_orders(side='ask', state='open', session=bitfinex.session))
     assert oasks >= 3
     bitfinex.session.close()
     cancel_orders('bitfinex', market='BTC_USD')
     bids = len(get_orders(market='BTC_USD', state='open', exchange='bitfinex', session=bitfinex.session))  # include pending orders? race?
     countdown = 3000
     while bids != 0 and countdown > 0:
         countdown -= 1
         rawbids = get_orders(market='BTC_USD', state='open', exchange='bitfinex', session=bitfinex.session)
         bids = len(rawbids)
         if bids != 0:
             time.sleep(0.01)
             bitfinex.session.close()
     assert bids == 0
     cancel_orders('bitfinex', market='ETH_BTC', side='ask')
Esempio n. 12
0
 def test_order_lifecycle(self):
     order = create_order('bitfinex',
                          100,
                          0.01,
                          'BTC_USD',
                          'bid',
                          session=bitfinex.session,
                          expire=time.time() + 60)
     assert isinstance(order.id, int)
     assert isinstance(order.price, Amount)
     assert order.price == Amount("100 USD")
     assert order.state == 'pending'
     oorder = get_orders(oid=order.id, session=bitfinex.session)
     countdown = 1000
     while oorder[0].state == 'pending' and countdown > 0:
         countdown -= 1
         oorder = get_orders(oid=order.id, session=bitfinex.session)
         if oorder[0].state == 'pending':
             time.sleep(0.01)
             bitfinex.session.close()
     assert len(oorder) == 1
     assert oorder[0].state == 'open'
     bitfinex.session.close()
     cancel_orders('bitfinex', oid=order.id)
     countdown = 1000
     corder = get_orders('bitfinex',
                         order_id=oorder[0].order_id,
                         session=bitfinex.session)
     while corder[0].state != 'closed' and countdown > 0:
         countdown -= 1
         corder = get_orders('bitfinex',
                             order_id=oorder[0].order_id,
                             session=bitfinex.session)
         if corder[0].state != 'closed':
             time.sleep(0.01)
             bitfinex.session.close()
     assert len(corder) == 1
     assert corder[0].state == 'closed'
Esempio n. 13
0
 def test_cancel_orders_by_market(self):
     create_order('helper', 100, 0.1, 'BTC_USD', 'bid', session=tp.session, submit=False)
     create_order('helper', 100, 0.1, 'BTC_USD', 'bid', session=tp.session, submit=False)
     obids = len(get_orders(side='bid', exchange='helper', state='pending', session=tp.session))
     assert obids >= 2
     create_order('helper', 100, 0.1, 'BTC_USD', 'ask', session=tp.session, submit=False)
     create_order('helper', 100, 0.1, 'BTC_USD', 'ask', session=tp.session, submit=False)
     create_order('helper', 100, 0.1, 'DASH_BTC', 'ask', session=tp.session, submit=False)
     oasks = len(get_orders(side='ask', exchange='helper', state='pending', session=tp.session))
     assert oasks >= 3
     tp.session.close()
     cancel_orders('helper', market='BTC_USD')
     orders = len(get_orders(market='BTC_USD', exchange='helper', state='pending', session=tp.session))
     countdown = 30
     while orders != 0 and countdown > 0:
         countdown -= 1
         orders = len(get_orders(market='BTC_USD', exchange='helper', state='pending', session=tp.session))
         if orders != 0:
             time.sleep(0.01)
             tp.session.close()
     assert orders == 0
     dorders = len(get_orders(market='DASH_BTC', exchange='helper', state='pending', session=tp.session))
     assert dorders >= 1
Esempio n. 14
0
    def test_cancel_orders_by_side(self):
        kraken.sync_orders()
        assert create_order('kraken', 100, 0.1, 'BTC_USD', 'bid', session=kraken.session, expire=time.time()+60) is not None
        last = create_order('kraken', 100, 0.1, 'BTC_USD', 'bid', session=kraken.session, expire=time.time()+60)
        got = get_order_by_order_id(last.order_id, 'kraken', session=kraken.session)
        countdown = 1000
        while (got is None or got.state != 'open') and countdown > 0:
            countdown -= 1
            got = get_order_by_order_id(last.order_id, 'kraken', session=kraken.session)
            time.sleep(0.01)
            kraken.session.close()
        obids = len(get_orders(side='bid', state='open', session=kraken.session))
        assert obids >= 2
        assert create_order('kraken', 1000, 0.01, 'BTC_USD', 'ask', session=kraken.session, expire=time.time()+60) is not None
        last = create_order('kraken', 1000, 0.01, 'BTC_USD', 'ask', session=kraken.session, expire=time.time()+60)
        got = get_order_by_order_id(last.order_id, 'kraken', session=kraken.session)
        countdown = 1000
        while (got is None or got.state != 'open') and countdown > 0:
            countdown -= 1
            got = get_order_by_order_id(last.order_id, 'kraken', session=kraken.session)
            time.sleep(0.01)
            kraken.session.close()
        oasks = len(get_orders(side='ask', state='open', session=kraken.session))
        assert oasks >= 2
        kraken.session.close()
        cancel_orders('kraken', side='bid')
        bids = len(get_orders(side='bid', state='open', session=kraken.session))  # include pending orders? race?
        countdown = 30000
        while bids != 0 and countdown > 0:
            countdown -= 1
            bids = len(get_orders(side='bid', state='open', session=kraken.session))
            if bids != 0:
                time.sleep(0.01)
                kraken.session.close()

        assert bids == 0
        kraken.session.close()
        asks = len(get_orders(side='ask', state='open', session=kraken.session))
        countdown = 300
        while asks != 0 and countdown > 0:
            countdown -= 1
            asks = len(get_orders(side='ask', state='open', session=kraken.session))
            if asks != 0:
                time.sleep(0.01)
                kraken.session.close()

        assert asks > 0
        assert oasks == asks
Esempio n. 15
0
    def test_cancel_orders_by_side(self):
        bitfinex.sync_orders()
        assert create_order('bitfinex',
                            100,
                            0.1,
                            'BTC_USD',
                            'bid',
                            session=bitfinex.session,
                            expire=time.time() + 60) is not None
        last = create_order('bitfinex',
                            100,
                            0.1,
                            'BTC_USD',
                            'bid',
                            session=bitfinex.session,
                            expire=time.time() + 60)
        got = get_order_by_order_id(last.order_id,
                                    'bitfinex',
                                    session=bitfinex.session)
        countdown = 1000
        while (got is None or got.state != 'open') and countdown > 0:
            countdown -= 1
            got = get_order_by_order_id(last.order_id,
                                        'bitfinex',
                                        session=bitfinex.session)
            time.sleep(0.01)
            bitfinex.session.close()
        obids = len(
            get_orders(side='bid', state='open', session=bitfinex.session))
        assert obids >= 2
        assert create_order('bitfinex',
                            1000,
                            0.01,
                            'BTC_USD',
                            'ask',
                            session=bitfinex.session,
                            expire=time.time() + 60) is not None
        last = create_order('bitfinex',
                            1000,
                            0.01,
                            'BTC_USD',
                            'ask',
                            session=bitfinex.session,
                            expire=time.time() + 60)
        got = get_order_by_order_id(last.order_id,
                                    'bitfinex',
                                    session=bitfinex.session)
        countdown = 1000
        while (got is None or got.state != 'open') and countdown > 0:
            countdown -= 1
            got = get_order_by_order_id(last.order_id,
                                        'bitfinex',
                                        session=bitfinex.session)
            time.sleep(0.01)
            bitfinex.session.close()
        oasks = len(
            get_orders(side='ask',
                       state='open',
                       exchange='bitfinex',
                       session=bitfinex.session))
        assert oasks >= 2
        bitfinex.session.close()
        cancel_orders('bitfinex', side='bid')
        bids = len(
            get_orders(
                side='bid',
                state='open',
                exchange='bitfinex',
                session=bitfinex.session))  # include pending orders? race?
        countdown = 3000
        while bids != 0 and countdown > 0:
            countdown -= 1
            bids = len(
                get_orders(side='bid',
                           state='open',
                           exchange='bitfinex',
                           session=bitfinex.session))
            if bids != 0:
                time.sleep(0.01)
                bitfinex.session.close()

        assert bids == 0
        bitfinex.session.close()
        asks = len(
            get_orders(side='ask',
                       state='open',
                       exchange='bitfinex',
                       session=bitfinex.session))
        countdown = 3000
        while asks != 0 and countdown > 0:
            countdown -= 1
            asks = len(
                get_orders(side='ask',
                           state='open',
                           exchange='bitfinex',
                           session=bitfinex.session))
            if asks != 0:
                time.sleep(0.01)
                bitfinex.session.close()

        assert asks > 0
        assert oasks == asks