Giter Club home page Giter Club logo

bybit_rs's Introduction

Fork of pybit python libary in Rust

For the rust lovers and creators for bybit exchange version 5

Official Python3 API connector for Bybit's HTTP and WebSockets APIs.

Table of Contents

About

Put simply, bybit-rs (Bybit + Rust) is the fork of the python (pybit library) official lightweight one-stop-shop module for the Bybit HTTP and WebSocket APIs. Originally created by Verata Veritatis, it's now maintained by Omambia Dauglous & Dennis Mwangi โ€“ however, you're still welcome to contribute!

It was designed with the following vision in mind:

I was personally never a fan of auto-generated connectors that used a mosh-pit of various modules you didn't want (sorry, bravado) and wanted to build my own Python3-dedicated connector with very little external resources. The goal of the connector is to provide traders and developers with an easy-to-use high-performing module that has an active issue and discussion board leading to consistent improvements.

Development

bybit-rs is being actively developed, and new Bybit API changes should arrive on bybit-rs very quickly. pybit uses reqwest and websocket for its methods, alongside other built-in modules. Anyone is welcome to branch/fork the repository and add their own upgrades. If you think you've made substantial improvements to the module, submit a pull request and we'll gladly take a look.

Installation

bybit requires Python 3.9.1 or higher. The module can be installed manually or via PyPI with pip:

cargo add bybit-rs

Usage

You can retrieve a specific market like so:

use std::{
    collections::{BTreeMap, HashMap},
    sync::Arc,
};

use bybit::{
    asset::{self, Asset},
    http_manager::{HttpManager, Manager},
    market::{self, Market},
    trade::{self, Trade},
};

Create an HTTP session and connect via WebSocket for Inverse on mainnet:

let http_api_key =""
let http_api_secret =""

let testnet = ""

let manager = Arc::new(HttpManager::new(http_api_key, http_api_secret, testnet));

Get Market Kline Data

let mut query: HashMap<String, String> = HashMap::new();
query.insert("category".to_string(), "inverse".to_string());
query.insert("symbol".to_string(), "BTCUSD".to_string());
query.insert("interval".to_string(), "60".to_string());
query.insert("start".to_string(), "1670601600000".to_string());
query.insert("end".to_string(), "1670608800000".to_string());

// market object
let market: market::MarketHTTP = market::MarketHTTP::new(manager.clone());

match market.get_kline(query).await {
    Ok(result) => println!("{:?}", result),
    Err(e) => println!("{:?}", e),
}

Place and Order

let mut query: HashMap<String, String> = HashMap::new();
query.insert("category".to_owned(), "linear".to_owned());
query.insert("symbol".to_owned(), "BTCUSDT".to_owned());
query.insert("orderType".to_owned(), "Limit".to_owned());
query.insert("qty".to_owned(), "0.06".to_owned());
query.insert("price".to_owned(), "25000".to_owned());
query.insert("side".to_owned(), "Buy".to_owned());

let trade: trade::TradeHTTP = trade::TradeHTTP::new(manager.clone());

match trade.place_order(query).await {
    Ok(result) => println!("{:?}", result),
    Err(e) => println!("{:?}", e),
}

Get Single Order

let mut query: HashMap<String, String> = HashMap::new();
query.insert("category".to_owned(), "linear".to_owned());
query.insert("limit".to_owned(), "1".to_owned());
query.insert("symbol".to_owned(), "BTCUSDT".to_owned());
query.insert("openOnly".to_owned(), "0".to_owned());

match trade.get_open_orders(query).await {
    Ok(result) => println!("{:?}", result),
    Err(e) => println!("{:?}", e),
}

Cancel a Single

let mut query: HashMap<String, String> = HashMap::new();
query.insert("category".to_owned(), "linear".to_owned());
query.insert(
    "orderId".to_owned(),
    "3380b972-a334-4d00-87e9-3423fa27602f".to_owned(),
);
query.insert("symbol".to_owned(), "BTCUSDT".to_owned());
query.insert("settleCoin".to_owned(), "USDT".to_owned());

match trade.cancel_order(query).await {
    Ok(result) => println!("{:?}", result),
    Err(e) => println!("{:?}", e),
}
```

### Cancel All Orders

```rust
let mut query: HashMap<String, String> = HashMap::new();
query.insert("category".to_owned(), "linear".to_owned());
query.insert("symbol".to_owned(), "".to_owned());
query.insert("settleCoin".to_owned(), "USDT".to_owned());

match trade.cancel_all_orders(query).await {
    Ok(result) => println!("{:?}", result),
    Err(e) => println!("{:?}", e),
}

Check out the example rust files or the list of endpoints below for more information on available endpoints and methods. Usage examples on the libary Manager methods can be found in the examples folder.

Contact

You can reach out for support on the Ngeni Labs Support Telegram group chat.

Credits

Thanks goes to these wonderful contritors of pybit libary official commutity library & NGENI LABs github team for your technical support

Donations

If you find this libary useful, donate to

USDT

1. TRC20 TVGdWAZ3MetiRyUhkR4CjR7YFi99TQvZ2L
2. ERC20: 0x43bFd041eB6F6ccdC247B4162EB7D056B4bF97BA

BTC: bc1q8mcktjuwh9ufy7tcz4ep7u5uhef3z2m8qdnurs ETH:0x43bFd041eB6F6ccdC247B4162EB7D056B4bF97BA

bybit_rs's People

Contributors

0xca11 avatar dennis-codes avatar domambia avatar muathendirangu avatar umbertov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bybit_rs's Issues

get_wallet_balance -> failed to lookup address information: nodename nor servname provided, or not known

When I call account.get_wallet_balance(query) this throw a error.

"Error: reqwest::Error { kind: Request, url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("api.bybit.comf")), port: None, path: "/", query: Some("accountType=unified"), fragment: None }, source: hyper::Error(Connect, ConnectError("dns error", Custom { kind: Uncategorized, error: "failed to lookup address information: nodename nor servname provided, or not known" })) }"

Because here in Account::GetWalletBalance it's just "f" instead of "/v5/account/wallet-balance" supposed

impl std::fmt::Display for Account {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Account::GetWalletBalance => write!(f, "f"),
Account::UpgradeToUnifiedAccount => write!(f, "/v5/account/upgrade-to-uta"),
Account::GetBorrowHistory => write!(f, "/v5/account/borrow-history"),
Account::GetCollateralInfo => write!(f, "/v5/account/collateral-info"),
Account::GetCoinGreeks => write!(f, "/v5/asset/coin-greeks"),
Account::GetFeeRate => write!(f, "/v5/account/fee-rate"),
Account::GetAccountInfo => write!(f, "/v5/account/info"),
Account::GetTransactionLog => write!(f, "/v5/account/transaction-log"),
Account::SetMarginMode => write!(f, "/v5/account/set-margin-mode"),
Account::SetMMP => write!(f, "/v5/account/mmp-modify"),
Account::ResetMMP => write!(f, "/v5/account/mmp-reset"),
Account::GetMMPState => write!(f, "/v5/account/mmp-state"),
}
}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.