Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Huobi support & major refactoring #165

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Cargo.lock
#
#already existing elements were commented out

/target
target
#Cargo.lock
.DS_store
.env
Expand Down
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ tungstenite = "0.12"
sha2 = "0.9.1"
url = "2.1.1"
derive_more = "0.99"
nash-protocol = { version = "=0.1.24", default-features = false, features = ["rustcrypto"] }
#nash-protocol = { version = "=0.1.24", default-features = false, features = ["rustcrypto"] }
nash-protocol = { path = "../nash-rust/nash-protocol", default-features = false, features = ["rustcrypto"]}
nash-native-client = { version = "=0.1.18", default-features = false, features = ["rustcrypto"] }
pyo3 = { version = "0.12.3", optional = true }
huobi = { path = "crates/huobi" }
exchange = { path = "crates/exchange" }
anyhow = "1.0.38"

#nash-protocol = { path = "../nash-rust/nash-protocol", default-features = false, features = ["rustcrypto"]}
#nash-native-client = { path = "../nash-rust/nash-native-client", default-features = false, features = ["rustcrypto"]}
10 changes: 10 additions & 0 deletions crates/cross-async/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "cross-async"
version = "0.1.0"
authors = ["Danilo Guanabara <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = "1.1.1"
10 changes: 10 additions & 0 deletions crates/cross-async/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use std::future::Future;
use tokio::task::JoinHandle;

pub fn spawn<T>(task: T) -> JoinHandle<T::Output>
where
T: Future + Send + 'static,
T::Output: Send + 'static,
{
tokio::spawn(task)
}
21 changes: 21 additions & 0 deletions crates/exchange/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "exchange"
version = "0.1.0"
authors = ["Danilo Guanabara <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-trait = "0.1"
futures = "0.3.12"
chrono = "0.4.19"
rust_decimal = "1.10.2"
serde = { version = "1.0.123", features = ["derive"] }
serde_json = "1.0.62"
thiserror = "1.0.23"
messaging = { path = "../messaging" }
derive_more = "0.99.11"
url = "2.2.0"
serde_urlencoded = "0.7.0"
anyhow = "1.0.38"
62 changes: 62 additions & 0 deletions crates/exchange/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use serde::{Deserialize, Serialize};
use std::fmt;
use thiserror::Error;

#[derive(Serialize, Deserialize, Debug, Error)]
pub struct MissingImplementationContent {
pub message: String,
}

impl fmt::Display for MissingImplementationContent {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "error message: {}", self.message)
}
}

#[derive(Error, Debug)]
pub enum Error {
#[error("")]
NoMarketPair,
#[error("")]
MissingImplementation(#[from] MissingImplementationContent),
#[error("")]
AssetNotFound(),
#[error("")]
NoApiKeySet(),
#[error("")]
InternalServerError(),
#[error("")]
ServiceUnavailable(),
#[error("")]
Unauthorized(),
#[error("")]
SymbolNotFound(),
#[error("")]
SocketError(),
#[error("")]
WebSocketMessageNotSupported(),
#[error("")]
GetTimestampFailed(),
#[error(transparent)]
InvalidPayloadSignature(#[from] serde_urlencoded::ser::Error),
#[error(transparent)]
IoError(#[from] std::io::Error),
#[error("")]
PoisonError(),
#[error(transparent)]
JsonError(#[from] serde_json::Error),
#[error(transparent)]
ParseFloatError(#[from] std::num::ParseFloatError),
#[error(transparent)]
UrlParserError(#[from] url::ParseError),
#[error(transparent)]
TimestampError(#[from] std::time::SystemTimeError),
#[error("")]
UnkownResponse(String),
#[error("")]
NotParsableResponse(String),
#[error("")]
MissingParameter(String),
#[error("")]
InvalidParameter(String),
}
15 changes: 15 additions & 0 deletions crates/exchange/src/exchange.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use messaging::Subscriber;
use async_trait::async_trait;

#[async_trait]
pub trait Exchange: Subscriber {
type InitializationParameters;

fn endpoint_url(environment: Environment) -> &'static str;
async fn new(parameters: Self::InitializationParameters) -> Result<Self, Self::Error> where Self: Sized;
}

pub enum Environment {
Production,
Sandbox
}
11 changes: 11 additions & 0 deletions crates/exchange/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mod exchange;
pub use crate::exchange::*;
pub mod market;
pub mod message;
pub mod errors;
pub mod prelude;

pub mod model;

pub type Error = String;
pub type Result<T> = std::result::Result<T, Error>;
6 changes: 6 additions & 0 deletions crates/exchange/src/market/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod symbol;

use symbol::Symbol;

#[derive(Debug, Clone)]
pub struct MarketPair(pub Symbol, pub Symbol);
7 changes: 7 additions & 0 deletions crates/exchange/src/market/symbol.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[derive(Debug, Clone)]
pub enum Symbol {
ETH,
BTC,
NEO,
USDC
}
2 changes: 2 additions & 0 deletions crates/exchange/src/message/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod request;
pub mod subscription;
11 changes: 11 additions & 0 deletions crates/exchange/src/message/request.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::message::subscription::{Subscription, SubscriptionResponse};

#[derive(Debug)]
pub enum Request {
Subscription(Subscription)
}

#[derive(Debug)]
pub enum Response {
Subscription(SubscriptionResponse)
}
14 changes: 14 additions & 0 deletions crates/exchange/src/message/subscription.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use crate::market::MarketPair;

#[derive(Debug, Clone)]
pub enum Subscription {
Tick(MarketPair)
}

#[derive(Debug, Clone)]
pub struct SubscriptionResponse {}

#[derive(Debug, Clone)]
pub enum Publication {
Tick
}
Loading