Skip to content

Commit

Permalink
0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
negi-grass committed Dec 26, 2022
1 parent 14749fc commit 030f775
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 42 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

43 changes: 40 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ default-members = ["generic-api-client", "crypto-botters-binance", "crypto-botte

[package]
name = "crypto-botters"
version = "0.1.1"
version = "0.2.0"
authors = ["negi_grass"]
edition = "2021"
description = "A crate for interacting with various cryptocurrency exchanges."
Expand All @@ -15,6 +15,7 @@ documentation = "https://docs.rs/crypto-botters"
repository = "https://github.com/negi-grass/crypto-botters"
keywords = ["cryptocurrency", "finance", "trading", "client", "websocket"]
categories = ["api-bindings", "asynchronous", "cryptography::cryptocurrencies", "authentication"]
autoexamples = false

[package.metadata.docs.rs]
all-features = true
Expand All @@ -26,8 +27,8 @@ bitflyer = ["dep:crypto-botters-bitflyer"]

[dependencies]
generic-api-client = { version = "0.1", path = "generic-api-client" }
crypto-botters-binance = { version = "0.1", path = "crypto-botters-binance", optional = true }
crypto-botters-bitflyer = { version = "0.1", path = "crypto-botters-bitflyer", optional = true }
crypto-botters-binance = { version = "0.2", path = "crypto-botters-binance", optional = true }
crypto-botters-bitflyer = { version = "0.2", path = "crypto-botters-bitflyer", optional = true }

[dev-dependencies]
crypto-botters = { path = ".", features = ["full"] }
Expand All @@ -37,3 +38,39 @@ serde_json = "1.0.90"
rust_decimal = { version = "1.27.0", features = ["serde-with-str", "serde-with-float"] }
env_logger = "0.10.0"
log = "0.4.17"

[[example]]
name = "binance_http_private"
path = "examples/binance/binance_http_private.rs"

[[example]]
name = "binance_http_public"
path = "examples/binance/binance_http_public.rs"

[[example]]
name = "binance_websocket_private"
path = "examples/binance/binance_websocket_private.rs"

[[example]]
name = "binance_websocket_public"
path = "examples/binance/binance_websocket_public.rs"

[[example]]
name = "binance_spawn"
path = "examples/binance/binance_spawn.rs"

[[example]]
name = "bitflyer_http_private"
path = "examples/bitflyer/bitflyer_http_private.rs"

[[example]]
name = "bitflyer_http_public"
path = "examples/bitflyer/bitflyer_http_public.rs"

[[example]]
name = "bitflyer_websocket_private"
path = "examples/bitflyer/bitflyer_websocket_private.rs"

[[example]]
name = "bitflyer_websocket_public"
path = "examples/bitflyer/bitflyer_websocket_public.rs"
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# crypto-botters
仮想通貨取引所のAPIと通信するためのライブラリです
仮想通貨取引所のAPIと通信するためのRustライブラリです

[crates.io](https://crates.io/crates/crypto-botters)

Expand All @@ -10,23 +10,20 @@
Cargo.toml:
```
[dependencies]
crypto-botters = { version = "0.1", features = ["binance", "bitflyer"] }
crypto-botters = { version = "0.2", features = ["binance", "bitflyer"] }
```

## 対応API
以下のAPIは最新バージョンで対応しています。

- [Binance](https://www.binance.com/en)
- [Spot/Margin/Savings/Mining](https://binance-docs.github.io/apidocs/spot/en/)
- [USDⓈ-M Futures](https://binance-docs.github.io/apidocs/futures/en/)
- [COIN-M Futures](https://binance-docs.github.io/apidocs/delivery/en/)
- [European Options](https://binance-docs.github.io/apidocs/voptions/en/)
- [WebSocket API](https://binance-docs.github.io/apidocs/websocket_api/en/)
- [bitFlyer](https://bitflyer.com)
- [HTTP API](https://lightning.bitflyer.com/docs)
- [Realtime API](https://bf-lightning-api.readme.io/docs) (Socket.IO は非対応)

以下のAPIは次のバージョンで対応する予定です。

- [Binance](https://www.binance.com/en)
- [European Options](https://binance-docs.github.io/apidocs/voptions/en/)
- [Bybit](https://www.bybit.com)
2 changes: 1 addition & 1 deletion crypto-botters-binance/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "crypto-botters-binance"
version = "0.1.1"
version = "0.2.0"
authors = ["negi_grass"]
edition = "2021"
description = "A crate for interacting with the Binance API."
Expand Down
56 changes: 31 additions & 25 deletions crypto-botters-binance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize};
use generic_api_client::{http::*, websocket::*};

/// The type returned by [Client::request()].
pub type RequestResult<T> = Result<T, RequestError<&'static str, BinanceHandlerError>>;
pub type BinanceRequestResult<T> = Result<T, RequestError<&'static str, BinanceHandlerError>>;

/// A `struct` that provides the [generic_api_client]'s handlers.
#[derive(Clone)]
Expand Down Expand Up @@ -52,6 +52,8 @@ pub enum BinanceHttpUrl {
FuturesCoinM,
/// https://testnet.binancefuture.com
FuturesTest,
/// https://eapi.binance.com
EuropeanOptions,
/// The url will not be modified by [BinanceRequestHandler]
None,
}
Expand Down Expand Up @@ -82,6 +84,8 @@ pub enum BinanceWebSocketUrl {
FuturesUsdMTest,
/// wss://dstream.binancefuture.com
FuturesCoinMTest,
/// wss://nbstream.binance.com
EuropeanOptions,
/// The url will not be modified by [BinanceRequestHandler]
None,
}
Expand All @@ -107,7 +111,7 @@ pub struct BinanceRequestHandler<'a, R: DeserializeOwned> {
security: BinanceSecurity,
base_url: BinanceHttpUrl,
max_try: u8,
_phantom: PhantomData<*const R>,
_phantom: PhantomData<&'a R>,
}

pub struct BinanceWebSocketHandler<H: FnMut(serde_json::Value) + Send + 'static> {
Expand Down Expand Up @@ -142,7 +146,7 @@ impl Binance {
security,
base_url,
max_try: self.request_max_try,
_phantom: PhantomData::default(),
_phantom: PhantomData,
}
}

Expand Down Expand Up @@ -303,35 +307,37 @@ impl BinanceHttpUrl {
/// The string that this variant represents.
pub fn to_str(&self) -> &'static str {
match self {
BinanceHttpUrl::Spot => "https://api.binance.com",
BinanceHttpUrl::Spot1 => "https://api1.binance.com",
BinanceHttpUrl::Spot2 => "https://api2.binance.com",
BinanceHttpUrl::Spot3 => "https://api3.binance.com",
BinanceHttpUrl::SpotTest => "https://testnet.binance.vision",
BinanceHttpUrl::SpotData => "https://data.binance.com",
BinanceHttpUrl::FuturesUsdM => "https://fapi.binance.com",
BinanceHttpUrl::FuturesCoinM => "https://dapi.binance.com",
BinanceHttpUrl::FuturesTest => "https://testnet.binancefuture.com",
BinanceHttpUrl::None => "",
Self::Spot => "https://api.binance.com",
Self::Spot1 => "https://api1.binance.com",
Self::Spot2 => "https://api2.binance.com",
Self::Spot3 => "https://api3.binance.com",
Self::SpotTest => "https://testnet.binance.vision",
Self::SpotData => "https://data.binance.com",
Self::FuturesUsdM => "https://fapi.binance.com",
Self::FuturesCoinM => "https://dapi.binance.com",
Self::FuturesTest => "https://testnet.binancefuture.com",
Self::EuropeanOptions => "https://eapi.binance.com",
Self::None => "",
}
}
}

impl BinanceWebSocketUrl {
pub fn to_str(&self) -> &'static str {
match self {
BinanceWebSocketUrl::Spot9443 => "wss://stream.binance.com:9443",
BinanceWebSocketUrl::Spot443 => "wss://stream.binance.com:443",
BinanceWebSocketUrl::SpotTest => "wss://testnet.binance.vision",
BinanceWebSocketUrl::SpotData => "wss://data-stream.binance.com",
BinanceWebSocketUrl::WebSocket443 => "wss://ws-api.binance.com:443",
BinanceWebSocketUrl::WebSocket9443 => "wss://ws-api.binance.com:9443",
BinanceWebSocketUrl::FuturesUsdM => "wss://fstream.binance.com",
BinanceWebSocketUrl::FuturesUsdMAuth => "wss://fstream-auth.binance.com",
BinanceWebSocketUrl::FuturesCoinM => "wss://dstream.binance.com",
BinanceWebSocketUrl::FuturesUsdMTest => "wss://stream.binancefuture.com",
BinanceWebSocketUrl::FuturesCoinMTest => "wss://dstream.binancefuture.com",
BinanceWebSocketUrl::None => "",
Self::Spot9443 => "wss://stream.binance.com:9443",
Self::Spot443 => "wss://stream.binance.com:443",
Self::SpotTest => "wss://testnet.binance.vision",
Self::SpotData => "wss://data-stream.binance.com",
Self::WebSocket443 => "wss://ws-api.binance.com:443",
Self::WebSocket9443 => "wss://ws-api.binance.com:9443",
Self::FuturesUsdM => "wss://fstream.binance.com",
Self::FuturesUsdMAuth => "wss://fstream-auth.binance.com",
Self::FuturesCoinM => "wss://dstream.binance.com",
Self::FuturesUsdMTest => "wss://stream.binancefuture.com",
Self::FuturesCoinMTest => "wss://dstream.binancefuture.com",
Self::EuropeanOptions => "wss://nbstream.binance.com",
Self::None => "",
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crypto-botters-bitflyer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "crypto-botters-bitflyer"
version = "0.1.1"
version = "0.2.0"
authors = ["negi_grass"]
edition = "2021"
description = "A crate for interacting with the bitFlyer API."
Expand Down
6 changes: 3 additions & 3 deletions crypto-botters-bitflyer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use generic_api_client::{http::*, websocket::*};
use generic_api_client::http::header::HeaderValue;

/// The type returned by [Client::request()].
pub type RequestResult<T> = Result<T, RequestError<&'static str, BitFlyerHandlerError>>;
pub type BitFlyerRequestResult<T> = Result<T, RequestError<&'static str, BitFlyerHandlerError>>;

/// A `struct` that provides the [generic_api_client]'s handlers.
#[derive(Clone)]
Expand Down Expand Up @@ -56,7 +56,7 @@ pub struct BitFlyerRequestHandler<'a, R: DeserializeOwned> {
api_secret: Option<&'a str>,
security: BitflyerSecurity,
max_try: u8,
_phantom: PhantomData<*const R>,
_phantom: PhantomData<&'a R>,
}

pub struct BitFlyerWebSocketHandler<H: FnMut(BitFlyerChannelMessage) + Send + 'static> {
Expand Down Expand Up @@ -88,7 +88,7 @@ impl BitFlyer {
api_secret: self.api_secret.as_deref(),
security,
max_try: self.request_max_try,
_phantom: PhantomData::default(),
_phantom: PhantomData,
}
}

Expand Down
File renamed without changes.
File renamed without changes.
44 changes: 44 additions & 0 deletions examples/binance/binance_spawn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use log::LevelFilter;
use serde_json::json;
use crypto_botters::{
http::Client,
binance::{Binance, BinanceSecurity, BinanceRequestResult},
};

struct Api {
binance: Binance,
client: Client,
}

impl Api {
fn new() -> Self {
Self {
binance: Binance::new(None, None),
client: Client::new(),
}
}

async fn get_orderbook(&self) -> BinanceRequestResult<serde_json::Value> {
self.client.get(
"https://api.binance.com/api/v3/ticker/bookTicker",
Some(&json!({ "symbol": "BTCUSDT" })),
&self.binance.request_no_url(BinanceSecurity::None),
).await
}
}

#[tokio::main]
async fn main() {
env_logger::builder()
.filter_level(LevelFilter::Debug)
.init();

let api = Api::new();
let handle = tokio::spawn(async move {
log::info!("in async block");
let orderbook = api.get_orderbook().await;
println!("{:?}", orderbook);
});
let result = handle.await;
println!("{:?}", result);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 030f775

Please sign in to comment.