ZR::RetVal MyOrders::match( Order * myOrder ) { if( myOrder->m_locked ) return ZR::ZR_FINISH; OrderList asks; m_asks->filterOrders( asks, myOrder->m_currency ); ZR::ZR_Number amount = myOrder->m_amount; for( OrderIterator askIt = asks.begin(); askIt != asks.end(); askIt++ ) { Order * other = *askIt; if( other->m_ignored ) continue; // trying to execute this order did not go well in the past. Don't try again. if( other->m_isMyOrder ) continue; // don't fill own orders if( myOrder->m_matched.find( other->m_order_id ) != myOrder->m_matched.end() ) continue; // matched that already if( myOrder->m_price < other->m_price ) break; // no need to try and find matches beyond std::cerr << "Zero Reserve: Match at ask price " << other->m_price.toStdString() << std::endl; myOrder->m_matched.insert( other->m_order_id ); if( amount > other->m_amount ) { buy( other, myOrder, other->m_amount ); } else { buy( other, myOrder, amount ); return ZR::ZR_FINISH; } amount -= other->m_amount; } return ZR::ZR_SUCCESS; }
ZR::RetVal MyOrders::init() { try { OrderList myorders; ZrDB::Instance()->loadOrders( &myorders ); for( OrderIterator it = myorders.begin(); it != myorders.end(); it++) { Order * order = *it; addOrder( order ); if( order->m_orderType == Order::ASK ) { m_asks->addOrder( order ); } else { m_bids->addOrder( order ); } } } catch( std::runtime_error & e ) { g_ZeroReservePlugin->placeMsg( std::string( "Exception caught: " ) + e.what() ); return ZR::ZR_FAILURE; } return ZR::ZR_SUCCESS; }