pub struct Info {
pub client: Client,
pub chain: Chain,
}
Expand description
Endpoint to fetch information about the exchange and specific users.
Fields§
§client: Client
§chain: Chain
Implementations§
Source§impl Info
impl Info
Sourcepub async fn mids(&self) -> Result<HashMap<String, String>>
pub async fn mids(&self) -> Result<HashMap<String, String>>
Retrieve all mids for all actively traded coins
Sourcepub async fn contexts(&self) -> Result<Vec<AssetContext>>
pub async fn contexts(&self) -> Result<Vec<AssetContext>>
Retrieve asset contexts i.e mark price, current funding, open interest, etc
Sourcepub async fn user_state(&self, user: Address) -> Result<UserState>
pub async fn user_state(&self, user: Address) -> Result<UserState>
Retrieve a user’s state to see user’s open positions and margin summary
§Arguments
user
- The user’s address in 42-character hexadecimal format; e.g.0x0000000000000000000000000000000000000000
Examples found in repository?
More examples
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}
Sourcepub async fn user_states(&self, users: Vec<Address>) -> Result<Vec<UserState>>
pub async fn user_states(&self, users: Vec<Address>) -> Result<Vec<UserState>>
Retrieve a user’s state to see user’s open positions and margin summary in batch
§Arguments
users
- A list of user addresses in 42-character hexadecimal format
Sourcepub async fn open_orders(&self, user: Address) -> Result<Vec<OpenOrder>>
pub async fn open_orders(&self, user: Address) -> Result<Vec<OpenOrder>>
Retrieve a user’s open orders
§Arguments
user
- The user’s address in 42-character hexadecimal format; e.g.0x0000000000000000000000000000000000000000
Sourcepub async fn frontend_open_orders(
&self,
user: Address,
) -> Result<Vec<FrontendOpenOrders>>
pub async fn frontend_open_orders( &self, user: Address, ) -> Result<Vec<FrontendOpenOrders>>
Retrieve a user’s open orders with additional frontend info. This is useful for displaying orders in a UI
§Arguments
user
- The user’s address in 42-character hexadecimal format; e.g.0x0000000000000000000000000000000000000000
Sourcepub async fn user_fills(&self, user: Address) -> Result<Vec<UserFill>>
pub async fn user_fills(&self, user: Address) -> Result<Vec<UserFill>>
Retrieve a user’s Userfills
§Arguments
user
- The user’s address in 42-character hexadecimal format; e.g.0x0000000000000000000000000000000000000000
Sourcepub async fn user_fills_by_time(
&self,
user: Address,
start_time: u64,
end_time: Option<u64>,
) -> Result<Vec<UserFill>>
pub async fn user_fills_by_time( &self, user: Address, start_time: u64, end_time: Option<u64>, ) -> Result<Vec<UserFill>>
Retrieve a user’s fills by time
§Arguments
user
- The user’s address in 42-character hexadecimal format; e.g.0x0000000000000000000000000000000000000000
start_time
- Start time in milliseconds, inclusiveend_time
- End time in milliseconds, inclusive. IfNone
, it will default to the current time
§Note
- Number of fills is limited to 2000
Sourcepub async fn user_funding(
&self,
user: Address,
start_time: u64,
end_time: Option<u64>,
) -> Result<Vec<UserFunding>>
pub async fn user_funding( &self, user: Address, start_time: u64, end_time: Option<u64>, ) -> Result<Vec<UserFunding>>
Retrieve a user’s funding history
§Arguments
user
- The user’s address in 42-character hexadecimal format; e.g.0x0000000000000000000000000000000000000000
start_time
- Start time in milliseconds, inclusiveend_time
- End time in milliseconds, inclusive. IfNone
, it will default to the current time
Examples found in repository?
106async fn user_funding(info: &Info, user: Address) {
107 let start_timestamp = 1690540602225;
108 let end_timestamp = 1690569402225;
109
110 let user_funding = info
111 .user_funding(user, start_timestamp, Some(end_timestamp))
112 .await
113 .unwrap();
114 println!(
115 "User funding for {user} between {start_timestamp} and {end_timestamp} \n{:?}{SEP}",
116 user_funding
117 );
118}
Sourcepub async fn funding_history(
&self,
coin: String,
start_time: u64,
end_time: Option<u64>,
) -> Result<Vec<FundingHistory>>
pub async fn funding_history( &self, coin: String, start_time: u64, end_time: Option<u64>, ) -> Result<Vec<FundingHistory>>
Retrieve historical funding rates for a coin
§Arguments
coin
- The coin to retrieve funding history for e.gBTC
,ETH
, etcstart_time
- Start time in milliseconds, inclusiveend_time
- End time in milliseconds, inclusive. IfNone
, it will default to the current time
Examples found in repository?
120async fn funding_history(info: &Info) {
121 let coin = "ETH";
122
123 let start_timestamp = 1690540602225;
124 let end_timestamp = 1690569402225;
125
126 let funding_history = info
127 .funding_history(coin.to_string(), start_timestamp, Some(end_timestamp))
128 .await
129 .unwrap();
130 println!(
131 "Funding history for {coin} between {start_timestamp} and {end_timestamp} \n{:?}{SEP}",
132 funding_history
133 );
134}
Sourcepub async fn l2_book(&self, coin: String) -> Result<L2Book>
pub async fn l2_book(&self, coin: String) -> Result<L2Book>
Retrieve the L2 order book for a coin
§Arguments
coin
- The coin to retrieve the L2 order book for e.gBTC
,ETH
, etc
Sourcepub async fn recent_trades(&self, coin: String) -> Result<Vec<RecentTrades>>
pub async fn recent_trades(&self, coin: String) -> Result<Vec<RecentTrades>>
Sourcepub async fn candle_snapshot(
&self,
coin: String,
interval: String,
start_time: u64,
end_time: u64,
) -> Result<Vec<CandleSnapshot>>
pub async fn candle_snapshot( &self, coin: String, interval: String, start_time: u64, end_time: u64, ) -> Result<Vec<CandleSnapshot>>
Retrieve candle snapshot for a coin
§Arguments
coin
- The coin to retrieve the candle snapshot for e.gBTC
,ETH
, etcinterval
- The interval to retrieve the candle snapshot forstart_time
- Start time in milliseconds, inclusiveend_time
- End time in milliseconds, inclusive.
Examples found in repository?
150async fn candle_snapshot(info: &Info) {
151 let coin = "ETH";
152 let interval = "15m";
153 let start_timestamp = 1690540602225;
154 let end_timestamp = 1690569402225;
155
156 let snapshot = info
157 .candle_snapshot(
158 coin.to_string(),
159 interval.to_string(),
160 start_timestamp,
161 end_timestamp,
162 )
163 .await
164 .unwrap();
165 println!("Candle snapshot for {coin} between {start_timestamp} and {end_timestamp} with interval {interval} \n{:?}{SEP}",snapshot);
166}
Sourcepub async fn order_status(&self, user: Address, oid: Oid) -> Result<OrderStatus>
pub async fn order_status(&self, user: Address, oid: Oid) -> Result<OrderStatus>
Query the status of an order by oid
or cloid
§Arguments
user
- The user’s address in 42-character hexadecimal format; e.g.0x0000000000000000000000000000000000000000
oid
- The order id either u64 representing the order id or 16-byte hex string representing the client order id
Examples found in repository?
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
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}
Sourcepub async fn sub_accounts(
&self,
user: Address,
) -> Result<Option<Vec<SubAccount>>>
pub async fn sub_accounts( &self, user: Address, ) -> Result<Option<Vec<SubAccount>>>
Query user sub-accounts
§Arguments
user
- The user’s address in 42-character hexadecimal format; e.g.0x0000000000000000000000000000000000000000
Source§impl Info
impl Info
Sourcepub async fn spot_meta_and_asset_ctxs(
&self,
) -> Result<Vec<SpotMetaAndAssetCtxs>>
pub async fn spot_meta_and_asset_ctxs( &self, ) -> Result<Vec<SpotMetaAndAssetCtxs>>
Retrieve spot asset contexts
Sourcepub async fn spot_clearinghouse_state(
&self,
user: Address,
) -> Result<UserSpotState>
pub async fn spot_clearinghouse_state( &self, user: Address, ) -> Result<UserSpotState>
Retrieve a user’s token balances
§Arguments
user
- The user’s address in 42-character hexadecimal format; e.g.0x0000000000000000000000000000000000000000
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Info
impl !RefUnwindSafe for Info
impl Send for Info
impl Sync for Info
impl Unpin for Info
impl !UnwindSafe for Info
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
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
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
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
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.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
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.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
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.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
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.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
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.