Skip to content

Commit

Permalink
add order op like a channel
Browse files Browse the repository at this point in the history
  • Loading branch information
roytang121 committed Jan 28, 2024
1 parent 2138bd2 commit c33163c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/api/v5/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub struct ApiResponse<T> {
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WsResponse<'a, A: Debug, T: Debug> {
pub id: Option<&'a str>,
pub op: Option<&'a str>,
pub arg: Option<A>,
pub code: Option<u32>,
pub conn_id: Option<&'a str>,
Expand Down
8 changes: 8 additions & 0 deletions src/api/v5/orderbook_trading/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::serde_util::{deserialize_from_opt_str, deserialize_timestamp};
use chrono::{DateTime, Utc};
use reqwest::Method;
use serde::{Deserialize, Serialize};
use crate::websocket::WebsocketChannel;

/// https://www.okx.com/docs-v5/en/#rest-api-trade-cancel-order
#[derive(Debug, Clone, Serialize)]
Expand Down Expand Up @@ -352,4 +353,11 @@ pub mod websocket {
.to_string()
}
}
}

pub struct OrderOp;
impl WebsocketChannel for OrderOp {
const CHANNEL: &'static str = "";
type Response<'de> = PlaceOrderResponse;
type ArgType<'de> = ();
}
4 changes: 3 additions & 1 deletion src/api/v5/ws_convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
use const_format::concatcp;
use serde::Deserialize;
use crate::api::error::{ApiError, Error};
use crate::api::v5::{AccountChannel, BalanceAndPositionChannel, PositionsChannel};
use crate::api::v5::{AccountChannel, BalanceAndPositionChannel, OrderOp, PositionsChannel};
use crate::api::v5::orderbook_trading::orders::websocket::OrdersChannel;

fn deser_from_str<'a, T>(s: &'a str) -> serde_json::Result<T>
Expand Down Expand Up @@ -46,6 +46,8 @@ impl_channel_match!(AccountChannel);
impl_channel_match!(BalanceAndPositionChannel);
impl_channel_match!(OrdersChannel);

impl ChannelMatch for OrderOp { const CHANNEL_PATTERN: &'static str = r#""op":"order""#; }

#[cfg(test)]
mod test_channel_match {
use crate::api::v5::Instruments;
Expand Down

0 comments on commit c33163c

Please sign in to comment.