Skip to content

Commit

Permalink
Merge pull request #7 from Detoo/fix_wss_v2_executions_triggers_fields
Browse files Browse the repository at this point in the history
fix: ExecutionResult with triggers
  • Loading branch information
Brendan-Blanchard authored Sep 6, 2024
2 parents 4f95007 + df3885f commit 84c3a81
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/wss/v2/user_data_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ pub struct TriggerDescription {
pub reference: TriggerType,
pub price: Decimal,
pub price_type: PriceType,
pub actual_price: Decimal,
pub peak_price: Decimal,
pub last_price: Decimal,
pub actual_price: Option<Decimal>,
pub peak_price: Option<Decimal>,
pub last_price: Option<Decimal>,
pub status: TriggerStatus,
pub timestamp: String,
pub timestamp: Option<String>,
}

#[derive(Debug, Deserialize, PartialEq)]
Expand Down
75 changes: 72 additions & 3 deletions tests/wss_v2/user_data_tests.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::wss_v2::shared::ParseIncomingTest;
use kraken_async_rs::request_types::TimeInForce;
use kraken_async_rs::request_types::{TimeInForce, TriggerType};
use kraken_async_rs::response_types::{BuySell, OrderStatusV2, OrderType};
use kraken_async_rs::wss::v2::base_messages::{ChannelMessage, Response, WssMessage};
use kraken_async_rs::wss::v2::trading_messages::{FeePreference, PriceType};
use kraken_async_rs::wss::v2::user_data_messages::{
Balance, BalanceResponse, ExecutionResult, ExecutionType, Fee, LedgerCategory,
LedgerEntryTypeV2, LedgerUpdate, MakerTaker, WalletId, WalletType,
LedgerEntryTypeV2, LedgerUpdate, MakerTaker, TriggerDescription, TriggerStatus, WalletId,
WalletType,
};
use rust_decimal_macros::dec;

Expand Down Expand Up @@ -269,7 +270,7 @@ async fn test_execution_order_update_cancelled() {
}

#[tokio::test]
async fn test_execution_order_update_pending() {
async fn test_execution_limit_order_update_pending() {
let pending_new = r#"{"channel":"executions","type":"update","data":[{"order_id":"AHOJQ8-1E72C-8M2VQH","symbol":"ADX/USD",
"order_qty":81.36256082,"cum_cost":0.0000000,"time_in_force":"GTC","exec_type":"pending_new","side":"buy","order_type":"limit",
"order_userref":0,"limit_price_type":"static","limit_price":0.18328,"stop_price":0.00000,"order_status":"pending_new",
Expand Down Expand Up @@ -326,6 +327,74 @@ async fn test_execution_order_update_pending() {
.await;
}

#[tokio::test]
async fn test_execution_stop_loss_limit_order_update_pending() {
let pending_new = r#"{"channel":"executions","type":"update","data":[{"order_id":"AHOJQ8-1E72C-8M2VQH","symbol":"ADX/USD",
"order_qty":81.36256082,"cum_cost":0,"time_in_force":"GTC","exec_type":"pending_new","side":"buy","order_type":"stop-loss-limit",
"order_userref":0,"limit_price_type":"static","triggers":{"price":0.2,"price_type":"static","reference":"index","status":"untriggered"},
"stop_price":0.2,"limit_price":0.2,"trigger":"index","order_status":"pending_new","fee_usd_equiv":0,"fee_ccy_pref":"fciq",
"timestamp":"2024-05-18T12:01:56.165888Z"}],"sequence":120}"#.to_string();

let expected_update_pending = WssMessage::Channel(ChannelMessage::Execution(Response {
data: vec![ExecutionResult {
execution_type: ExecutionType::PendingNew,
cash_order_quantity: None,
contingent: None,
cost: None,
execution_id: None,
fees: None,
liquidity_indicator: None,
last_price: None,
last_quantity: None,
average_price: None,
reason: None,
cumulative_cost: Some(dec!(0.0)),
cumulative_quantity: None,
display_quantity: None,
effective_time: None,
expire_time: None,
fee_preference: Some(FeePreference::Quote),
fee_usd_equivalent: Some(dec!(0.0)),
limit_price: Some(dec!(0.2)),
limit_price_type: Some(PriceType::Static),
margin: None,
no_market_price_protection: None,
order_ref_id: None,
order_id: "AHOJQ8-1E72C-8M2VQH".to_string(),
order_quantity: Some(dec!(81.36256082)),
order_type: Some(OrderType::StopLossLimit),
order_status: OrderStatusV2::PendingNew,
order_user_ref: Some(0),
post_only: None,
position_status: None,
reduce_only: None,
side: Some(BuySell::Buy),
symbol: Some("ADX/USD".to_string()),
time_in_force: Some(TimeInForce::GTC),
timestamp: "2024-05-18T12:01:56.165888Z".to_string(),
trade_id: None,
triggers: Some(TriggerDescription {
reference: TriggerType::Index,
price: dec!(0.2),
price_type: PriceType::Static,
actual_price: None,
peak_price: None,
last_price: None,
status: TriggerStatus::Untriggered,
timestamp: None,
}),
client_order_id: None,
}],
sequence: 120,
}));

ParseIncomingTest::new()
.with_incoming(pending_new)
.expect_message(expected_update_pending)
.test()
.await;
}

#[tokio::test]
async fn test_execution_order_update_new() {
let new = r#"{"channel":"executions","type":"update","data":[{"timestamp":"2024-05-18T12:58:51.121515Z",
Expand Down

0 comments on commit 84c3a81

Please sign in to comment.