Skip to main content

barter_instrument_copy/
lib.rs

1use derive_more::Constructor;
2use serde::{Deserialize, Serialize};
3
4/// Defines a global [`ExchangeId`] enum covering all exchanges.
5pub mod exchange;
6
7/// [`Asset`](asset::Asset) related data structures.
8///
9/// eg/ `AssetKind`, `AssetNameInternal`, etc.
10pub mod asset;
11
12/// [`Instrument`](market_data::MarketDataInstrument) related data structures.
13///
14/// eg/ `InstrumentKind`, `OptionContract``, etc.
15pub mod instrument;
16
17pub mod market;
18
19#[derive(
20    Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize, Constructor,
21)]
22pub struct Keyed<Key, Value> {
23    pub key: Key,
24    pub value: Value,
25}
26
27impl<Key, Value> AsRef<Value> for Keyed<Key, Value> {
28    fn as_ref(&self) -> &Value {
29        &self.value
30    }
31}
32
33#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize)]
34pub struct Underlying<AssetKey> {
35    pub base: AssetKey,
36    pub quote: AssetKey,
37}
38
39impl<AssetKey> Underlying<AssetKey> {
40    pub fn new<A>(base: A, quote: A) -> Self
41    where
42        A: Into<AssetKey>,
43    {
44        Self {
45            base: base.into(),
46            quote: quote.into(),
47        }
48    }
49}