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
//! Exchange-neutral trading types and traits for Weirdnet apps.
//!
//! - [`num`]: exact decimal [`Price`] and [`Qty`] (no floats), with increment rounding.
//! - [`instrument`]: venues, products, markets and instrument kinds (spot, dated futures,
//! perpetuals), with order checks against a product's increments and limits.
//! - [`order`]: sides, order types, time in force, client order ids, requests, and an
//! [`Order`] state machine that accounts fills.
//! - [`account`]: fills, balances, fee tiers, positions (with a [`PositionBook`]) and margin.
//! - [`market`]: trades, tickers, order book snapshots and deltas (an [`OrderBook`] that
//! applies them with gap checks), candles and a [`CandleBuilder`].
//! - [`exchange`]: the async adapter traits, [`MarketData`] (no credentials) and [`Trading`],
//! with [`Capabilities`] and paging; [`Exchange`] is both.
//! - [`cost`]: a [`CostModel`] for fees, spread and slippage from a live book.
//! - [`rate`]: a shared token-bucket [`RateLimiter`].
//! - [`credentials`]: secrets for adapters, typed by environment so a live adapter can only be
//! built from [`Live`] credentials.
//! - [`paper`]: [`Paper`], an in-memory simulated exchange for tests and dry runs.
//! - Feature `vault`: [`vault::VaultSecret`], credentials from `weirdnet-vault`.
//! - Feature `service`: [`feeds::MarketHubs`], market data as `weirdnet-service` hub topics.
//!
//! This crate has no exchange adapters and makes no network calls. Adapters implement the
//! traits in their own crates.
//!
//! Timestamps are milliseconds since the Unix epoch (UTC). Amounts are [`Decimal`].
//!
//! ```
//! use weirdnet_exchange::*;
//!
//! # tokio::runtime::Builder::new_current_thread().build().unwrap().block_on(async {
//! let paper = Paper::default();
//! let m = paper.market("BTC-USD");
//! paper.add_product(Product::spot(m.clone(), "BTC", "USD").with_increments(Decimal::new(1, 2), Decimal::new(1, 4)))?;
//! paper.deposit("USD", Decimal::from(1000));
//! paper.set_book(BookSnapshot {
//! market: m.clone(),
//! bids: vec![Level::new(Price::parse("99")?, Qty::parse("1")?)],
//! asks: vec![Level::new(Price::parse("101")?, Qty::parse("1")?)],
//! sequence: 1,
//! at_ms: 0,
//! })?;
//!
//! let x: &dyn Exchange = &paper;
//! let order = OrderRequest::market(ClientOrderId::generate("demo"), m, Side::Buy, OrderSize::Base(Qty::parse("0.5")?));
//! let ack = x.place_order(&order).await?;
//! assert_eq!(ack.status, OrderStatus::Filled);
//! # Ok::<_, ExchangeError>(())
//! # }).unwrap();
//! ```
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// Milliseconds since the Unix epoch, from the system clock.