Bohr1005 / xcrypto

quant,trading system,crypto,async
MIT License
295 stars 87 forks source link

Stop Orders Error #17

Open KyoMorya opened 2 days ago

KyoMorya commented 2 days ago

long_order.send(price, self.dsize, Side.BUY, OrderType.STOP_MARKET, Tif.GTC) => Order { time: 1727708860003, symbol: "wifusdt", side: BUY, state: REJECTED, order_type: STOP_MARKET, tif: GTC, quantity: 5.0, price: 2.5, order_id: -1, internal_id: 4, trade_time: 0, trade_price: 0.0, trade_quantity: 0.0, acc: 0.0, making: Some( false, ), } in the server log [16:07:43.720197166 trade.rs 124 ERROR] Error { code: -1106, msg: "Parameter 'price' sent when not required." } stop_price should be used not price

KyoMorya commented 2 days ago

pub async fn add_order( &self, path: &str, symbol: String, price: String, quantity: String, side: String, order_type: String, tif: String, session_id: u16, id: u32, ) -> anyhow::Result { let client_order_id = u64::from(session_id) << 32 | u64::from(id); let mut params = vec![ ("symbol".into(), symbol), ("side".into(), side), ("type".into(), order_type.clone()), ("quantity".into(), quantity), ("newClientOrderId".into(), client_order_id.to_string()), ("newOrderRespType".into(), "RESULT".into()), ];

match order_type.as_str() {
    "STOP_MARKET" => {
        // For stop market orders, the price is treated as stopPrice
        params.push(("stopPrice".into(), price));
    }
    "MARKET" => {
        // Market orders don't need a price, so no action needed
    }
    _ => {
        // For other types (e.g., LIMIT), use price
        params.push(("price".into(), price));
    }
}

if tif != "UNDEF" {
    params.push(("timeInForce".into(), tif));
}

self.post(path, &params, true).await

} added this to rest.rs it solved the issue