Skip to main content

bpx_api_types/
lib.rs

1//! Types module for the Backpack Exchange API.
2//!
3//! This module contains various types used across the Backpack Exchange API,
4//! including enums and structs for capital, markets, orders, trades, and user data.
5
6use serde::{Deserialize, Serialize};
7use strum::{Display, EnumIter, EnumString};
8
9pub mod account;
10pub mod borrow_lend;
11pub mod capital;
12pub mod fill;
13pub mod futures;
14pub mod history;
15pub mod margin;
16pub mod markets;
17pub mod order;
18pub mod rfq;
19pub mod trade;
20pub mod user;
21pub mod vault;
22
23#[derive(
24    Debug,
25    Display,
26    Clone,
27    Copy,
28    Serialize,
29    Deserialize,
30    Default,
31    EnumString,
32    PartialEq,
33    Eq,
34    Hash,
35    EnumIter,
36)]
37pub enum Blockchain {
38    #[default]
39    Solana,
40    Ethereum,
41    Polygon,
42    Bitcoin,
43    Internal,
44    EqualsMoney,
45    Cardano,
46    Hyperliquid,
47    Story,
48    Bsc,
49    Dogecoin,
50    Sui,
51    XRP,
52    Litecoin,
53    Berachain,
54    HyperEVM,
55    Plasma,
56    Arbitrum,
57    Base,
58    Optimism,
59    Aptos,
60    Sei,
61    Tron,
62    #[strum(serialize = "0G")]
63    #[serde(rename = "0G")]
64    ZeroG,
65    Eclipse,
66    Fogo,
67    Monad,
68    Stable,
69    Zcash,
70    #[serde(other)]
71    Unknown,
72}
73
74#[cfg(test)]
75pub(crate) mod test_support {
76    use std::fmt::Debug;
77
78    use serde::{Serialize, de::DeserializeOwned};
79
80    /// Asserts that `value` serializes to the JSON string `wire` and that `wire` parses back
81    /// to `value`.
82    pub(crate) fn assert_wire<T>(value: &T, wire: &str)
83    where
84        T: Serialize + DeserializeOwned + PartialEq + Debug,
85    {
86        let json = format!("\"{wire}\"");
87        assert_eq!(serde_json::to_string(value).unwrap(), json);
88        assert_eq!(serde_json::from_str::<T>(&json).unwrap(), *value);
89    }
90}