Skip to content

Commit

Permalink
Extend Order type with average fill price
Browse files Browse the repository at this point in the history
For cases when an order is filled, the Alpaca API provides fields that
help in determining the profit/loss associated the underlying position.
One such field is the average fill price.
This change adds this property to the Order type to make it accessible.
  • Loading branch information
d-e-s-o committed Mar 14, 2020
1 parent e99dad1 commit 97eb804
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Unreleased
----------
- Added `average_fill_price` to `Order` type
- Fixed issue when deserializing non-trade activity object without a
quantity

Expand Down
6 changes: 5 additions & 1 deletion src/api/v2/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ pub struct Order {
/// The stop price.
#[serde(rename = "stop_price")]
pub stop_price: Option<Num>,
/// The average price at which the order was filled.
#[serde(rename = "filled_avg_price")]
pub average_fill_price: Option<Num>,
/// If true, the order is eligible for execution outside regular
/// trading hours.
#[serde(rename = "extended_hours")]
Expand Down Expand Up @@ -555,7 +558,7 @@ mod tests {
"time_in_force": "day",
"limit_price": "107.00",
"stop_price": "106.00",
"filled_avg_price": "106.00",
"filled_avg_price": "106.25",
"status": "accepted",
"extended_hours": false
}"#;
Expand All @@ -573,6 +576,7 @@ mod tests {
assert_eq!(order.time_in_force, TimeInForce::Day);
assert_eq!(order.limit_price, Some(Num::from_int(107)));
assert_eq!(order.stop_price, Some(Num::from_int(106)));
assert_eq!(order.average_fill_price, Some(Num::new(10625, 100)));
}

#[test(tokio::test)]
Expand Down

0 comments on commit 97eb804

Please sign in to comment.