def test_securities_history(ses): response = ses.get(base_url + '/orders') ticker_sym = '' if response.ok: orders_dict1 = orders.orders_dict(ses) for ord_id in orders_dict1: ticker_sym = orders_dict1[ord_id].ticker break else: raise ApiException('Authorization Error: Please check API key.') payload = {'ticker': ticker_sym} response = ses.get(base_url + '/history', params=payload) if response.ok: sec_history_json = response.json() sec_history_json1 = sh.security_history_json(ses, ticker_sym) sec_history_json2 = sec_history if (sec_history_json1 != sec_history_json2): raise AssertionError("Sec hist json not eq") sec_history_dict1 = sh.security_history_dict(ses, ticker_sym) sec_history_dict2 = { sh.Security_History(sec_hist).tick: sh.Security_History(sec_hist) for sec_hist in sec_history_json } if (sec_history_dict1 != sec_history_dict2): raise AssertionError("Sec hist dict not eq") else: raise ApiException('Authorization Error: Please check API key.')
def test_securities_book(ses): response = ses.get(base_url + '/orders') ticker_sym = '' if response.ok: orders_dict1 = orders.orders_dict(ses) for ord_id in orders_dict1: ticker_sym = orders_dict1[ord_id].ticker break else: raise ApiException('Authorization Error: Please check API key.') payload = {'ticker': ticker_sym} response = ses.get(base_url + '/securities/book', params=payload) if response.ok: sec_book = response.json() _side = 'bids' _param = 'price' sec_info1 = sb.get_security_info(ses, ticker_sym, _side, _param) sec_info2 = sec_book[_side][0][_param] if (sec_info1 != sec_info2): raise AssertionError("Security info not equal") best_bid1 = sb.get_best_bid(ses, ticker_sym) best_bid2 = sec_book['bids'][0] if (best_bid1 != best_bid2): raise AssertionError("Best bids not equal") best_ask1 = sb.get_best_ask(ses, ticker_sym) best_ask2 = sec_book['asks'][0] if (best_ask1 != best_ask2): raise AssertionError("Best asks not equal") bbo1 = sb.get_bbo(ses, ticker_sym) bbo2 = {'best_bid': best_bid1, 'best_ask': best_ask1} if (bbo1 != bbo2): raise AssertionError("Best bid and offer not equal") all_bids1 = sb.get_all_bids(ses, ticker_sym) all_bids2 = sec_book['bids'] if (all_bids1 != all_bids2): raise AssertionError("All bids not equal") all_asks1 = sb.get_all_asks(ses, ticker_sym) all_asks2 = sec_book['asks'] if (all_asks1 != all_asks2): raise AssertionError("All asks not equal") all_ba1 = sb.get_all_bids_asks(ses, ticker_sym) all_ba2 = sec_book if (all_ba1 != all_ba2): raise AssertionError("All bids/asks not equal") else: raise ApiException('Authorization Error: Please check API key.')
def test_orders(ses): response = ses.get(base_url + '/orders') if response.ok: order_json = response.json() orders_json1 = orders.orders_json(ses) orders_json2 = order_json if (orders_json1 != orders_json2): raise AssertionError("Orders JSON not equal") orders_dict1 = orders.orders_dict(ses) orders_dict2 = {(orders.Order(ord)).order_id: orders.Order(ord) for ord in order_json} if (orders_dict1 != orders_dict2): raise AssertionError("Orders dict not equal") for ord_id in orders_dict1: orders_obj1 = orders.order(ses, ord_id) orders_obj2 = orders.Order(order_json) if (orders_obj1.__dict__ != orders_obj2.__dict__): raise AssertionError("Orders obj not equal") else: raise ApiException('Authorization Error: Please check API key.')
def test_submit_cancel_orders(ses): ticker = 'CRZY' side = 'BUY' quantity = 100 lim_price = 30 # MARKET ORDER CHECK mkt_order_params = { 'ticker': ticker, 'type': 'MARKET', 'quantity': quantity, 'action': side } response = ses.post(base_url + '/orders', params=mkt_order_params) if response.ok: mkt_order = response.json() orderId = mkt_order['order_id'] else: raise ApiException('Authorization Error: Please check API key.') with capture() as market_msg1: sco.market_order(ses, ticker, side, quantity) market_msg2 = ('%s %s Market order was submitted and has ID %d' % (side, quantity, orderId)) if (market_msg1 != market_msg2): raise AssertionError("Market order msg not equal") # LIMIT ORDER CHECK lim_order_params = { 'ticker': ticker, 'type': 'LIMIT', 'quantity': quantity, 'price': price, 'action': side } response = ses.post(base_url + '/orders', params=lim_order_params) if response.ok: lim_order = response.json() orderId = lim_order['order_id'] else: raise ApiException('Authorization Error: Please check API key.') with capture() as limit_msg1: sco.limit_order(ses, TICKER, side, qty, lim_price) limit_msg2 = ("%s %s Limit order was submitted and has ID %d" % (side, quantity, orderId)) if (limit_msg1 != limit_msg2): raise AssertionError("Limit order msg not equal") # Make sure there are unfufilled orders present in the book first # CANCEL ORDER TEST response = ses.get(base_url + '/orders') if response.ok: orders_dict = orders.orders_dict(ses) for ord_id in orders_dict: with capture() as cancel_msg1: sco.cancel_order(ses, ord_id) cancel_msg2 = ('Order ' + ord_id + ' was successfully cancelled.') if (cancel_msg1 != cancel_msg2): raise AssertionError("Cancel order msg not equal") else: raise ApiException('Authorization Error: Please check API key.')