Fork of the Official Python3 API connector for Bybit's HTTP (bybit) and WebSockets APIs to rust

Overview

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

You might also like...
Small microservice to render Lottie animation files via an http REST API.

Lottie Renderer Service Small microservice to render Lottie animation files via an http REST API. Run via docker docker run -p 8080:8080 ghcr.io/mikbo

SvelteUI Official CLI written in Rust

SvelteUI Official CLI The cli will be written in Rust 🦀 . This CLI as of now (04/30/22) will be used for scaffolding new projects, and creating boile

Yfin is the Official package manager for the Y-flat programming language
Yfin is the Official package manager for the Y-flat programming language

Yfin is the Official package manager for the Y-flat programming language. Yfin allows the user to install, upgrade, and uninstall packages. It also allows a user to initialize a package with the Y-flat package structure and files automatically generated. In future, Yfin will also allow users to publish packages.

Official repository for v3's backend

RoChat This repository holds the official source code for RoChat's new backend. Previously, the old backend was written in PHP. The newer one, coming

This tool will profile official instances of OpenSUSE mirrorcache to determine the fastest repositories for your system

Mirror Magic tool to Magically make OpenSUSE Mirrors Magic-er This tool will profile official instances of OpenSUSE mirrorcache to determine the faste

The official command-line interface for the makedeb Package Repository

mpr-cli This is the repository for the MPR CLI, the official command-line interface for the makedeb Package Repository. Installation Users have a few

this-week-in-neovim.org official webapp repository

This Week In Neovim This repository holds the source code of https://this-week-in-neovim.org. Architecture How does it run in production Automatic upd

The official documentation for Njord.
The official documentation for Njord.

Docs The docs for Njord using mdBook. Not being used yet, will update this later. We refer to the API docs for now and examples. Contributors The foll

Api testing tool made with rust to use for api developement (Kind of Tui)
Api testing tool made with rust to use for api developement (Kind of Tui)

Api testing tool made with rust to use for api developement (Kind of Tui) This Rust project provides a simple yet powerful tool for making HTTP reques

Owner
Omambia Dauglous
Dauglous is a FinTech & Blockchain enthusiast and holds an excellent in understanding DeFi, Markets Trading, DevOps, and software Development in general.
Omambia Dauglous
REC2 (Rusty External Command and Control) is client and server tool allowing auditor to execute command from VirusTotal and Mastodon APIs written in Rust. 🦀

Information: REC2 is an old personal project (early 2023) that I didn't continue development on. It's part of a list of projects that helped me to lea

Quentin Texier (g0h4n) 104 Oct 7, 2023
A fork of V8Js re-implemented in Rust

PHP-V8Js PHP-V8Js is a PHP extension for the V8 JavaScript engine. It is a re-implementation of the fantastic (though unmaintained) V8Js PHP extension

Joe Hoyle 13 Jan 2, 2023
A community fork of a language named after a plant fungus

A community fork of a language named after a plant fungus. All of the memory-safe features you love, now with 100% less bureaucracy!

null 1.9k Apr 20, 2023
A fork of criterion.rs to keep things afloat.

Criterion.rs Statistics-driven Microbenchmarking in Rust Getting Started | User Guide | Master API Docs | Released API Docs | Changelog | Criterion.rs

Boshen 5 May 7, 2024
Rust library for integrating local LLMs (with llama.cpp) and external LLM APIs.

Table of Contents About The Project Getting Started Roadmap Contributing License Contact A rust interface for the OpenAI API and Llama.cpp ./server AP

Shelby Jenkins 4 Dec 18, 2023
A safe and idiomatic wrapper over shared memory APIs in rust with proper cleanups.

shmem-bind A safe and idiomatic wrapper over shared memory APIs in rust with proper cleanups. Quick start: check the message-passing example for bette

ArshiA Akhavan 3 Apr 6, 2024
Crates.io library that provides high-level APIs for obtaining information on various entertainment media such as books, movies, comic books, anime, manga, and so on.

Crates.io library that provides high-level APIs for obtaining information on various entertainment media such as books, movies, comic books, anime, manga, and so on.

consumet-rs 5 Aug 13, 2023
Prototype for a CLI/Libary designed for interacting with NASA Open APIs with Rust.

Overview Voyager is a swiss army knife library for the NASA Open APIs. It is designed to bundle all the NASA APIs into a single package. Voyager can b

Ethan Gallucci 4 Aug 14, 2022
The official CLI for FlakeHub: search for flakes, and add new inputs to your Nix flake.

fh, the official FlakeHub CLI fh is a scrappy CLI for searching FlakeHub and adding new inputs to your Nix flakes. Usage Using fh from FlakeHub: nix s

Determinate Systems 35 Oct 11, 2023
excss is a small, simple, zero-runtime CSS-in-JS library with just two APIs.

excss excss is a small, simple, zero-runtime CSS-in-JS library with just two APIs.

Taishi Naritomi 12 Sep 12, 2023