Skip to content

Question: quoting logic using modify #280

@Kayne88

Description

@Kayne88

Hi,

Using the quoting mechanism from your examples with 1) cancel -> 2) submit new works fine. Occasionally however I receive fills far exceeding my quote amount (usd) and even my hard inventory cap. This does not really make sense unless there is some race condition between submitted but not yet confirmed/cancellable orders. When markets move fast this would lead to multiple active quotes at one point (I am using wait_next_feed including order responses, so things can tick quickly).

I am trying to use order modify instead but can't get it to work. With the previous quoting mechanism I trade approx. 1000 trades, whereas with the modify only 4. Where's the flaw in my logic?

for asset_no in range(hbt.num_assets):
            depth = hbt.depth(asset_no)
            active_limit_orders = Dict.empty(key_type=order_key_type, value_type=order_value_type)
            orders = hbt.orders(asset_no)
            order_values = orders.values();
            while order_values.has_next():
                order = order_values.get()
                if order.order_type == LIMIT:
                    if order.status == NEW:
                        active_limit_orders[order.order_id] = (
                            int(round(order.price/depth.tick_size)), 
                            int(round(order.qty)), 
                            order.req
                        )
                        
            hbt.clear_inactive_orders(asset_no)
            
            hedge_qty = round(hedge_qtys[asset_no], qty_prec[asset_no])
            if hedge_qty > 0:
                order_id = np.random.randint(0, 10_000)
                resp = hbt.submit_buy_order(asset_no, np.uint64(order_id), roi_ub[asset_no], hedge_qty, GTC, MARKET, False)
            elif hedge_qty < 0:
                order_id = np.random.randint(0, 10_000)
                resp = hbt.submit_sell_order(asset_no, np.uint64(order_id), roi_lb[asset_no], np.abs(hedge_qty), GTC, MARKET, False)

            order_qty = round(order_qtys[asset_no], qty_prec[asset_no])
            bid_order_id = np.uint64(2*asset_no)
            ask_order_id = np.uint64(2*asset_no+1)
            if order_qty > 0:
                quote_price = depth.best_bid*(1+alpha_skew_bps*alphas[asset_no])
                quote_price = min(quote_price, depth.best_ask-depth.tick_size)
                quote_price = round(quote_price, price_prec[asset_no])
                quote_price_tick = round(quote_price/depth.tick_size)
                if bid_order_id in active_limit_orders:
                    order = active_limit_orders[bid_order_id]
                    if (order[0] != quote_price or order[1] != order_qty) and order[2] == NONE:
                        resp = hbt.modify(asset_no, bid_order_id, quote_price, order_qty, False)
                else:
                    resp = hbt.submit_buy_order(asset_no, bid_order_id, quote_price, order_qty, GTX, LIMIT, False)

                if ask_order_id in active_limit_orders:
                    order = active_limit_orders[ask_order_id]
                    if order[2] == NONE or order[2] == NEW:
                        resp = hbt.cancel(asset_no, ask_order_id, False)

            elif order_qty < 0:
                quote_price = depth.best_ask*(1+alpha_skew_bps*alphas[asset_no])
                quote_price = max(quote_price, depth.best_bid+depth.tick_size)
                quote_price = round(quote_price, price_prec[asset_no])
                quote_price_tick = round(quote_price/depth.tick_size)
                
                if ask_order_id in active_limit_orders:
                    order = active_limit_orders[ask_order_id]
                    if (order[0] != quote_price or order[1] != np.abs(order_qty)) and order[2] == NONE:
                        resp = hbt.modify(asset_no, ask_order_id, quote_price, np.abs(order_qty), False)
                else:
                    resp = hbt.submit_sell_order(asset_no, ask_order_id, quote_price, np.abs(order_qty), GTX, LIMIT, False)

                if bid_order_id in active_limit_orders:
                    order = active_limit_orders[bid_order_id]
                    if order[2] == NONE or order[2] == NEW:
                        resp = hbt.cancel(asset_no, bid_order_id, False)
            
            else:
                if bid_order_id in active_limit_orders:
                    order = active_limit_orders[bid_order_id]
                    if order[2] == NONE or order[2] == NEW:
                        resp = hbt.cancel(asset_no, bid_order_id, False)
                
                if ask_order_id in active_limit_orders:
                    order = active_limit_orders[ask_order_id]
                    if order[2] == NONE or order[2] == NEW:
                        resp = hbt.cancel(asset_no, ask_order_id, False)

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions