예제 #1
0
def test_cases(ses):
    response = ses.get(base_url + '/case')
    if response.ok:
        case_obj1 = cases.case(ses)
        case_obj2 = cases.Case(response.json())
        if (case_obj1.__dict__ != case_obj2.__dict__):
            raise AssertionError("Case objects not equal")

        case_json1 = cases.case_json(ses)
        case_json2 = response.json()
        if (case_json1 != case_json2):
            raise AssertionError("Case JSONs not equal")

        enforce = cases.trade_lim_enforce_chk(ses)
    else:
        raise ApiException('Authorization Error: Please check API key.')

    response = ses.get(base_url + '/limits')
    if response.ok and enforce:
        limits_json = response.json()
        case_limit_obj1 = cases.case_limits(ses)
        case_limit_obj2 = cases.CaseLimits(limits_json[0])
        if (case_limit_obj1.__dict__ != case_limit_obj2.__dict__):
            raise AssertionError("Case Lim obj not equal")

        case_lim_json1 = cases.case_limits_json(ses)
        case_lim_json2 = limits_json
        if (case_lim_json1 != case_lim_json2):
            raise AssertionError("Case lim JSON not equal")
    else:
        raise ApiException('Authorization Error: Please check API key.')
예제 #2
0
def main():
    with requests.Session() as ses:
        ses.headers.update(API_KEY)

        current_case = cases.case(ses)
        current_case_json = cases.case_json(ses)
        current_case_lim = cases.case_limits(ses)
        tick = current_case.tick
        print(current_case_json)
예제 #3
0
def main():

    arbitrage_qty = 1000  # arbitrage qunatity for one orders by default 1000

    # checking for correct number of arguments entered
    if len(sys.argv) != 3:
        print('Usage arbitrage.py SEC_A SEC_B')
        sys.exit()
    # loading the two security names
    sec1_a = (sys.argv[1]).upper()
    sec1_b = (sys.argv[2]).upper()

    with requests.Session() as ses:
        ses.headers.update(API_KEY)
        current_case = cases.case(ses)
        current_case_lim = cases.case_limits(ses)
        tick = current_case.tick
        # the orders submission limits are a max of 10000 units per order
        max_arbitrage_qty = min(10000, current_case_lim.gross_limit)
        while tick > 5 and tick < 295 and not shutdown:
            # get best bid and ask for security in both exchanges
            sec1_a_bid = book.get_security_info(ses, sec1_a, 'bids', 'price')
            sec1_a_ask = book.get_security_info(ses, sec1_a, 'asks', 'price')
            sec1_b_bid = book.get_security_info(ses, sec1_b, 'bids', 'price')
            sec1_b_ask = book.get_security_info(ses, sec1_b, 'asks', 'price')

            # checking for crossed markets and arbitraging
            if sec1_a_bid > sec1_b_ask:  # if a_bid is higher than b_ask then buy at the lower b_ask and sell at the higher a_bid
                # checking for the minumum qty between the two crossed orders not to prevent non-zero positions
                sec1_b_qty = book.get_security_info(ses, sec1_b, 'bids',
                                                    'quantity')
                sec1_a_qty = book.get_security_info(ses, sec1_a, 'asks',
                                                    'quantity')
                arbitrage_qty = min(sec1_a_qty, sec1_b_qty) % max_arbitrage_qty
                orders.market_order(ses, sec1_b, 'BUY', arbitrage_qty)
                orders.market_order(ses, sec1_a, 'SELL', arbitrage_qty)
                sleep(1)
            if sec1_b_bid > sec1_a_ask:  # if b_bid is higher than a_ask then buy at the lower a_ask and sell at the higher b_bid
                # checking for the minumum qty between the two crossed orders not to prevent non-zero positions
                sec1_b_qty = book.get_security_info(ses, sec1_b, 'asks',
                                                    'quantity')
                sec1_a_qty = book.get_security_info(ses, sec1_a, 'bids',
                                                    'quantity')
                arbitrage_qty = min(sec1_a_qty, sec1_b_qty) % max_arbitrage_qty
                orders.market_order(ses, sec1_a, 'BUY', arbitrage_qty)
                orders.market_order(ses, sec1_b, 'SELL', arbitrage_qty)
                sleep(1)

            # updating ticks to make sure the session is active
            current_case = cases.case(ses)
            tick = current_case.tick