/** * Handle an order replace. * * @param recvts the timestamp when the message was received * @param msgcnt the number of messages received before this message * @param msgoffset the number of bytes received before this message * @param msg the message describing the cancel/replace */ void handle_message( time_point recvts, long msgcnt, std::size_t msgoffset, order_replace_message const& msg) { JB_LOG(trace) << " " << msgcnt << ":" << msgoffset << " " << msg; // First we need to find the original order ... auto position = orders_.find(msg.original_order_reference_number); if (position == orders_.end()) { // ... ooops, this should not happen, there is a problem with the // feed, log the problem and skip the message ... JB_LOG(warning) << "unknown order in handle_message(order_replace_message)" << ", id=" << msg.original_order_reference_number << ", location=" << msgcnt << ":" << msgoffset << ", msg=" << msg; return; } // ... then we need to make sure the new order is not a duplicate // ... auto newpos = orders_.find(msg.new_order_reference_number); if (newpos != orders_.end()) { JB_LOG(warning) << "duplicate order in " << "handle_message(order_replace_message)" << ", id=" << msg.new_order_reference_number << ", location=" << msgcnt << ":" << msgoffset << ", msg=" << msg; return; } auto& book = books_[position->second.stock]; // ... update the order list and book, but do not make a callback ... auto update = do_reduce( position, book, recvts, msgcnt, msgoffset, msg.header, msg.original_order_reference_number, 0); // ... now we need to insert the new order ... orders_.emplace( msg.new_order_reference_number, order_data{update.stock, update.buy_sell_indicator, msg.price, msg.shares}); (void)book.handle_add_order( update.buy_sell_indicator, msg.price, msg.shares); // ... adjust the update data structure ... update.cxlreplx = true; update.oldpx = update.px; update.oldqty = -update.qty; update.px = msg.price; update.qty = msg.shares; // ... and invoke the callback ... callback_(msg.header, book, update); }
/** * Refactor code to handle order reductions, i.e., cancels and * executions * * @param recvts the timestamp when the message was received * @param msgcnt the number of messages received before this message * @param msgoffset the number of bytes received before this message * @param header the header of the message that triggered this event * @param order_reference_number the id of the order being reduced * @param shares the number of shares to reduce, if 0 reduce all shares */ void handle_order_reduction( time_point recvts, long msgcnt, std::size_t msgoffset, message_header const& header, std::uint64_t order_reference_number, std::uint32_t shares) { // First we need to find the order ... auto position = orders_.find(order_reference_number); if (position == orders_.end()) { // ... ooops, this should not happen, there is a problem with the // feed, log the problem and skip the message ... JB_LOG(warning) << "unknown order in handle_order_reduction" << ", id=" << order_reference_number << ", location=" << msgcnt << ":" << msgoffset << ", header=" << header << ", order_reference_number=" << order_reference_number << ", shares=" << shares; return; } auto& book = books_[position->second.stock]; auto u = do_reduce( position, book, recvts, msgcnt, msgoffset, header, order_reference_number, shares); callback_(header, book, u); }
bool Generator::reduce() { tmp_cnt = 0; label_cnt = 0; labels.clear(); for_beg.clear(); memset(is_busy, 0, sizeof (is_busy)); top = -1; stat[++top] = 1; pair<string, int> nxt; int cur; string add; int id; string for_begin_label; pair<string, vector<string> > prod; vector<Word>::iterator it = src.begin(); while (it != src.end()) { add = it->type; cur = stat[top]; nxt = lr1.next_action(cur, add); if (nxt.second == -1) { cout << "Error in reduce" << endl; break; } // cout << add << " : "; if (nxt.first == "r") { id = nxt.second; prod = lr1.get_p_by_id(id); stk[top] = do_reduce(prod, id + 1); cur = stat[top]; stat[++top] = lr1.next_action(cur, prod.first).second; } else if (nxt.first == "AC") { cout << top << endl; section_text << "pushl\t$0\n"; section_text << "call _exit\n"; section_text.flush(); return true; } else { stk[top] = *it; stat[++top] = nxt.second; ++it; } // for (int i = 0; i < top; ++i) cout << " " <<stat[i] <<" " << stk[i].type << " "; // cout << stat[top]; // cout << endl; if (top >= 4 && stk[top - 4].x == "for" && stk[top - 1].x == ";") { //cerr <<stk[top-4].x <<" "<<stk[top-3].x <<" "<<stk[top-2].x <<" "<<stk[top-1].x <<endl; cerr << "has for" << endl; for_begin_label = get_new_label(); section_text << for_begin_label << ":\n"; for_beg.push_back(for_begin_label); section_text.flush(); } if (top >= 1 && stk[top - 1].x == "if") { end_flag = get_new_label(); } if (top >= 1 && stk[top - 1].x == "else") { section_text << "jmp\t" << end_flag << "\n"; else_flag = get_new_label(); section_text << else_flag << ":\n"; } } section_data.close(); section_text.close(); return false; }