1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (C) 2019-2021 The apca Developers
// SPDX-License-Identifier: GPL-3.0-or-later

use crate::api::v2::position::Position;
use crate::Str;


Endpoint! {
  /// The representation of a GET request to the /v2/positions endpoint.
  pub Get(()),
  Ok => Vec<Position>, [
    /// The list of positions was retrieved successfully.
    /* 200 */ OK,
  ],
  Err => GetError, [ ]

  #[inline]
  fn path(_input: &Self::Input) -> Str {
    "/v2/positions".into()
  }
}


// TODO: There is the possibility to issue a DELETE against the
//       /v2/positions endpoint in order to liquidate all open
//       positions, which may be interesting to use. However, that
//       requires support for multi-status HTTP responses.


#[cfg(test)]
mod tests {
  use super::*;

  use test_log::test;

  use crate::api_info::ApiInfo;
  use crate::Client;


  #[test(tokio::test)]
  async fn list_positions() {
    // We can't do much here except check that the request is not
    // reporting any errors.
    let api_info = ApiInfo::from_env().unwrap();
    let client = Client::new(api_info);
    let _ = client.issue::<Get>(&()).await.unwrap();
  }
}