Skip to content

Commit

Permalink
feat: first commmit 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkersner committed Oct 20, 2024
0 parents commit 63b1905
Show file tree
Hide file tree
Showing 17 changed files with 1,598 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATAMAXI_API_KEY=
45 changes: 45 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Publish Documentation

on:
push:
branches: [main]

workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Rust
uses: dtolnay/rust-toolchain@stable

- name: Configure cache
uses: Swatinem/rust-cache@v2

- name: Setup pages
id: pages
uses: actions/configure-pages@v4

- name: Clean docs folder
run: cargo clean --doc

- name: Build docs
run: cargo doc --no-deps

- name: Add redirect
run: echo '<meta http-equiv="refresh" content="0;url=datamaxi/index.html">' > target/doc/index.html

- name: Remove lock file
run: rm target/doc/.lock

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./target/doc
publish_branch: gh-pages
allow_empty_commit: true
38 changes: 38 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Rust

on:
push:
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: clippy
- run: cargo clippy --all-targets

fmt:
name: format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
profile: minimal
components: rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/target
src/main.rs

Cargo.lock
.env
19 changes: 19 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "datamaxi"
version = "0.1.0"
edition = "2021"
readme = "README.md"
license = "MIT"

[dependencies]
dotenv = "0.15.0"
api = "0.2.0"
error-chain = "0.12.4"
reqwest = { version = "0.12.7", features = ["blocking", "json"] }
serde = { version = "1.0.209", features = ["derive"] }
serde_json = "1.0.127"
tungstenite = "0.24.0"
url = "2.5.2"

[dev-dependencies]
mockito = "1.5.0"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Bisonai

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
120 changes: 120 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
## DataMaxi+ Rust SDK

This is the official implementation of Rust SDK for [DataMaxi+](https://datamaxiplus.com/).
The package can be used to fetch both historical and latest data using [DataMaxi+ API](https://docs.datamaxiplus.com/).

- [Installation](#installation)
- [Configuration](#configuration)
- [Links](#links)
- [Contributing](#contributing)
- [License](#license)

### Installation

```shell
[dependencies]
datamaxi = { git = "https://github.com/bisonai/datamaxi-rust.git" }
```
### Configuration
Private API endpoints are protected by an API key.
You can get the API key upon registering at <https://datamaxiplus.com/auth>.
| Option | Explanation |
|------------|-------------------------------------------------------------------------------|
| `api_key` | Your API key |
| `base_url` | If `base_url` is not provided, it defaults to `https://api.datamaxiplus.com`. |
### Examples
#### CEX Candle
```rust
let api_key = "my_api_key".to_string();
let candle: datamaxi::cex::Candle = datamaxi::api::Datamaxi::new(api_key);

// Fetch supported exchanges for CEX candle data
candle.exchanges("spot");

// Fetch supported symbols for CEX candle data
let symbols_options = datamaxi::cex::SymbolsOptions::new();
candle.symbols("binance", symbols_options);

// Fetch supported intervals for CEX candle data
candle.intervals();

// Fetch CEX candle data
let candle_options = datamaxi::cex::CandleOptions::new();
candle.get("binance", "ETH-USDT", candle_options);
```
#### DEX Candle
```rust
let api_key = "my_api_key".to_string();
let candle: datamaxi::dex::Candle = datamaxi::api::Datamaxi::new(api_key);

// Fetch supported intervals for DEX candle data
candle.intervals();

// Fetch supported exchange for DEX candle data
candle.exchanges();

// Fetch supported chains for DEX candle data
candle.chains();

// Fetch supported pools for DEX candle data
let pools_options = datamaxi::dex::PoolsOptions::new();
candle.pools(pools_options);

// Fetch DEX candle data
let params = datamaxi::dex::CandleOptions::new();
candle.get(
"bsc_mainnet",
"pancakeswap",
"0xb24cd29e32FaCDDf9e73831d5cD1FFcd1e535423",
params,
);
```
#### DEX Trade
```rust
let api_key = "my_api_key".to_string();
let trade: datamaxi::dex::Trade = datamaxi::api::Datamaxi::new(api_key);

// Fetch supported exchange for DEX trade data
trade.exchanges();

// Fetch supported chains for DEX trade data
trade.chains();

// Fetch supported pools for DEX trade data
let pools_options = datamaxi::dex::PoolsOptions::new();
trade.pools(pools_options);

// Fetch DEX candle data
let trade_options = datamaxi::dex::TradeOptions::new().limit(5);
trade.get(
"bsc_mainnet",
"pancakeswap",
"0xb24cd29e32FaCDDf9e73831d5cD1FFcd1e535423",
trade_options
);
```
### Links
- [Official Website](https://datamaxiplus.com/)
- [Documentation](https://docs.datamaxiplus.com/)
### Contributing
We welcome contributions!
If you discover a bug in this project, please feel free to open an issue to discuss the changes you would like to propose.
### License
[MIT License](./LICENSE)
1 change: 1 addition & 0 deletions README.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{readme}}
22 changes: 22 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# DataMaxi+ Examples

All examples load `DATAMAXI_API_KEY` environment variable to authenticate with the DataMaxi+ API.
Setup your environment variable with your API key in `.env` file before running the examples.

## CEX Candle

```bash
cargo run --release -q --example "cex-candle"
```

## DEX Trade

```bash
cargo run --release -q --example "dex-trade"
```

## DEX Candle

```bash
cargo run --release -q --example "dex-candle"
```
41 changes: 41 additions & 0 deletions examples/cex-candle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use std::env;

fn main() {
dotenv::dotenv().ok();
let api_key = env::var("DATAMAXI_API_KEY").expect("DATAMAXI_API_KEY not found");
let candle: datamaxi::cex::Candle = datamaxi::api::Datamaxi::new(api_key);

// CEX Candle Exchanges
match candle.exchanges("futures") {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

// CEX Candle Symbols
let symbols_options = datamaxi::cex::SymbolsOptions::new();
let symbols_response = candle.symbols("binance", symbols_options);
match symbols_response {
Ok(answer) => match serde_json::to_string(&answer) {
Ok(json) => println!("{}", json),
Err(e) => println!("Error: {}", e),
},
Err(e) => println!("Error: {}", e),
}

// CEX Candle Intervals
match candle.intervals() {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

// CEX Candle Data
let candle_options = datamaxi::cex::CandleOptions::new();
let candle_response = candle.get("binance", "ETH-USDT", candle_options);
match candle_response {
Ok(answer) => match serde_json::to_string(&answer) {
Ok(json) => println!("{}", json),
Err(e) => println!("Error: {}", e),
},
Err(e) => println!("Error: {}", e),
}
}
52 changes: 52 additions & 0 deletions examples/dex-candle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use std::env;

fn main() {
dotenv::dotenv().ok();
let api_key = env::var("DATAMAXI_API_KEY").expect("DATAMAXI_API_KEY not found");
let candle: datamaxi::dex::Candle = datamaxi::api::Datamaxi::new(api_key);

// DEX Candle Intervals
match candle.intervals() {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

// DEX Candle Exchanges
match candle.exchanges() {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

// DEX Candle Chains
match candle.chains() {
Ok(answer) => println!("{:?}", answer),
Err(e) => println!("Error: {}", e),
}

// DEX Candle Pools
let pools_options = datamaxi::dex::PoolsOptions::new();
let pools_response = candle.pools(pools_options);
match pools_response {
Ok(answer) => match serde_json::to_string(&answer) {
Ok(json) => println!("{}", json),
Err(e) => println!("Error: {}", e),
},
Err(e) => println!("Error: {}", e),
}

// DEX Candle Data
let params = datamaxi::dex::CandleOptions::new();
let candle_response = candle.get(
"bsc_mainnet",
"pancakeswap",
"0xb24cd29e32FaCDDf9e73831d5cD1FFcd1e535423",
params,
);
match candle_response {
Ok(answer) => match serde_json::to_string(&answer) {
Ok(json) => println!("{}", json),
Err(e) => println!("Error: {}", e),
},
Err(e) => println!("Error: {}", e),
}
}
Loading

0 comments on commit 63b1905

Please sign in to comment.