Struct Exchange

Source
pub struct Exchange {
    pub client: Client,
    pub chain: Chain,
}
Expand description

Endpoint to interact with and trade on the Hyperliquid chain.

Fields§

§client: Client§chain: Chain

Implementations§

Source§

impl Exchange

Source

pub async fn place_order( &self, wallet: Arc<LocalWallet>, orders: Vec<OrderRequest>, vault_address: Option<Address>, ) -> Result<Response>

Place an order

§Arguments
  • wallet - The wallet to sign the order with
  • orders - The orders to place
  • vault_address - If trading on behalf of a vault, its onchain address in 42-character hexadecimal format e.g. 0x0000000000000000000000000000000000000000
§Note
  • cloid in argument order is an optional 128 bit hex string, e.g. 0x1234567890abcdef1234567890abcdef
Examples found in repository?
examples/info/perps.rs (line 184)
168async fn order_status(info: &Info, exchange: &Exchange, wallet: Arc<LocalWallet>) {
169    let user = wallet.address();
170    let vault_address = None;
171    let cloid = Uuid::new_v4();
172    let order = OrderRequest {
173        asset: 4,
174        is_buy: true,
175        reduce_only: false,
176        limit_px: parse_price(2800.0),
177        sz: parse_size(0.0331, 4),
178        order_type: OrderType::Limit(Limit { tif: Tif::Gtc }),
179        cloid: Some(cloid),
180    };
181
182    println!("Placing order with cloid: {}{SEP}", cloid.simple());
183    let response = exchange
184        .place_order(wallet, vec![order], vault_address)
185        .await
186        .expect("Failed to place order");
187
188    println!("Response: {:?}", response);
189
190    tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
191
192    let order_status = info.order_status(user, Oid::Cloid(cloid)).await.unwrap();
193
194    println!(
195        "Order status for {} \n{:?}{SEP}",
196        cloid.simple(),
197        order_status
198    );
199}
More examples
Hide additional examples
examples/agent.rs (line 62)
20async fn main() {
21    // Key was randomly generated for testing and shouldn't be used with any real funds
22    let wallet: Arc<LocalWallet> = Arc::new(
23        "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
24            .parse()
25            .unwrap(),
26    );
27
28    let exchange: Exchange = Hyperliquid::new(Chain::ArbitrumTestnet);
29
30    // Create a new wallet with the agent. This agent can't transfer or withdraw funds
31    // but can place orders.
32
33    let agent = Arc::new(LocalWallet::new(&mut thread_rng()));
34
35    let agent_address = agent.address();
36
37    println!("Agent address: {:?}", agent_address);
38
39    let res = exchange
40        .approve_agent(wallet.clone(), agent_address, Some("WETH".to_string()))
41        .await
42        .unwrap();
43
44    println!("Response: {:?}", res);
45
46    // place order with agent
47    let order_type = OrderType::Limit(Limit { tif: Tif::Gtc });
48    let order = OrderRequest {
49        asset: 4,
50        is_buy: true,
51        reduce_only: false,
52        limit_px: "1700".to_string(),
53        sz: "0.1".to_string(),
54        order_type,
55        cloid: None,
56    };
57    let vault_address = None;
58
59    println!("Placing order with agent...");
60
61    let response = exchange
62        .place_order(agent.clone(), vec![order], vault_address)
63        .await
64        .expect("Failed to place order");
65
66    println!("Response: {:?}", response);
67}
examples/order-status.rs (line 47)
17async fn main() {
18    // Key was randomly generated for testing and shouldn't be used with any real funds
19    let wallet: Arc<LocalWallet> = Arc::new(
20        "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
21            .parse()
22            .unwrap(),
23    );
24
25    let exchange: Exchange = Hyperliquid::new(Chain::Dev);
26    let info: Info = Hyperliquid::new(Chain::Dev);
27
28    let asset = 4;
29    let sz_decimals = 4;
30
31    let order_type = OrderType::Limit(Limit { tif: Tif::Gtc });
32
33    let order = OrderRequest {
34        asset,
35        is_buy: true,
36        reduce_only: false,
37        limit_px: parse_price(2800.0),
38        sz: parse_size(0.0331, sz_decimals),
39        order_type,
40        cloid: None,
41    };
42
43    let vault_address = None;
44
45    println!("Placing order...");
46    let response = exchange
47        .place_order(wallet.clone(), vec![order], vault_address)
48        .await
49        .expect("Failed to place order");
50
51    let response = match response {
52        Response::Ok(order) => order,
53        Response::Err(error) => panic!("Failed to place order: {:?}", error),
54    };
55
56    println!("Response: {:?}", response.data);
57
58    let status_type = &response.data.unwrap();
59
60    let status = match status_type {
61        StatusType::Statuses(statuses) => &statuses[0],
62        _ => {
63            panic!("Failed to place order: {:?}", status_type);
64        }
65    };
66
67    let oid = match status {
68        Status::Filled(order) => order.oid,
69        Status::Resting(order) => order.oid,
70        _ => panic!("Order is not filled or resting"),
71    };
72
73    println!("-----------------");
74
75    println!("Fetching order {} status...", oid);
76
77    let status = info
78        .order_status(wallet.address(), Oid::Order(oid))
79        .await
80        .expect("Failed to fetch order status");
81
82    println!("Order status: {:#?}", status.order);
83}
examples/modify-order.rs (line 44)
17async fn main() {
18    // Key was randomly generated for testing and shouldn't be used with any real funds
19    let wallet: Arc<LocalWallet> = Arc::new(
20        "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
21            .parse()
22            .unwrap(),
23    );
24
25    let exchange: Exchange = Hyperliquid::new(Chain::Dev);
26
27    let order_type = OrderType::Limit(Limit { tif: Tif::Gtc });
28    let cloid = Uuid::new_v4();
29
30    let order = OrderRequest {
31        asset: 4,
32        is_buy: true,
33        reduce_only: false,
34        limit_px: "1800".to_string(),
35        sz: "0.1".to_string(),
36        order_type,
37        cloid: Some(cloid),
38    };
39
40    let vault_address = None;
41
42    println!("Placing order...");
43    let response = exchange
44        .place_order(wallet.clone(), vec![order], vault_address)
45        .await
46        .expect("Failed to place order");
47
48    let response = match response {
49        Response::Ok(order) => order,
50        Response::Err(error) => panic!("Failed to place order: {:?}", error),
51    };
52
53    let status_type = &response.data.unwrap();
54
55    let status = match status_type {
56        StatusType::Statuses(statuses) => &statuses[0],
57        _ => {
58            panic!("Failed to place order: {:?}", status_type);
59        }
60    };
61
62    let oid = match status {
63        Status::Filled(order) => order.oid,
64        Status::Resting(order) => order.oid,
65        _ => panic!("Order is not filled or resting"),
66    };
67
68    println!("Order placed: {:?}", oid);
69
70    tokio::time::sleep(std::time::Duration::from_secs(5)).await;
71
72    let limit_px = "1710".to_string();
73    // Modifying the order
74    println!("Modifying order {oid} limit price to {limit_px}.");
75
76    let order = OrderRequest {
77        asset: 4,
78        is_buy: true,
79        reduce_only: false,
80        limit_px,
81        sz: "0.1".to_string(),
82        order_type: OrderType::Limit(Limit { tif: Tif::Gtc }),
83        cloid: Some(cloid),
84    };
85
86    let order = ModifyRequest { order, oid };
87
88    let response = exchange
89        .modify_order(wallet.clone(), order, vault_address)
90        .await
91        .expect("Failed to modify order");
92
93    println!("Response: {:?}", response);
94}
examples/place-order.rs (line 44)
15async fn main() {
16    // Key was randomly generated for testing and shouldn't be used with any real funds
17    let wallet: Arc<LocalWallet> = Arc::new(
18        "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
19            .parse()
20            .unwrap(),
21    );
22
23    let exchange: Exchange = Hyperliquid::new(Chain::Dev);
24
25    let asset = 4;
26    let sz_decimals = 4;
27
28    let order_type = OrderType::Limit(Limit { tif: Tif::Gtc });
29
30    let order = OrderRequest {
31        asset,
32        is_buy: true,
33        reduce_only: false,
34        limit_px: parse_price(2800.0),
35        sz: parse_size(0.0331, sz_decimals),
36        order_type,
37        cloid: None,
38    };
39
40    let vault_address = None;
41
42    println!("Placing order...");
43    let response = exchange
44        .place_order(wallet.clone(), vec![order], vault_address)
45        .await
46        .expect("Failed to place order");
47
48    println!("Response: {:?}", response);
49
50    println!("-----------------");
51    println!("Placing an order with cloid...");
52
53    let order_type = OrderType::Limit(Limit { tif: Tif::Gtc });
54
55    let cloid = Uuid::new_v4();
56
57    let order = OrderRequest {
58        asset,
59        is_buy: true,
60        reduce_only: false,
61        limit_px: parse_price(2800.0),
62        sz: parse_size(0.0331, sz_decimals),
63        order_type,
64        cloid: Some(cloid),
65    };
66
67    let response = exchange
68        .place_order(wallet.clone(), vec![order], vault_address)
69        .await
70        .expect("Failed to place order");
71
72    println!("Response: {:?}", response);
73
74    println!("-----------------");
75    println!("Placing a trigger order with tpsl...");
76
77    let order_type = OrderType::Trigger(Trigger {
78        is_market: false,
79        trigger_px: parse_price(2800.0),
80        tpsl: TpSl::Tp,
81    });
82
83    let order = OrderRequest {
84        asset,
85        is_buy: true,
86        reduce_only: false,
87        limit_px: parse_price(2800.0),
88        sz: parse_size(0.0331, sz_decimals),
89        order_type,
90        cloid: Some(cloid),
91    };
92
93    let response = exchange
94        .place_order(wallet.clone(), vec![order], vault_address)
95        .await
96        .expect("Failed to place order");
97
98    println!("Response: {:?}", response);
99}
examples/cancel-order.rs (line 43)
17async fn main() {
18    // Key was randomly generated for testing and shouldn't be used with any real funds
19    let wallet: Arc<LocalWallet> = Arc::new(
20        "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
21            .parse()
22            .unwrap(),
23    );
24
25    let exchange: Exchange = Hyperliquid::new(Chain::Dev);
26
27    let order_type = OrderType::Limit(Limit { tif: Tif::Gtc });
28
29    let order = OrderRequest {
30        asset: 4,
31        is_buy: true,
32        reduce_only: false,
33        limit_px: "1800".to_string(),
34        sz: "0.1".to_string(),
35        order_type,
36        cloid: None,
37    };
38
39    let vault_address = None;
40
41    println!("Placing order...");
42    let response = exchange
43        .place_order(wallet.clone(), vec![order], vault_address)
44        .await
45        .expect("Failed to place order");
46
47    let response = match response {
48        Response::Ok(order) => order,
49        Response::Err(error) => panic!("Failed to place order: {:?}", error),
50    };
51
52    let status_type = &response.data.unwrap();
53
54    let status = match status_type {
55        StatusType::Statuses(statuses) => &statuses[0],
56        _ => {
57            panic!("Failed to place order: {:?}", status_type);
58        }
59    };
60
61    let oid = match status {
62        Status::Filled(order) => order.oid,
63        Status::Resting(order) => order.oid,
64        _ => {
65            panic!("Order is not filled or resting, status: {:?}", status);
66        }
67    };
68
69    println!("Order placed: {:?}", oid);
70
71    tokio::time::sleep(std::time::Duration::from_secs(5)).await;
72
73    // Cancel order
74
75    println!("Cancelling order with oid {oid}.");
76    let cancel = CancelRequest { asset: 4, oid };
77
78    let vault_address = None;
79
80    let response = exchange
81        .cancel_order(wallet.clone(), vec![cancel], vault_address)
82        .await
83        .expect("Failed to cancel order");
84
85    println!("Response: {:?}", response);
86
87    let cloid = Uuid::new_v4();
88
89    println!("Placing order with cloid: {}", cloid.simple());
90
91    let order_type = OrderType::Limit(Limit { tif: Tif::Gtc });
92
93    let order = OrderRequest {
94        asset: 4,
95        is_buy: true,
96        reduce_only: false,
97        limit_px: "1700".to_string(),
98        sz: "0.1".to_string(),
99        order_type,
100        cloid: Some(cloid),
101    };
102
103    let vault_address = None;
104
105    let response = exchange
106        .place_order(wallet.clone(), vec![order], vault_address)
107        .await
108        .expect("Failed to place order");
109
110    let response = match response {
111        Response::Ok(order) => order,
112        Response::Err(error) => panic!("Failed to place order: {:?}", error),
113    };
114
115    let data = &response.data.unwrap();
116    let status = match data {
117        StatusType::Statuses(statuses) => &statuses[0],
118        _ => {
119            panic!("Failed to place order: {:?}", data);
120        }
121    };
122
123    let oid = match status {
124        Status::Filled(order) => order.oid,
125        Status::Resting(order) => order.oid,
126        _ => panic!("Order is not filled or resting"),
127    };
128
129    println!("Order placed: {:?}", oid);
130
131    tokio::time::sleep(std::time::Duration::from_secs(5)).await;
132
133    println!("Cancelling order with cloid: {}", cloid.simple());
134    let cancel = CancelByCloidRequest { asset: 4, cloid };
135
136    let response = exchange
137        .cancel_order_by_cloid(wallet.clone(), vec![cancel], vault_address)
138        .await
139        .expect("Failed to cancel order");
140
141    println!("Response: {:?}", response);
142}
Source

pub async fn normal_tpsl( &self, wallet: Arc<LocalWallet>, orders: Vec<OrderRequest>, vault_address: Option<Address>, ) -> Result<Response>

Place a normal order with tpsl order

§Arguments
  • wallet - The wallet to sign the order with
  • orders - The orders to place
  • vault_address - If trading on behalf of a vault, its onchain address in 42-character hexadecimal format e.g. 0x0000000000000000000000000000000000000000
§Note
  • cloid in argument order is an optional 128 bit hex string, e.g. 0x1234567890abcdef1234567890abcdef
Examples found in repository?
examples/normal-tpsl.rs (line 68)
13async fn main() {
14    // Key was randomly generated for testing and shouldn't be used with any real funds
15    let wallet: Arc<LocalWallet> = Arc::new(
16        "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
17            .parse()
18            .unwrap(),
19    );
20
21    let exchange: Exchange = Hyperliquid::new(Chain::Dev);
22
23    let asset = 4;
24    let sz_decimals = 4;
25
26    let normal = OrderRequest {
27        asset,
28        is_buy: true,
29        reduce_only: false,
30        limit_px: parse_price(2800.0),
31        sz: parse_size(0.0331, sz_decimals),
32        order_type: OrderType::Limit(Limit { tif: Tif::Gtc }),
33        cloid: None,
34    };
35
36    let tp = OrderRequest {
37        asset,
38        is_buy: false,
39        reduce_only: true,
40        limit_px: parse_price(2810.0),
41        sz: parse_size(0.0331, sz_decimals),
42        order_type: OrderType::Trigger(Trigger {
43            is_market: true,
44            trigger_px: parse_price(2810.0),
45            tpsl: TpSl::Tp,
46        }),
47        cloid: None,
48    };
49
50    let sl = OrderRequest {
51        asset,
52        is_buy: false,
53        reduce_only: true,
54        limit_px: parse_price(2750.0),
55        sz: parse_size(0.0331, sz_decimals),
56        order_type: OrderType::Trigger(Trigger {
57            is_market: true,
58            trigger_px: parse_price(2750.0),
59            tpsl: TpSl::Tp,
60        }),
61        cloid: None,
62    };
63
64    let vault_address = None;
65
66    println!("Placing normal tpsl order...");
67    let response = exchange
68        .normal_tpsl(wallet.clone(), vec![normal, tp, sl], vault_address)
69        .await
70        .expect("Failed to place order");
71
72    println!("Response: {:?}", response);
73
74    println!("-----------------");
75}
Source

pub async fn cancel_order( &self, wallet: Arc<LocalWallet>, cancels: Vec<CancelRequest>, vault_address: Option<Address>, ) -> Result<Response>

Cancel an order

§Arguments
  • wallet - The wallet to sign the order with
  • cancels - The orders to cancel
  • vault_address - If trading on behalf of a vault, its onchain address in 42-character hexadecimal format e.g. 0x0000000000000000000000000000000000000000
Examples found in repository?
examples/cancel-order.rs (line 81)
17async fn main() {
18    // Key was randomly generated for testing and shouldn't be used with any real funds
19    let wallet: Arc<LocalWallet> = Arc::new(
20        "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
21            .parse()
22            .unwrap(),
23    );
24
25    let exchange: Exchange = Hyperliquid::new(Chain::Dev);
26
27    let order_type = OrderType::Limit(Limit { tif: Tif::Gtc });
28
29    let order = OrderRequest {
30        asset: 4,
31        is_buy: true,
32        reduce_only: false,
33        limit_px: "1800".to_string(),
34        sz: "0.1".to_string(),
35        order_type,
36        cloid: None,
37    };
38
39    let vault_address = None;
40
41    println!("Placing order...");
42    let response = exchange
43        .place_order(wallet.clone(), vec![order], vault_address)
44        .await
45        .expect("Failed to place order");
46
47    let response = match response {
48        Response::Ok(order) => order,
49        Response::Err(error) => panic!("Failed to place order: {:?}", error),
50    };
51
52    let status_type = &response.data.unwrap();
53
54    let status = match status_type {
55        StatusType::Statuses(statuses) => &statuses[0],
56        _ => {
57            panic!("Failed to place order: {:?}", status_type);
58        }
59    };
60
61    let oid = match status {
62        Status::Filled(order) => order.oid,
63        Status::Resting(order) => order.oid,
64        _ => {
65            panic!("Order is not filled or resting, status: {:?}", status);
66        }
67    };
68
69    println!("Order placed: {:?}", oid);
70
71    tokio::time::sleep(std::time::Duration::from_secs(5)).await;
72
73    // Cancel order
74
75    println!("Cancelling order with oid {oid}.");
76    let cancel = CancelRequest { asset: 4, oid };
77
78    let vault_address = None;
79
80    let response = exchange
81        .cancel_order(wallet.clone(), vec![cancel], vault_address)
82        .await
83        .expect("Failed to cancel order");
84
85    println!("Response: {:?}", response);
86
87    let cloid = Uuid::new_v4();
88
89    println!("Placing order with cloid: {}", cloid.simple());
90
91    let order_type = OrderType::Limit(Limit { tif: Tif::Gtc });
92
93    let order = OrderRequest {
94        asset: 4,
95        is_buy: true,
96        reduce_only: false,
97        limit_px: "1700".to_string(),
98        sz: "0.1".to_string(),
99        order_type,
100        cloid: Some(cloid),
101    };
102
103    let vault_address = None;
104
105    let response = exchange
106        .place_order(wallet.clone(), vec![order], vault_address)
107        .await
108        .expect("Failed to place order");
109
110    let response = match response {
111        Response::Ok(order) => order,
112        Response::Err(error) => panic!("Failed to place order: {:?}", error),
113    };
114
115    let data = &response.data.unwrap();
116    let status = match data {
117        StatusType::Statuses(statuses) => &statuses[0],
118        _ => {
119            panic!("Failed to place order: {:?}", data);
120        }
121    };
122
123    let oid = match status {
124        Status::Filled(order) => order.oid,
125        Status::Resting(order) => order.oid,
126        _ => panic!("Order is not filled or resting"),
127    };
128
129    println!("Order placed: {:?}", oid);
130
131    tokio::time::sleep(std::time::Duration::from_secs(5)).await;
132
133    println!("Cancelling order with cloid: {}", cloid.simple());
134    let cancel = CancelByCloidRequest { asset: 4, cloid };
135
136    let response = exchange
137        .cancel_order_by_cloid(wallet.clone(), vec![cancel], vault_address)
138        .await
139        .expect("Failed to cancel order");
140
141    println!("Response: {:?}", response);
142}
Source

pub async fn cancel_order_by_cloid( &self, wallet: Arc<LocalWallet>, cancels: Vec<CancelByCloidRequest>, vault_address: Option<Address>, ) -> Result<Response>

Cancel order(s) by client order id (cloid)

§Arguments
  • wallet - The wallet to sign the order with
  • cancels - The client orders to cancel
  • vault_address - If trading on behalf of a vault, its onchain address in 42-character hexadecimal format e.g. 0x0000000000000000000000000000000000000000

Note: cloid in argument cancel is a 128 bit hex string, e.g. 0x1234567890abcdef1234567890abcdef

Examples found in repository?
examples/cancel-order.rs (line 137)
17async fn main() {
18    // Key was randomly generated for testing and shouldn't be used with any real funds
19    let wallet: Arc<LocalWallet> = Arc::new(
20        "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
21            .parse()
22            .unwrap(),
23    );
24
25    let exchange: Exchange = Hyperliquid::new(Chain::Dev);
26
27    let order_type = OrderType::Limit(Limit { tif: Tif::Gtc });
28
29    let order = OrderRequest {
30        asset: 4,
31        is_buy: true,
32        reduce_only: false,
33        limit_px: "1800".to_string(),
34        sz: "0.1".to_string(),
35        order_type,
36        cloid: None,
37    };
38
39    let vault_address = None;
40
41    println!("Placing order...");
42    let response = exchange
43        .place_order(wallet.clone(), vec![order], vault_address)
44        .await
45        .expect("Failed to place order");
46
47    let response = match response {
48        Response::Ok(order) => order,
49        Response::Err(error) => panic!("Failed to place order: {:?}", error),
50    };
51
52    let status_type = &response.data.unwrap();
53
54    let status = match status_type {
55        StatusType::Statuses(statuses) => &statuses[0],
56        _ => {
57            panic!("Failed to place order: {:?}", status_type);
58        }
59    };
60
61    let oid = match status {
62        Status::Filled(order) => order.oid,
63        Status::Resting(order) => order.oid,
64        _ => {
65            panic!("Order is not filled or resting, status: {:?}", status);
66        }
67    };
68
69    println!("Order placed: {:?}", oid);
70
71    tokio::time::sleep(std::time::Duration::from_secs(5)).await;
72
73    // Cancel order
74
75    println!("Cancelling order with oid {oid}.");
76    let cancel = CancelRequest { asset: 4, oid };
77
78    let vault_address = None;
79
80    let response = exchange
81        .cancel_order(wallet.clone(), vec![cancel], vault_address)
82        .await
83        .expect("Failed to cancel order");
84
85    println!("Response: {:?}", response);
86
87    let cloid = Uuid::new_v4();
88
89    println!("Placing order with cloid: {}", cloid.simple());
90
91    let order_type = OrderType::Limit(Limit { tif: Tif::Gtc });
92
93    let order = OrderRequest {
94        asset: 4,
95        is_buy: true,
96        reduce_only: false,
97        limit_px: "1700".to_string(),
98        sz: "0.1".to_string(),
99        order_type,
100        cloid: Some(cloid),
101    };
102
103    let vault_address = None;
104
105    let response = exchange
106        .place_order(wallet.clone(), vec![order], vault_address)
107        .await
108        .expect("Failed to place order");
109
110    let response = match response {
111        Response::Ok(order) => order,
112        Response::Err(error) => panic!("Failed to place order: {:?}", error),
113    };
114
115    let data = &response.data.unwrap();
116    let status = match data {
117        StatusType::Statuses(statuses) => &statuses[0],
118        _ => {
119            panic!("Failed to place order: {:?}", data);
120        }
121    };
122
123    let oid = match status {
124        Status::Filled(order) => order.oid,
125        Status::Resting(order) => order.oid,
126        _ => panic!("Order is not filled or resting"),
127    };
128
129    println!("Order placed: {:?}", oid);
130
131    tokio::time::sleep(std::time::Duration::from_secs(5)).await;
132
133    println!("Cancelling order with cloid: {}", cloid.simple());
134    let cancel = CancelByCloidRequest { asset: 4, cloid };
135
136    let response = exchange
137        .cancel_order_by_cloid(wallet.clone(), vec![cancel], vault_address)
138        .await
139        .expect("Failed to cancel order");
140
141    println!("Response: {:?}", response);
142}
Source

pub async fn modify_order( &self, wallet: Arc<LocalWallet>, order: ModifyRequest, vault_address: Option<Address>, ) -> Result<Response>

Modify an order

§Arguments
  • wallet - The wallet to sign the order with
  • order - The orders to modify
  • vault_address - If trading on behalf of a vault, its onchain address in 42-character hexadecimal format e.g. 0x0000000000000000000000000000000000000000

Note: cloid in argument order is an optional 128 bit hex string, e.g. 0x1234567890abcdef1234567890abcdef

Examples found in repository?
examples/modify-order.rs (line 89)
17async fn main() {
18    // Key was randomly generated for testing and shouldn't be used with any real funds
19    let wallet: Arc<LocalWallet> = Arc::new(
20        "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
21            .parse()
22            .unwrap(),
23    );
24
25    let exchange: Exchange = Hyperliquid::new(Chain::Dev);
26
27    let order_type = OrderType::Limit(Limit { tif: Tif::Gtc });
28    let cloid = Uuid::new_v4();
29
30    let order = OrderRequest {
31        asset: 4,
32        is_buy: true,
33        reduce_only: false,
34        limit_px: "1800".to_string(),
35        sz: "0.1".to_string(),
36        order_type,
37        cloid: Some(cloid),
38    };
39
40    let vault_address = None;
41
42    println!("Placing order...");
43    let response = exchange
44        .place_order(wallet.clone(), vec![order], vault_address)
45        .await
46        .expect("Failed to place order");
47
48    let response = match response {
49        Response::Ok(order) => order,
50        Response::Err(error) => panic!("Failed to place order: {:?}", error),
51    };
52
53    let status_type = &response.data.unwrap();
54
55    let status = match status_type {
56        StatusType::Statuses(statuses) => &statuses[0],
57        _ => {
58            panic!("Failed to place order: {:?}", status_type);
59        }
60    };
61
62    let oid = match status {
63        Status::Filled(order) => order.oid,
64        Status::Resting(order) => order.oid,
65        _ => panic!("Order is not filled or resting"),
66    };
67
68    println!("Order placed: {:?}", oid);
69
70    tokio::time::sleep(std::time::Duration::from_secs(5)).await;
71
72    let limit_px = "1710".to_string();
73    // Modifying the order
74    println!("Modifying order {oid} limit price to {limit_px}.");
75
76    let order = OrderRequest {
77        asset: 4,
78        is_buy: true,
79        reduce_only: false,
80        limit_px,
81        sz: "0.1".to_string(),
82        order_type: OrderType::Limit(Limit { tif: Tif::Gtc }),
83        cloid: Some(cloid),
84    };
85
86    let order = ModifyRequest { order, oid };
87
88    let response = exchange
89        .modify_order(wallet.clone(), order, vault_address)
90        .await
91        .expect("Failed to modify order");
92
93    println!("Response: {:?}", response);
94}
Source

pub async fn batch_modify_orders( &self, wallet: Arc<LocalWallet>, orders: Vec<ModifyRequest>, vault_address: Option<Address>, ) -> Result<Response>

Batch modify orders

§Arguments
  • wallet - The wallet to sign the order with
  • orders - The orders to modify
  • vault_address - If trading on behalf of a vault, its onchain address in 42-character hexadecimal format e.g. 0x0000000000000000000000000000000000000000
Source

pub async fn update_leverage( &self, wallet: Arc<LocalWallet>, leverage: u32, asset: u32, is_cross: bool, ) -> Result<Response>

Update cross or isolated leverage on a coin

§Arguments
  • wallet - The wallet to sign the order with
  • leverage - The new leverage to set
  • asset - The asset to set the leverage for
  • is_cross - true if cross leverage, false if isolated leverage
Examples found in repository?
examples/leverage.rs (line 24)
7async fn main() {
8    // Key was randomly generated for testing and shouldn't be used with any real funds
9    let wallet: Arc<LocalWallet> = Arc::new(
10        "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
11            .parse()
12            .unwrap(),
13    );
14
15    let exchange: Exchange = Hyperliquid::new(Chain::Dev);
16
17    let leverage = 2;
18    let asset = 4;
19    let is_cross = false;
20
21    println!("Updating leverage to {}x ...", leverage);
22
23    let res = exchange
24        .update_leverage(wallet.clone(), leverage, asset, is_cross)
25        .await
26        .unwrap();
27
28    println!("Response: {:?}", res);
29
30    let margin = 1;
31
32    println!("--\nUpdating isolated margin for ETH to {margin}% ...");
33
34    let res = exchange
35        .update_isolated_margin(wallet.clone(), asset, true, margin)
36        .await
37        .unwrap();
38
39    println!("Response: {:?}", res);
40
41    let info: Info = Hyperliquid::new(Chain::Dev);
42
43    // user state
44    let res = info.user_state(wallet.address()).await.unwrap();
45
46    println!("--\nUser state: {:?}", res);
47}
Source

pub async fn update_isolated_margin( &self, wallet: Arc<LocalWallet>, asset: u32, is_buy: bool, ntli: i64, ) -> Result<Response>

Add or remove margin from isolated position

§Arguments
  • wallet - The wallet to sign the order with
  • asset - The asset to set the margin for
  • is_buy - true if adding margin, false if removing margin
  • ntli - The new margin to set
Examples found in repository?
examples/leverage.rs (line 35)
7async fn main() {
8    // Key was randomly generated for testing and shouldn't be used with any real funds
9    let wallet: Arc<LocalWallet> = Arc::new(
10        "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
11            .parse()
12            .unwrap(),
13    );
14
15    let exchange: Exchange = Hyperliquid::new(Chain::Dev);
16
17    let leverage = 2;
18    let asset = 4;
19    let is_cross = false;
20
21    println!("Updating leverage to {}x ...", leverage);
22
23    let res = exchange
24        .update_leverage(wallet.clone(), leverage, asset, is_cross)
25        .await
26        .unwrap();
27
28    println!("Response: {:?}", res);
29
30    let margin = 1;
31
32    println!("--\nUpdating isolated margin for ETH to {margin}% ...");
33
34    let res = exchange
35        .update_isolated_margin(wallet.clone(), asset, true, margin)
36        .await
37        .unwrap();
38
39    println!("Response: {:?}", res);
40
41    let info: Info = Hyperliquid::new(Chain::Dev);
42
43    // user state
44    let res = info.user_state(wallet.address()).await.unwrap();
45
46    println!("--\nUser state: {:?}", res);
47}
Source

pub async fn twap_order( &self, wallet: Arc<LocalWallet>, twap: TwapRequest, vault_address: Option<Address>, ) -> Result<Response>

Place a TWAP order

§Arguments
  • wallet - The wallet to sign the order with
  • twap - The twap order to place
  • vault_address - If trading on behalf of a vault, its onchain address in 42-character hexadecimal format e.g. 0x0000000000000000000000000000000000000000
Examples found in repository?
examples/twap_order.rs (line 37)
11async fn main() {
12    // Key was randomly generated for testing and shouldn't be used with any real funds
13    let wallet: Arc<LocalWallet> = Arc::new(
14        "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
15            .parse()
16            .unwrap(),
17    );
18
19    let exchange: Exchange = Hyperliquid::new(Chain::Dev);
20
21    let asset = 0;
22    let sz_decimals = 2;
23
24    let twap = TwapRequest {
25        asset,
26        is_buy: true,
27        reduce_only: false,
28        duration: 10,
29        sz: parse_size(13.85, sz_decimals),
30        randomize: true,
31    };
32
33    let vault_address = None;
34
35    println!("Placing a TWAP order...");
36    let response = exchange
37        .twap_order(wallet.clone(), twap, vault_address)
38        .await
39        .expect("Failed to place twap order");
40
41    println!("Response: {:?}", response);
42}
Source

pub async fn usdc_transfer( &self, from: Arc<LocalWallet>, destination: Address, amount: String, ) -> Result<Response>

Send usd to another address. This transfer does not touch the EVM bridge. The signature format is human readable for wallet interfaces.

§Arguments
  • from - The wallet to sign the transfer with
  • destination - The address to send the usd to
  • amount - The amount of usd to send
Examples found in repository?
examples/usd_send.rs (line 31)
7async fn main() {
8    // Key was randomly generated for testing and shouldn't be used with any real funds
9    let wallet: Arc<LocalWallet> = Arc::new(
10        "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
11            .parse()
12            .unwrap(),
13    );
14
15    let exchange: Exchange = Hyperliquid::new(Chain::ArbitrumTestnet);
16
17    let destination = "0x0D1d9635D0640821d15e323ac8AdADfA9c111414"
18        .parse()
19        .expect("Invalid address");
20
21    let amount = "1".to_string(); // USD
22
23    println!(
24        "Transferring ${} from {:?} to {:?}",
25        amount,
26        wallet.address(),
27        destination
28    );
29
30    let res = exchange
31        .usdc_transfer(wallet.clone(), destination, amount)
32        .await
33        .unwrap();
34
35    println!("Response: {:?}", res);
36}
Source

pub async fn withdraw_from_bridge( &self, wallet: Arc<LocalWallet>, destination: Address, amount: String, ) -> Result<Response>

Withdraw from bridge

§Arguments
  • wallet - The wallet to sign the withdrawal with
  • destination - The address to send the usd to
  • amount - The amount of usd to send
Examples found in repository?
examples/bridge.rs (line 26)
7async fn main() {
8    // Key was randomly generated for testing and shouldn't be used with any real funds
9    let wallet: Arc<LocalWallet> = Arc::new(
10        "8547bf37e4ac35e85d1e8afc2a2ba5c7f352b8a11ae916e9f14737737e8e0e47"
11            .parse()
12            .unwrap(),
13    );
14
15    let exchange: Exchange = Hyperliquid::new(Chain::ArbitrumGoerli);
16
17    let destination = "0x0D1d9635D0640821d15e323ac8AdADfA9c111414"
18        .parse()
19        .expect("Invalid address");
20
21    let usd = "10".to_string(); // USD
22
23    println!("Withdrawing ${} from bridge to {:?}", usd, destination);
24
25    let res = exchange
26        .withdraw_from_bridge(wallet.clone(), destination, usd)
27        .await
28        .unwrap();
29
30    println!("Response: {:?}", res);
31}
Source

pub async fn approve_agent( &self, wallet: Arc<LocalWallet>, agent_address: Address, agent_name: Option<String>, ) -> Result<Response>

Approve an agent to trade on behalf of the user

§Arguments
  • wallet - The wallet to sign the approval with
  • agent_address - The address of the agent to approve
  • agent_name - An optional name for the agent
Examples found in repository?
examples/agent.rs (line 40)
20async fn main() {
21    // Key was randomly generated for testing and shouldn't be used with any real funds
22    let wallet: Arc<LocalWallet> = Arc::new(
23        "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
24            .parse()
25            .unwrap(),
26    );
27
28    let exchange: Exchange = Hyperliquid::new(Chain::ArbitrumTestnet);
29
30    // Create a new wallet with the agent. This agent can't transfer or withdraw funds
31    // but can place orders.
32
33    let agent = Arc::new(LocalWallet::new(&mut thread_rng()));
34
35    let agent_address = agent.address();
36
37    println!("Agent address: {:?}", agent_address);
38
39    let res = exchange
40        .approve_agent(wallet.clone(), agent_address, Some("WETH".to_string()))
41        .await
42        .unwrap();
43
44    println!("Response: {:?}", res);
45
46    // place order with agent
47    let order_type = OrderType::Limit(Limit { tif: Tif::Gtc });
48    let order = OrderRequest {
49        asset: 4,
50        is_buy: true,
51        reduce_only: false,
52        limit_px: "1700".to_string(),
53        sz: "0.1".to_string(),
54        order_type,
55        cloid: None,
56    };
57    let vault_address = None;
58
59    println!("Placing order with agent...");
60
61    let response = exchange
62        .place_order(agent.clone(), vec![order], vault_address)
63        .await
64        .expect("Failed to place order");
65
66    println!("Response: {:?}", response);
67}
Source

pub async fn create_sub_account( &self, wallet: Arc<LocalWallet>, name: String, ) -> Result<Response>

Create subaccount for the user

§Arguments
  • wallet - The wallet to create the subaccount with
  • name - The name of the subaccount
Examples found in repository?
examples/subaccount.rs (line 34)
13async fn main() {
14    // Key was randomly generated for testing and shouldn't be used with any real funds
15    let wallet: Arc<LocalWallet> = Arc::new(
16        "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
17            .parse()
18            .unwrap(),
19    );
20
21    let exchange: Exchange = Hyperliquid::new(Chain::ArbitrumTestnet);
22
23    println!("Creating subaccount...");
24    let name = {
25        let suffix = timestamp().to_string();
26
27        // slice the last 4 characters
28        let suffix = &suffix[suffix.len() - 4..];
29
30        format!("Acc-{}", suffix)
31    };
32
33    let response = exchange
34        .create_sub_account(wallet.clone(), name.clone())
35        .await
36        .expect("Failed to create subaccount");
37
38    let response = match response {
39        Response::Ok(sub_account) => sub_account,
40        Response::Err(error) => {
41            panic!("Failed to create subaccount: {:?}", error)
42        }
43    };
44
45    let sub_account_user = match response.data {
46        Some(StatusType::Address(address)) => address,
47        _ => panic!("Failed to get subaccount address: {:?}", response),
48    };
49
50    println!(
51        "Subaccount created with name {} and user address: {:x} ✓",
52        name, sub_account_user
53    );
54
55    tokio::time::sleep(std::time::Duration::from_secs(10)).await;
56
57    let new_name = {
58        let suffix = timestamp().to_string();
59
60        // slice the last 4 characters
61        let suffix = &suffix[suffix.len() - 4..];
62
63        format!("Acc-{}", suffix)
64    };
65
66    println!("Renaming subaccount to: {}", new_name);
67
68    let response = exchange
69        .sub_account_modify(wallet.clone(), new_name, sub_account_user)
70        .await
71        .expect("Failed to rename subaccount");
72
73    let response = match response {
74        Response::Ok(sub_account) => sub_account,
75        Response::Err(error) => {
76            panic!("Failed to rename subaccount: {:?}", error)
77        }
78    };
79
80    println!("Subaccount rename response: {:?} ✓", response);
81
82    tokio::time::sleep(std::time::Duration::from_secs(5)).await;
83
84    println!("Depositing 1 USD to subaccount...");
85
86    let usd = 1_000_000;
87
88    let is_deposit = true;
89
90    let response = exchange
91        .sub_account_transfer(wallet.clone(), is_deposit, sub_account_user, usd)
92        .await
93        .expect("Failed to deposit funds");
94
95    let response = match response {
96        Response::Ok(response) => response,
97        Response::Err(error) => {
98            panic!("Failed to deposit funds: {:?}", error)
99        }
100    };
101
102    println!("Deposit response: {:?} ✓", response);
103
104    tokio::time::sleep(std::time::Duration::from_secs(10)).await;
105
106    println!("Withdrawing funds from subaccount...");
107
108    let response = exchange
109        .sub_account_transfer(wallet.clone(), !is_deposit, sub_account_user, usd)
110        .await
111        .expect("Failed to withdraw funds");
112
113    let response = match response {
114        Response::Ok(response) => response,
115        Response::Err(error) => {
116            panic!("Failed to withdraw funds: {:?}", error)
117        }
118    };
119
120    println!("Withdraw response: {:?} ✓", response);
121}
Source

pub async fn sub_account_modify( &self, wallet: Arc<LocalWallet>, name: String, sub_account_user: Address, ) -> Result<Response>

Rename subaccount

§Arguments
  • wallet - The wallet to sign the rename with
  • name - The new name of the subaccount
  • sub_account_user - The address of the subaccount to rename
Examples found in repository?
examples/subaccount.rs (line 69)
13async fn main() {
14    // Key was randomly generated for testing and shouldn't be used with any real funds
15    let wallet: Arc<LocalWallet> = Arc::new(
16        "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
17            .parse()
18            .unwrap(),
19    );
20
21    let exchange: Exchange = Hyperliquid::new(Chain::ArbitrumTestnet);
22
23    println!("Creating subaccount...");
24    let name = {
25        let suffix = timestamp().to_string();
26
27        // slice the last 4 characters
28        let suffix = &suffix[suffix.len() - 4..];
29
30        format!("Acc-{}", suffix)
31    };
32
33    let response = exchange
34        .create_sub_account(wallet.clone(), name.clone())
35        .await
36        .expect("Failed to create subaccount");
37
38    let response = match response {
39        Response::Ok(sub_account) => sub_account,
40        Response::Err(error) => {
41            panic!("Failed to create subaccount: {:?}", error)
42        }
43    };
44
45    let sub_account_user = match response.data {
46        Some(StatusType::Address(address)) => address,
47        _ => panic!("Failed to get subaccount address: {:?}", response),
48    };
49
50    println!(
51        "Subaccount created with name {} and user address: {:x} ✓",
52        name, sub_account_user
53    );
54
55    tokio::time::sleep(std::time::Duration::from_secs(10)).await;
56
57    let new_name = {
58        let suffix = timestamp().to_string();
59
60        // slice the last 4 characters
61        let suffix = &suffix[suffix.len() - 4..];
62
63        format!("Acc-{}", suffix)
64    };
65
66    println!("Renaming subaccount to: {}", new_name);
67
68    let response = exchange
69        .sub_account_modify(wallet.clone(), new_name, sub_account_user)
70        .await
71        .expect("Failed to rename subaccount");
72
73    let response = match response {
74        Response::Ok(sub_account) => sub_account,
75        Response::Err(error) => {
76            panic!("Failed to rename subaccount: {:?}", error)
77        }
78    };
79
80    println!("Subaccount rename response: {:?} ✓", response);
81
82    tokio::time::sleep(std::time::Duration::from_secs(5)).await;
83
84    println!("Depositing 1 USD to subaccount...");
85
86    let usd = 1_000_000;
87
88    let is_deposit = true;
89
90    let response = exchange
91        .sub_account_transfer(wallet.clone(), is_deposit, sub_account_user, usd)
92        .await
93        .expect("Failed to deposit funds");
94
95    let response = match response {
96        Response::Ok(response) => response,
97        Response::Err(error) => {
98            panic!("Failed to deposit funds: {:?}", error)
99        }
100    };
101
102    println!("Deposit response: {:?} ✓", response);
103
104    tokio::time::sleep(std::time::Duration::from_secs(10)).await;
105
106    println!("Withdrawing funds from subaccount...");
107
108    let response = exchange
109        .sub_account_transfer(wallet.clone(), !is_deposit, sub_account_user, usd)
110        .await
111        .expect("Failed to withdraw funds");
112
113    let response = match response {
114        Response::Ok(response) => response,
115        Response::Err(error) => {
116            panic!("Failed to withdraw funds: {:?}", error)
117        }
118    };
119
120    println!("Withdraw response: {:?} ✓", response);
121}
Source

pub async fn sub_account_transfer( &self, wallet: Arc<LocalWallet>, is_deposit: bool, sub_account_user: Address, usd: u64, ) -> Result<Response>

Transfer funds between subaccounts

§Arguments
  • wallet - The wallet to sign the transfer with
  • from - The subaccount to transfer from
Examples found in repository?
examples/subaccount.rs (line 91)
13async fn main() {
14    // Key was randomly generated for testing and shouldn't be used with any real funds
15    let wallet: Arc<LocalWallet> = Arc::new(
16        "e908f86dbb4d55ac876378565aafeabc187f6690f046459397b17d9b9a19688e"
17            .parse()
18            .unwrap(),
19    );
20
21    let exchange: Exchange = Hyperliquid::new(Chain::ArbitrumTestnet);
22
23    println!("Creating subaccount...");
24    let name = {
25        let suffix = timestamp().to_string();
26
27        // slice the last 4 characters
28        let suffix = &suffix[suffix.len() - 4..];
29
30        format!("Acc-{}", suffix)
31    };
32
33    let response = exchange
34        .create_sub_account(wallet.clone(), name.clone())
35        .await
36        .expect("Failed to create subaccount");
37
38    let response = match response {
39        Response::Ok(sub_account) => sub_account,
40        Response::Err(error) => {
41            panic!("Failed to create subaccount: {:?}", error)
42        }
43    };
44
45    let sub_account_user = match response.data {
46        Some(StatusType::Address(address)) => address,
47        _ => panic!("Failed to get subaccount address: {:?}", response),
48    };
49
50    println!(
51        "Subaccount created with name {} and user address: {:x} ✓",
52        name, sub_account_user
53    );
54
55    tokio::time::sleep(std::time::Duration::from_secs(10)).await;
56
57    let new_name = {
58        let suffix = timestamp().to_string();
59
60        // slice the last 4 characters
61        let suffix = &suffix[suffix.len() - 4..];
62
63        format!("Acc-{}", suffix)
64    };
65
66    println!("Renaming subaccount to: {}", new_name);
67
68    let response = exchange
69        .sub_account_modify(wallet.clone(), new_name, sub_account_user)
70        .await
71        .expect("Failed to rename subaccount");
72
73    let response = match response {
74        Response::Ok(sub_account) => sub_account,
75        Response::Err(error) => {
76            panic!("Failed to rename subaccount: {:?}", error)
77        }
78    };
79
80    println!("Subaccount rename response: {:?} ✓", response);
81
82    tokio::time::sleep(std::time::Duration::from_secs(5)).await;
83
84    println!("Depositing 1 USD to subaccount...");
85
86    let usd = 1_000_000;
87
88    let is_deposit = true;
89
90    let response = exchange
91        .sub_account_transfer(wallet.clone(), is_deposit, sub_account_user, usd)
92        .await
93        .expect("Failed to deposit funds");
94
95    let response = match response {
96        Response::Ok(response) => response,
97        Response::Err(error) => {
98            panic!("Failed to deposit funds: {:?}", error)
99        }
100    };
101
102    println!("Deposit response: {:?} ✓", response);
103
104    tokio::time::sleep(std::time::Duration::from_secs(10)).await;
105
106    println!("Withdrawing funds from subaccount...");
107
108    let response = exchange
109        .sub_account_transfer(wallet.clone(), !is_deposit, sub_account_user, usd)
110        .await
111        .expect("Failed to withdraw funds");
112
113    let response = match response {
114        Response::Ok(response) => response,
115        Response::Err(error) => {
116            panic!("Failed to withdraw funds: {:?}", error)
117        }
118    };
119
120    println!("Withdraw response: {:?} ✓", response);
121}
Source

pub async fn set_referrer( &self, wallet: Arc<LocalWallet>, code: String, ) -> Result<Response>

Set referrer for the user

§Arguments
  • wallet - The wallet to sign the transfer with
  • code - The referrer code
Source

pub async fn schedule_cancel( &self, wallet: Arc<LocalWallet>, time: Option<u64>, ) -> Result<Response>

Schedule a time in (UTC ms) to cancel all open orders

§Arguments
  • wallet - The wallet to sign the transaction with
  • time - Optional time in milliseconds to cancel all open orders
§Note
  • If time is None, then unsets any cancel time in the future. time must be atleast 5 seconds after the current time
  • Once the time is reached, all open orders will be cancelled and trigger count will be incremented. The max number of triggers is 10 per day. Trigger count resets at 00:00 UTC

Trait Implementations§

Source§

impl Hyperliquid for Exchange

Source§

fn new(chain: Chain) -> Self

Source§

fn new_with_config(chain: Chain, config: &Config) -> Self

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> JsonSchemaMaybe for T