Skip to content

Commit 8cc8d51

Browse files
colmaziaRogerKSI
andauthored
[Feat] Add api and core doc (#134)
* add api doc * fix doc test * cleanup and add doc for bothan-core * fix query_id * use lowercase for command * fixed from comment --------- Co-authored-by: Kitipong Sirirueangsakul <kitipong.sirir@gmail.com>
1 parent 169c7a3 commit 8cc8d51

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+812
-32
lines changed

bothan-api/client/go-client/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package client
22

33
import proto "github.com/bandprotocol/bothan/bothan-api/client/go-client/proto/bothan/v1"
44

5+
// Client defines the interface for interacting with the Bothan API client.
6+
// It provides methods to retrieve information, update the registry, push monitoring records,
7+
// and fetch prices for given signal IDs.
58
type Client interface {
69
GetInfo() (*proto.GetInfoResponse, error)
710
UpdateRegistry(ipfsHash string, version string) error

bothan-api/client/rust-client/src/client.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,53 @@
1+
//! Bothan API Rust client module.
2+
//!
3+
//! Provides gRPC and REST client implementations.
4+
//!
5+
//! ## Components
6+
//!
7+
//! - **GrpcClient**: High-performance gRPC client for binary protocol communication
8+
//! - **RestClient**: HTTP-based REST client for JSON API interactions
9+
//!
10+
//! ## Protocol Support
11+
//!
12+
//! ### gRPC Client
13+
//!
14+
//! The gRPC client provides:
15+
//! - Binary protocol for maximum performance
16+
//! - Streaming support for real-time data
17+
//! - Strong typing with protocol buffers
18+
//! - Connection pooling and load balancing
19+
//!
20+
//! ### REST Client
21+
//!
22+
//! The REST client provides:
23+
//! - HTTP/JSON interface for easy integration
24+
//! - Standard REST conventions
25+
//! - Browser-friendly API access
26+
//! - Simple authentication and headers
27+
//!
28+
//! ## Usage Examples
29+
//!
30+
//! ```rust,no_run
31+
//! use bothan_client::client::{GrpcClient, RestClient};
32+
//!
33+
//! #[tokio::main]
34+
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
35+
//! // gRPC client
36+
//! let grpc_client = GrpcClient::connect("http://localhost:9090").await?;
37+
//!
38+
//! // REST client
39+
//! let rest_client = RestClient::new("http://localhost:8080".to_string());
40+
//!
41+
//! Ok(())
42+
//! }
43+
//! ```
44+
145
#![allow(unused_imports)]
246
#![allow(dead_code)]
47+
48+
/// gRPC client for Bothan API Server communication
349
pub use grpc::GrpcClient;
50+
/// REST client for Bothan API Server communication
451
pub use rest::RestClient;
552

653
mod grpc;

bothan-api/client/rust-client/src/client/grpc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Bothan API Rust gRPC client implementation.
2+
//!
3+
//! Provides async gRPC client for Bothan API Server.
4+
15
use std::str::FromStr;
26
use std::sync::Arc;
37

@@ -14,6 +18,7 @@ pub struct GrpcClient {
1418
client: Arc<Mutex<BothanServiceClient<Channel>>>,
1519
}
1620

21+
/// Async gRPC client for Bothan API Server.
1722
impl GrpcClient {
1823
pub fn new(client: BothanServiceClient<Channel>) -> Self {
1924
Self {

bothan-api/client/rust-client/src/client/rest.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Bothan API Rust REST client implementation.
2+
//!
3+
//! Provides async REST client for Bothan API Server.
4+
15
use reqwest::{Client, Error};
26
use url::{ParseError, Url};
37

@@ -8,6 +12,7 @@ pub struct RestClient {
812
client: Client,
913
}
1014

15+
/// Async REST client for Bothan API Server.
1116
impl RestClient {
1217
pub fn new(url: String) -> Result<Self, ParseError> {
1318
Ok(RestClient {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
//! Bothan API Rust client library root.
2+
//!
3+
//! Provides async Rust clients for the Bothan API Server (gRPC and REST), with protocol buffer bindings.
4+
15
pub mod client;
26
pub mod proto;

bothan-api/client/rust-client/src/proto.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Bothan API Rust client protocol buffer bindings.
2+
//!
3+
//! Contains generated proto code and client re-exports.
4+
15
#![allow(clippy::all)]
26
pub mod bothan {
37
pub mod v1 {

bothan-api/server-cli/src/commands.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Bothan CLI command module.
2+
//!
3+
//! Exposes submodules for all CLI subcommands: config, key, query, request, and start.
4+
15
pub mod config;
26
pub mod key;
37
pub mod query;

bothan-api/server-cli/src/commands/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Bothan CLI config subcommand module.
2+
//!
3+
//! Initialize and manage the Bothan API server configuration file.
4+
15
use std::fs::{create_dir_all, write};
26
use std::path::PathBuf;
37

@@ -9,12 +13,14 @@ use clap::{Parser, Subcommand};
913
use crate::bothan_home_dir;
1014

1115
#[derive(Parser)]
16+
/// CLI arguments for the `config` command.
1217
pub struct ConfigCli {
1318
#[command(subcommand)]
1419
subcommand: ConfigSubCommand,
1520
}
1621

1722
#[derive(Subcommand)]
23+
/// Supported config subcommands.
1824
enum ConfigSubCommand {
1925
/// Initialize the configuration file.
2026
Init {
@@ -29,6 +35,7 @@ enum ConfigSubCommand {
2935
}
3036

3137
impl ConfigCli {
38+
/// Runs the config command.
3239
pub async fn run(&self) -> anyhow::Result<()> {
3340
match &self.subcommand {
3441
ConfigSubCommand::Init { path, override_ } => {

bothan-api/server-cli/src/commands/key.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Bothan CLI key subcommand module.
2+
//!
3+
//! Generate, export, import, and display monitoring keys.
4+
15
use std::fs::{create_dir_all, read, read_to_string, write};
26

37
use anyhow::{Context, anyhow};
@@ -7,12 +11,14 @@ use clap::{Parser, Subcommand};
711
use inquire::{Password, PasswordDisplayMode};
812

913
#[derive(Parser)]
14+
/// CLI arguments for the `key` command.
1015
pub struct KeyCli {
1116
#[command(subcommand)]
1217
subcommand: KeySubCommand,
1318
}
1419

1520
#[derive(Subcommand)]
21+
/// Supported key subcommands.
1622
enum KeySubCommand {
1723
/// Generates a new monitoring key
1824
Generate {
@@ -33,6 +39,7 @@ enum KeySubCommand {
3339
}
3440

3541
impl KeyCli {
42+
/// Runs the key command.
3643
pub async fn run(&self, app_config: AppConfig) -> anyhow::Result<()> {
3744
match &self.subcommand {
3845
KeySubCommand::Generate { override_ } => generate_key(&app_config, *override_),

bothan-api/server-cli/src/commands/query.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
//! Bothan CLI query subcommand module.
2+
//!
3+
//! Query prices and asset info from supported exchanges and data sources.
4+
//!
5+
//! Supports querying prices from multiple exchanges and data sources with customizable timeout and pretty-printed output.
6+
//!
7+
//! ## Features
8+
//!
9+
//! - Query prices from Binance, Bitfinex, Bybit, Coinbase, CoinGecko, CoinMarketCap, HTX, Kraken, OKX
10+
//! - Customizable timeout and query IDs
11+
//! - Pretty-printed table output
12+
//!
13+
//! ## Usage
14+
//!
15+
//! ```bash
16+
//! bothan query binance BTCUSDT ETHUSDT
17+
//! bothan query coingecko bitcoin ethereum
18+
//! ```
19+
120
use std::collections::{HashMap, HashSet};
221
use std::error::Error;
322
use std::sync::Arc;
@@ -20,12 +39,14 @@ use tokio::time::timeout;
2039
const DEFAULT_TIMEOUT: &str = "10s";
2140

2241
#[derive(Parser)]
42+
/// CLI arguments for the `query` command.
2343
pub struct QueryCli {
2444
#[command(subcommand)]
2545
subcommand: QuerySubCommand,
2646
}
2747

2848
#[derive(Args, Debug, Clone)]
49+
/// Arguments for querying prices.
2950
pub struct QueryArgs {
3051
/// The list of query ids to query prices for
3152
pub query_ids: Vec<String>,
@@ -34,50 +55,59 @@ pub struct QueryArgs {
3455
#[arg(short, long, default_value = DEFAULT_TIMEOUT)]
3556
pub timeout: HumanDuration,
3657
}
37-
3858
#[derive(Subcommand, Debug)]
59+
/// Supported query subcommands for each exchange or data source.
3960
pub enum QuerySubCommand {
4061
/// Query Binance prices
62+
#[clap(name = "binance")]
4163
Binance {
4264
#[clap(flatten)]
4365
args: QueryArgs,
4466
},
4567
/// Query Bitfinex prices
68+
#[clap(name = "bitfinex")]
4669
Bitfinex {
4770
#[clap(flatten)]
4871
args: QueryArgs,
4972
},
5073
/// Query Bybit prices
74+
#[clap(name = "bybit")]
5175
Bybit {
5276
#[clap(flatten)]
5377
args: QueryArgs,
5478
},
5579
/// Query Coinbase prices
80+
#[clap(name = "coinbase")]
5681
Coinbase {
5782
#[clap(flatten)]
5883
args: QueryArgs,
5984
},
6085
/// Query CoinGecko prices
86+
#[clap(name = "coingecko")]
6187
CoinGecko {
6288
#[clap(flatten)]
6389
args: QueryArgs,
6490
},
6591
/// Query CoinMarketCap prices
92+
#[clap(name = "coinmarketcap")]
6693
CoinMarketCap {
6794
#[clap(flatten)]
6895
args: QueryArgs,
6996
},
7097
/// Query HTX prices
98+
#[clap(name = "htx")]
7199
Htx {
72100
#[clap(flatten)]
73101
args: QueryArgs,
74102
},
75103
/// Query Kraken prices
104+
#[clap(name = "kraken")]
76105
Kraken {
77106
#[clap(flatten)]
78107
args: QueryArgs,
79108
},
80109
/// Query OKX prices
110+
#[clap(name = "okx")]
81111
Okx {
82112
#[clap(flatten)]
83113
args: QueryArgs,

0 commit comments

Comments
 (0)