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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use thiserror::Error;
/// Result type used by the TWS API client crate.
pub type TwsApiResult<T> = Result<T, TwsApiError>;
/// Errors produced while encoding, decoding, or transporting TWS API frames.
#[derive(Debug, Error)]
pub enum TwsApiError {
/// A caller attempted to encode a value containing non-printable ASCII.
#[error("TWS API fields must be printable ASCII: {0:?}")]
NonPrintableAscii(String),
/// A caller attempted to send a missing field value.
#[error("cannot encode a missing TWS API field")]
MissingField,
/// A frame length prefix exceeded the supported platform size.
#[error("TWS API frame length {0} is too large for this platform")]
FrameTooLarge(u32),
/// A message was incomplete.
#[error("incomplete TWS API frame: need {needed} bytes, have {available} bytes")]
IncompleteFrame {
/// Number of bytes needed to finish the frame.
needed: usize,
/// Number of bytes currently available.
available: usize,
},
/// The peer returned a malformed handshake response.
#[error("malformed TWS API handshake response")]
MalformedHandshake,
/// The peer advertised an unsupported server version.
#[error("TWS/Gateway server version {server_version} is below required minimum {min_version}")]
UnsupportedServerVersion {
/// Advertised server version.
server_version: i32,
/// Required minimum version.
min_version: i32,
},
/// A request used a field that the negotiated server version does not support.
#[error(
"TWS/Gateway server version {server_version} is below required minimum {min_version} for {parameter}"
)]
UnsupportedRequestParameter {
/// Advertised server version.
server_version: i32,
/// Required minimum version.
min_version: i32,
/// Unsupported parameter name.
parameter: &'static str,
},
/// A network operation failed.
#[error("TWS API I/O error: {0}")]
Io(#[from] std::io::Error),
/// An integer field could not be parsed.
#[error("invalid TWS API integer field {field:?}: {source}")]
InvalidInteger {
/// Field content.
field: String,
/// Parse failure.
source: std::num::ParseIntError,
},
/// A decimal field could not be parsed.
#[error("invalid TWS API decimal field {field:?}: {source}")]
InvalidDecimal {
/// Field content.
field: String,
/// Parse failure.
source: rust_decimal::Error,
},
/// A protobuf payload could not be decoded.
#[error("invalid TWS API protobuf payload: {0}")]
ProtobufDecode(#[from] prost::DecodeError),
}