apca/api/v2/
positions.rs

1// Copyright (C) 2019-2024 The apca Developers
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4use crate::api::v2::position::Position;
5use crate::Str;
6
7
8Endpoint! {
9  /// The representation of a GET request to the /v2/positions endpoint.
10  pub List(()),
11  Ok => Vec<Position>, [
12    /// The list of positions was retrieved successfully.
13    /* 200 */ OK,
14  ],
15  Err => ListError, []
16
17  #[inline]
18  fn path(_input: &Self::Input) -> Str {
19    "/v2/positions".into()
20  }
21}
22
23
24// TODO: There is the possibility to issue a DELETE against the
25//       /v2/positions endpoint in order to liquidate all open
26//       positions, which may be interesting to use. However, that
27//       requires support for multi-status HTTP responses.
28
29
30#[cfg(test)]
31mod tests {
32  use super::*;
33
34  use test_log::test;
35
36  use crate::api_info::ApiInfo;
37  use crate::Client;
38
39
40  #[test(tokio::test)]
41  async fn list_positions() {
42    // We can't do much here except check that the request is not
43    // reporting any errors.
44    let api_info = ApiInfo::from_env().unwrap();
45    let client = Client::new(api_info);
46    let _ = client.issue::<List>(&()).await.unwrap();
47  }
48}