-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Problem
The OrderSide enum currently serializes to capitalized values ("Buy" and "Sell"), but the Deribit API expects lowercase values ("buy" and "sell").
This causes serialization/deserialization errors when communicating with the Deribit API.
Current Behavior
#[derive(DebugPretty, DisplaySimple, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum OrderSide {
/// Buy order
Buy,
/// Sell order
Sell,
}When serialized, this produces:
OrderSide::Buy→"Buy"OrderSide::Sell→"Sell"
Expected Behavior
The enum should serialize to lowercase to match Deribit’s API specification:
OrderSide::Buy→"buy"OrderSide::Sell→"sell"
Evidence
- The existing test
test_order_side_serialization()at line 275 explicitly expects capitalized values, which is incorrect for Deribit API compatibility. - Other enums in the same file (
TimeInForceandOrderType) already use#[serde(rename = "...")]attributes to match API expectations. - The
OrderInfostruct uses adirection: Stringfield that contains lowercase values like"buy"(see test at line 409), indicating the API uses lowercase.
Solution
Add serde rename attributes to match the pattern used by other enums in the file:
#[derive(DebugPretty, DisplaySimple, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum OrderSide {
#[serde(rename = "buy")]
Buy,
#[serde(rename = "sell")]
Sell,
}Additional Changes Needed
- Update the test
test_order_side_serialization()to expect lowercase values. - Consider adding an
as_str()method toOrderSidefor consistency withTimeInForceandOrderType:
impl OrderSide {
pub fn as_str(&self) -> &'static str {
match self {
OrderSide::Buy => "buy",
OrderSide::Sell => "sell",
}
}
}Impact
This is a breaking change that affects serialization/deserialization, but it’s necessary for proper Deribit API compatibility.
Users relying on the current capitalized serialization format will need to update their code.
Metadata
Metadata
Assignees
Labels
No labels