Skip to content

Commit

Permalink
Added run limit order test
Browse files Browse the repository at this point in the history
  • Loading branch information
crnbarr93 committed Feb 21, 2024
1 parent febf5a6 commit 60f9b78
Show file tree
Hide file tree
Showing 3 changed files with 760 additions and 2 deletions.
3 changes: 3 additions & 0 deletions contracts/orderbook/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ pub enum ContractError {
amount_remaining: Uint128,
reason: Option<String>,
},

#[error("Mismatched order direction")]
MismatchedOrderDirection {},
}
9 changes: 7 additions & 2 deletions contracts/orderbook/src/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use crate::state::*;
use crate::state::{MAX_TICK, MIN_TICK, ORDERBOOKS};
use crate::types::{Fulfilment, LimitOrder, MarketOrder, OrderDirection, REPLY_ID_REFUND};
use cosmwasm_std::{
coin, ensure, ensure_eq, BankMsg, Decimal, DepsMut, Env, MessageInfo, Order, Response, Storage,
SubMsg, Uint128,
coin, ensure, ensure_eq, ensure_ne, BankMsg, Decimal, DepsMut, Env, MessageInfo, Order,
Response, Storage, SubMsg, Uint128,
};
use cw_storage_plus::Bound;
use cw_utils::{must_pay, nonpayable};
Expand Down Expand Up @@ -225,6 +225,11 @@ pub fn run_market_order(

for maybe_current_order in tick_orders {
let current_order = maybe_current_order?.1;
ensure_ne!(
current_order.order_direction,
order.order_direction,
ContractError::MismatchedOrderDirection {}
);
let fill_quantity = order.quantity.min(current_order.quantity);
// Add to total amount fulfiled from placed order
amount_fulfiled = amount_fulfiled.checked_add(fill_quantity)?;
Expand Down
Loading

0 comments on commit 60f9b78

Please sign in to comment.