Skip to content

Commit

Permalink
v2.0.1, async_callbacks and general optimizations.
Browse files Browse the repository at this point in the history
- Increased visibility of `apis::*` to improve documentation.
- General cleaning of the API for documentation due to new linting.
- Refactored the Order Builder to be easier to manage.
- Refactored Message parsing for the WebSocket.
- Removed the `sub` and `unsub` functions from the websocket.
- Added support for the FuturesBalanceSummary channel for the websocket.
- JWT Generation Optimizations.
- Added PANIC and ERROR documentation.
- WebSocket MessageCallbacks are now asynchronous.
- Updated the `websocket` example to demonstrate using a callback function and not trait.
- Re-exporting `async_trait` for user friendliness.
- `FunctionCallback` automatically converts `async` and `sync` functions to trait-based.
- Added the `From` trait to convert from CandleUpdate to Candle.
- Documentation updates.
  • Loading branch information
Ohkthx authored Dec 2, 2024
2 parents e26b9cb + 69ad0b3 commit 8718cb3
Show file tree
Hide file tree
Showing 56 changed files with 1,618 additions and 1,178 deletions.
14 changes: 13 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cbadv"
version = "2.0.0"
version = "2.0.1"
edition = "2021"
description = "Asynchronous Coinbase Advanced REST and WebSocket API"
license = "MIT"
Expand Down Expand Up @@ -36,6 +36,7 @@ toml = { version = "0.8.19", optional = true }
# WebSocket support
tokio-tungstenite = { version = "0.24.0", features = ["native-tls"] }
futures-util = "0.3.31"
async-trait = "0.1.83"

# Utilities
uuid = { version = "1.11.0", features = [
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ Full API documentation is available at [docs.rs](https://docs.rs/cbadv/latest/cb
Client: `use cbadv::{WebSocketClient, WebSocketClientBuilder}`

- **Authentication**: `client.connect`
- **Subscribe**: `client.subscribe` or `client.sub`
- **Unsubscribe**: `client.unsubscribe` or `client.unsub`
- **Subscribe**: `client.subscribe`
- **Unsubscribe**: `client.unsubscribe`
- **Listen**: `client.listen`
- **Channels Supported**:
- `Channel::STATUS`: Status
- `Channel::CANDLES`: Candles
Expand Down
24 changes: 12 additions & 12 deletions examples/account_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use std::process::exit;

use cbadv::account::AccountListQuery;
use cbadv::config::{self, BaseConfig};
use cbadv::models::account::AccountListQuery;
use cbadv::RestClientBuilder;

#[tokio::main]
Expand All @@ -21,7 +21,7 @@ async fn main() {
Err(err) => {
println!("Could not load configuration file.");
if config::exists("config.toml") {
println!("File exists, {}", err);
println!("File exists, {err}");
exit(1);
}

Expand All @@ -36,7 +36,7 @@ async fn main() {
let mut client = match RestClientBuilder::new().with_config(&config).build() {
Ok(c) => c,
Err(why) => {
eprintln!("!ERROR! {}", why);
eprintln!("!ERROR! {why}");
exit(1)
}
};
Expand All @@ -48,12 +48,12 @@ async fn main() {
.get_by_id(product_name, &AccountListQuery::new())
.await
{
Ok(account) => println!("{:#?}", account),
Err(error) => println!("Unable to get account: {}", error),
Ok(account) => println!("{account:#?}"),
Err(error) => println!("Unable to get account: {error}"),
}

// Pull accounts by ID.
let mut account_uuid = "".to_string();
let mut account_uuid = String::new();
println!("\n\nObtaining ALL accounts (non-standard).");
match client.account.get_all(&AccountListQuery::new()).await {
Ok(accounts) => {
Expand All @@ -68,7 +68,7 @@ async fn main() {
None => println!("Out of bounds, could not find account."),
}
}
Err(error) => println!("Unable to get accounts: {}", error),
Err(error) => println!("Unable to get accounts: {error}"),
}

// Parameters to send to the API.
Expand All @@ -79,17 +79,17 @@ async fn main() {
match client.account.get_bulk(&query).await {
Ok(accounts) => {
println!("Accounts obtained: {:#?}", accounts.accounts.len());
for acct in accounts.accounts.iter() {
for acct in &accounts.accounts {
println!("Account name: {}", acct.currency);
}
}
Err(error) => println!("Unable to get all accounts: {}", error),
Err(error) => println!("Unable to get all accounts: {error}"),
}

// Get a singular account based on the UUID.
println!("\n\nObtaining Account by UUID: {}", account_uuid);
println!("\n\nObtaining Account by UUID: {account_uuid}");
match client.account.get(&account_uuid).await {
Ok(account) => println!("{:#?}", account),
Err(error) => println!("Unable to get account: {}", error),
Ok(account) => println!("{account:#?}"),
Err(error) => println!("Unable to get account: {error}"),
}
}
17 changes: 8 additions & 9 deletions examples/convert_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use std::process::exit;

use cbadv::config::{self, BaseConfig};
use cbadv::convert::{ConvertQuery, ConvertQuoteRequest};
use cbadv::models::convert::{ConvertQuery, ConvertQuoteRequest};
use cbadv::RestClientBuilder;

#[tokio::main]
Expand All @@ -22,7 +22,7 @@ async fn main() {
Err(err) => {
println!("Could not load configuration file.");
if config::exists("config.toml") {
println!("File exists, {}", err);
println!("File exists, {err}");
exit(1);
}

Expand All @@ -37,34 +37,33 @@ async fn main() {
let mut client = match RestClientBuilder::new().with_config(&config).build() {
Ok(c) => c,
Err(why) => {
eprintln!("!ERROR! {}", why);
eprintln!("!ERROR! {why}");
exit(1)
}
};

// Create a quote to convert USDC to USD.
println!(
"Creating a quote to convert {} {} to {}.",
amount, from_product, to_product
"Creating a quote to convert {amount} {from_product} to {to_product}."
);
let request = ConvertQuoteRequest::new(from_product, to_product, amount);
let quote = match client.convert.create_quote(&request).await {
Ok(q) => q,
Err(why) => {
eprintln!("!ERROR! {}", why);
eprintln!("!ERROR! {why}");
exit(1)
}
};

println!("Quote created: {:#?}", quote);
println!("Quote created: {quote:#?}");
println!("\n\nObtain the quote with the quote_id: {}", quote.id);
let query = ConvertQuery::new(from_product, to_product);
match client.convert.get(&quote.id, &query).await {
Ok(q) => {
println!("Quote obtained: {:#?}", q);
println!("Quote obtained: {q:#?}");
}
Err(why) => {
eprintln!("!ERROR! {}", why);
eprintln!("!ERROR! {why}");
exit(1)
}
};
Expand Down
8 changes: 4 additions & 4 deletions examples/custom_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn main() {
Err(err) => {
println!("Could not load configuration file.");
if config::exists("config.toml") {
println!("File exists, {}", err);
println!("File exists, {err}");
exit(1);
}

Expand All @@ -69,7 +69,7 @@ async fn main() {
let mut client = match RestClientBuilder::new().with_config(&config).build() {
Ok(c) => c,
Err(why) => {
eprintln!("!ERROR! {}", why);
eprintln!("!ERROR! {why}");
exit(1)
}
};
Expand All @@ -79,9 +79,9 @@ async fn main() {
let product = match client.product.get(&config.general.product_id).await {
Ok(p) => p,
Err(err) => {
println!("{}", err);
println!("{err}");
exit(1);
}
};
println!("{:#?}\n\n", product);
println!("{product:#?}\n\n");
}
8 changes: 4 additions & 4 deletions examples/data_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async fn main() {
Err(err) => {
println!("Could not load configuration file.");
if config::exists("config.toml") {
println!("File exists, {}", err);
println!("File exists, {err}");
exit(1);
}

Expand All @@ -31,15 +31,15 @@ async fn main() {
let mut client = match RestClientBuilder::new().with_config(&config).build() {
Ok(c) => c,
Err(why) => {
eprintln!("!ERROR! {}", why);
eprintln!("!ERROR! {why}");
exit(1)
}
};

// Get the API key permissions.
println!("Obtaining Key Permissions for the API key.");
match client.data.key_permissions().await {
Ok(perm) => println!("{:#?}", perm),
Err(error) => println!("Unable to get the API key permissions: {}", error),
Ok(perm) => println!("{perm:#?}"),
Err(error) => println!("Unable to get the API key permissions: {error}"),
}
}
12 changes: 6 additions & 6 deletions examples/fee_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use std::process::exit;

use cbadv::config::{self, BaseConfig};
use cbadv::fee::FeeTransactionSummaryQuery;
use cbadv::product::ProductType;
use cbadv::models::fee::FeeTransactionSummaryQuery;
use cbadv::models::product::ProductType;
use cbadv::RestClientBuilder;

#[tokio::main]
Expand All @@ -18,7 +18,7 @@ async fn main() {
Err(err) => {
println!("Could not load configuration file.");
if config::exists("config.toml") {
println!("File exists, {}", err);
println!("File exists, {err}");
exit(1);
}

Expand All @@ -33,7 +33,7 @@ async fn main() {
let mut client = match RestClientBuilder::new().with_config(&config).build() {
Ok(c) => c,
Err(why) => {
eprintln!("!ERROR! {}", why);
eprintln!("!ERROR! {why}");
exit(1)
}
};
Expand All @@ -44,7 +44,7 @@ async fn main() {
// Get fee transaction summary.
println!("Obtaining Transaction Fee Summary");
match client.fee.get(&params).await {
Ok(summary) => println!("{:#?}", summary),
Err(error) => println!("Unable to get the Transaction Summary: {}", error),
Ok(summary) => println!("{summary:#?}"),
Err(error) => println!("Unable to get the Transaction Summary: {error}"),
}
}
Loading

0 comments on commit 8718cb3

Please sign in to comment.