-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3903427
commit 92622a7
Showing
10 changed files
with
225 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
use okx_rs::api::v5::model::InstrumentType::Spot; | ||
use okx_rs::api::v5::testkit::with_public_client; | ||
use okx_rs::api::v5::GetInstruments; | ||
use okx_rs::api::{Options, Production, Rest}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
with_public_client(|client| async move { | ||
let response = client | ||
.request(GetInstruments { | ||
inst_type: Spot, | ||
uly: None, | ||
inst_family: None, | ||
inst_id: None, | ||
}) | ||
.await | ||
.unwrap(); | ||
println!("{}", serde_json::to_string_pretty(&response).unwrap()); | ||
}) | ||
.await; | ||
env_logger::try_init().unwrap(); | ||
|
||
let client = Rest::new(Options::new(Production)); | ||
let response = client | ||
.request(GetInstruments { | ||
inst_type: Spot, | ||
uly: None, | ||
inst_family: None, | ||
inst_id: None, | ||
}) | ||
.await | ||
.unwrap(); | ||
println!("{}", serde_json::to_string_pretty(&response).unwrap()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,84 @@ | ||
#[derive(Debug, Clone, Default)] | ||
use std::sync::Arc; | ||
|
||
#[derive(Clone)] | ||
pub struct Production; | ||
|
||
impl OKXEnv for Production { | ||
fn rest(&self) -> &str { | ||
"https://www.okx.com/api/v5" | ||
} | ||
|
||
fn public_websocket(&self) -> &str { | ||
"wss://ws.okx.com:8443/ws/v5/public" | ||
} | ||
|
||
fn private_websocket(&self) -> &str { | ||
"wss://ws.okx.com:8443/ws/v5/private" | ||
} | ||
|
||
fn business_websocket(&self) -> &str { | ||
"wss://ws.okx.com:8443/ws/v5/business" | ||
} | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct DemoTrading; | ||
|
||
impl OKXEnv for DemoTrading { | ||
fn rest(&self) -> &str { | ||
"https://www.okx.com/api/v5" | ||
} | ||
|
||
fn public_websocket(&self) -> &str { | ||
"wss://wspap.okx.com:8443/ws/v5/public?brokerId=9999" | ||
} | ||
|
||
fn private_websocket(&self) -> &str { | ||
"wss://wspap.okx.com:8443/ws/v5/private?brokerId=9999" | ||
} | ||
|
||
fn business_websocket(&self) -> &str { | ||
"wss://wspap.okx.com:8443/ws/v5/business?brokerId=9999" | ||
} | ||
} | ||
|
||
pub trait OKXEnv { | ||
fn rest(&self) -> &str; | ||
fn public_websocket(&self) -> &str; | ||
fn private_websocket(&self) -> &str; | ||
fn business_websocket(&self) -> &str; | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct Options { | ||
pub env: Arc<dyn OKXEnv>, | ||
pub key: Option<String>, | ||
pub secret: Option<String>, | ||
pub passphrase: Option<String>, | ||
} | ||
|
||
impl Options { | ||
pub fn new(env: impl OKXEnv + 'static) -> Options { | ||
Self { | ||
env: Arc::new(env), | ||
key: None, | ||
secret: None, | ||
passphrase: None, | ||
} | ||
} | ||
} | ||
|
||
impl Options { | ||
pub fn rest(&self) -> &str { | ||
self.env.rest() | ||
} | ||
pub fn public_websocket(&self) -> &str { | ||
self.env.public_websocket() | ||
} | ||
pub fn private_websocket(&self) -> &str { | ||
self.env.private_websocket() | ||
} | ||
pub fn business_websocket(&self) -> &str { | ||
self.env.business_websocket() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.