Skip to content

Commit

Permalink
Return order_type in buy/sell responses #725.
Browse files Browse the repository at this point in the history
  • Loading branch information
artemii235 committed Sep 22, 2020
1 parent 2d0c07e commit 7ee2184
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
16 changes: 13 additions & 3 deletions mm2src/lp_ordermatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl Default for MatchBy {
fn default() -> Self { MatchBy::Any }
}

#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(tag = "type", content = "data")]
enum OrderType {
FillOrKill,
Expand Down Expand Up @@ -1271,6 +1271,13 @@ struct TakerMatch {
last_updated: u64,
}

#[derive(Serialize)]
struct LpautobuyResult<'a> {
#[serde(flatten)]
request: &'a TakerRequest,
order_type: OrderType,
}

pub fn lp_auto_buy(
ctx: &MmArc,
base_coin: &MmCoinEnum,
Expand Down Expand Up @@ -1308,7 +1315,10 @@ pub fn lp_auto_buy(
.with_sender_pubkey(H256Json::from(our_public_id.bytes));
let request = try_s!(request_builder.build());
ctx.broadcast_p2p_msg(P2PMessage::from_serialize_with_default_addr(&request));
let result = json!({ "result": request }).to_string();
let result = json!({ "result": LpautobuyResult {
request: &request,
order_type: input.order_type,
} });
let order = TakerOrder {
created_at: now_ms(),
matches: HashMap::new(),
Expand All @@ -1318,7 +1328,7 @@ pub fn lp_auto_buy(
save_my_taker_order(ctx, &order);
my_taker_orders.insert(order.request.uuid, order);
drop(my_taker_orders);
Ok(result)
Ok(result.to_string())
}

fn price_ping_sig_hash(timestamp: u32, pubsecp: &[u8], pubkey: &[u8], base: &[u8], rel: &[u8], price64: u64) -> H256 {
Expand Down
6 changes: 5 additions & 1 deletion mm2src/mm2_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2338,7 +2338,11 @@ fn test_fill_or_kill_taker_order_should_not_transform_to_maker() {
"type": "FillOrKill"
}
}))));
assert!(rc.0.is_success(), "!setprice: {}", rc.1);
assert!(rc.0.is_success(), "!sell: {}", rc.1);
let sell_json: Json = json::from_str(&rc.1).unwrap();
let order_type = sell_json["result"]["order_type"]["type"].as_str();
assert_eq!(order_type, Some("FillOrKill"));

log!("Wait for 40 seconds for Bob order to be cancelled");
thread::sleep(Duration::from_secs(40));

Expand Down

0 comments on commit 7ee2184

Please sign in to comment.