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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//! Client library for the cTrader Open API and the cTrader FIX 4.4 API.
//!
//! # Overview
//!
//! The crate talks to a cTrader server over either of its two programming interfaces:
//!
//! - [`open_api`]: Protobuf messages over TLS. One connection serves an application and
//! every trading account its access token grants: symbols, prices, depth, bars, ticks,
//! orders, positions, history and account data.
//! - [`fix`]: FIX 4.4. One trading account has a quote session for prices and a trade
//! session for orders, each a connection of its own.
//!
//! The [`common`] module holds what both share: [configuration](common::config),
//! [errors](common::errors), [typed identifiers](common::ids),
//! [exact prices and volumes](common::decimals) and [timestamps](common::time). Prices,
//! volumes and money are decimals throughout the typed API, never floats; the generated
//! Protobuf messages of the Open API keep the types of the wire.
//!
//! Both clients are asynchronous and run on a tokio runtime the application provides.
//!
//! # Features
//!
//! No feature is on by default.
//!
//! | Feature | Enables |
//! |---|---|
//! | `open-api` | The [`open_api`] module. |
//! | `fix` | The [`fix`] module. |
//! | `logging` | Diagnostic events of the Open API connection, emitted through `tracing`. |
//!
//! # Quick start
//!
//! Both clients are built from a configuration, which is either read from the environment
//! or put together with a builder. The Open API targets the demo environment unless the
//! live one is asked for; a FIX configuration names its host. The variables are listed in
//! the documentation of each protocol module.
//!
//! ## Open API
//!
//! ```no_run
//! # #[cfg(feature = "open-api")]
//! # async fn run() -> Result<(), ctrader_connector::common::errors::ConnectorError> {
//! use ctrader_connector::common::config::ConfigurationOpenApi;
//! use ctrader_connector::open_api::client::OpenApiClient;
//!
//! let client = OpenApiClient::connect(ConfigurationOpenApi::from_env()?).await?;
//! client.authorise_application().await?;
//! let accounts = client.accounts().await?;
//! if let Some(account) = accounts.iter().find(|account| !account.is_live) {
//! client.authorise_account(account.id).await?;
//! let trader = client.trader(account.id).await?;
//! println!("balance: {} {}", trader.balance, trader.currency);
//! }
//! client.shutdown().await;
//! # Ok(())
//! # }
//! ```
//!
//! ## FIX
//!
//! ```no_run
//! # #[cfg(feature = "fix")]
//! # async fn run() -> Result<(), ctrader_connector::common::errors::ConnectorError> {
//! use ctrader_connector::common::config::ConfigurationFix;
//! use ctrader_connector::fix::client::FixClient;
//! use ctrader_connector::fix::session::SessionKind;
//!
//! let quote = FixClient::connect(ConfigurationFix::from_env()?, SessionKind::Quote).await?;
//! let securities = quote.securities().await?;
//! if let Some(security) = securities.first() {
//! let mut spots = quote.subscribe_spot(security.id).await?;
//! let prices = spots.next().await?;
//! println!("{}: {:?} / {:?}", security.name, prices.bid, prices.offer);
//! spots.unsubscribe().await?;
//! }
//! quote.logout().await?;
//! # Ok(())
//! # }
//! ```
//!
//! # Errors
//!
//! Every call of a client returns [`ConnectorError`](common::errors::ConnectorError), one
//! family for both protocols. A configuration or a value that is refused before anything is
//! sent returns a narrower error, such as
//! [`ConfigError`](common::errors::ConfigError) or
//! [`ValueError`](common::errors::ValueError), that converts into it. Each protocol module
//! explains which of its variants call for
//! which reaction; the one to know before trading is
//! [`OutcomeUnknown`](common::errors::ConnectorError::OutcomeUnknown): an order is written
//! to the wire at most once and is never sent again by this library.
//!
//! # Examples
//!
//! The `examples` directory of the repository holds one runnable program per group of
//! requests, `examples/open_api` and `examples/fix`, each behind the feature of its
//! protocol.
/// Version of this crate as recorded in its manifest.
pub const VERSION: &str = env!;