Giter Club home page Giter Club logo

bybit-rs's Introduction

Contributor Covenant

Bybit-rs

Unofficial API connector for the Bybit API.

Disclaimer

This software is for educational purposes only. Do not risk money which you are afraid to lose. USE THE SOFTWARE AT YOUR OWN RISK. THE AUTHORS AND ALL AFFILIATES ASSUME NO RESPONSIBILITY FOR YOUR TRADING RESULTS.

Installation

Add the following dependency to your Cargo.toml

[dependencies.bybit]
git = "https://github.com/wassup-/bybit-rs.git"

Usage

use bybit::{
    http::{self, Client, Result},
    rest::{self, *},
    Order, OrderType, Side, TimeInForce,
};

async fn create_order() -> Result<Order> {
    // safe to unwrap because we know the url is valid
    let client = Client::new(http::MAINNET_BYBIT, "api key", "api secret").unwrap();
    let data = rest::PlaceActiveOrderData {
        symbol: "BTCUSD".to_string(),
        side: Side::Sell,
        qty: 10.0,
        order_type: OrderType::Limit,
        price: Some(45420.0),
        time_in_force: TimeInForce::PostOnly,
        ..Default::default()
    };
    client.place_active_order(data).await
}

Status

bybit-rs is still under active development. This means that until this library reaches version 1.0.0, things are prone to break and/or change. We're doing our best to quickly implement most of the API functionality provided by Bybit, however not all of the functionality may have been properly tested yet. Please do not hesitate to open an issue if you run into any problems, errors, ... (see Contributing).

Endpoints / Features

HTTP

Market Data Endpoints
  • order book
  • query kline
  • latest information for symbol (tickers)
  • public trading records
  • query symbol
  • query mark price kline
  • query index price kline
  • query premium index kline
  • advanced data
Account Data Endpoints
  • place active order
  • place active linear order
  • get active order
  • cancel active order
  • cancel all active orders
  • replace active order (incomplete)
  • query active order (real-time)
  • place conditional order
  • place conditional linear order
  • position
  • risk limit
  • funding
  • API key info
  • LCP info
Wallet Data Endpoints
  • get wallet balance
  • wallet fund records
  • withdraw records
  • asset exchange records
API Data Endpoints
  • server time
  • announcement

WebSocket

Public Topics
  • orderbook snapshot
  • orderbook delta
  • trade
  • insurance
  • instrument info snapshot
  • instrument info delta
  • kline v2
  • liquidation
Private Topics
  • position
  • execution
  • order
  • stop order

Contributing

To get involved, take a look at CONTRIBUTING.

License

This library is provided under the MIT license. See LICENSE.

Support the author of this library.

If bybit-rs made your life easier, please consider making a donation.

  • BTC 1NCLMTd4Zh6hcWxnVk9emfgyyRabEACy1m
  • ETH 0xab3e024d41b6e9eb6b03bd56de9fdf077c904ef9
  • EOS bybitdeposit tag/memo: 3493784
  • XRP rJn2zAPdFA193sixJwuFixRkYDUtx3apQh tag/memo: 3493784

bybit-rs's People

Contributors

dependabot[bot] avatar peepo5 avatar wassup- avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bybit-rs's Issues

ErrorCode 10001 (Market Order)

When using the following parameters for an order:

PlaceActiveOrderData {
    symbol: "BTCUSDT",
    side: Buy,
    qty: 0.013,
    order_type: Market,
    price: None,
    time_in_force: PostOnly,
    close_on_trigger: None,
    order_link_id: None,
    take_profit: Some(
        50000.0,
    ),
    stop_loss: Some(
        41000.0,
    ),
    tp_trigger_by: None,
    sl_trigger_by: None,
    reduce_only: None,
}

I get:

ErrorCode { code: 10001, msg: "Param validation for 'qty' failed on the 'required' tag", ext_code: "", ext_info: "" }

Also,
When I pass the following I get the same error code but a different message:

PlaceActiveOrderData {
    symbol: "BTCUSDT",
    side: Buy,
    qty: 0.004583041053733335,
    order_type: Market,
    price: None,
    time_in_force: PostOnly,
    close_on_trigger: None,
    order_link_id: None,
    take_profit: Some(
        50000.0,
    ),
    stop_loss: Some(
        41000.0,
    ),
    tp_trigger_by: None,
    sl_trigger_by: None,
    reduce_only: None,
}

I get:

ErrorCode { code: 10001, msg: "Param validation for 'symbol' failed on the 'symbol' tag", ext_code: "", ext_info: "" }

Very strange reaction as the error is different even though the qty is only different by a little bit. Any ideas what these are? :P

fetch_symbols(): Reqwest Error: error decoding response body: unknown variant `Pending`

When running this code:

//no problems with this part
let mut api = http::Client::new(
	http::MAINNET_BYBIT,
	bybit_pub_key,
	bybit_priv_key,
)
.unwrap();

//erroring part
println!("{:#?}", api.fetch_symbols().await?);

I get this error (no need for unwrap by my pr but this also is an error on your git repo):

Reqwest Error: error decoding response body: unknown variant `Pending`, expected one of `Trading`, `Settling`, `Closed` at line 1 column 45977 

websocket error (401 [unauthorized]) on ws.Client.connect()

When running the following code:

let mut api = ws::Client::new(ws::MAINNET_BYBIT, &bybit_pub_key, &bybit_priv_key);
api.connect().await?;

I receive:

Ws Error: Http(Response { status: 401, version: HTTP/1.1, headers: {"content-type": "text/plain; charset=utf-8", "content-length": "15", "connection": "close", "date": "Sat, 08 Jan 2022 02:18:00 GMT", "x-cache": "Error from cloudfront", "via": "1.1 660625642e0df86c41275db1ce1ac923.cloudfront.net (CloudFront)", "x-amz-cf-pop": "ARN54-C1", "x-amz-cf-id": "sensitive info here?"}, body: None })

The API keys work fully for rest.

Have no idea how this happens, bad endpoint? Appreciate the help.

Open discussions tab

If this project is working fine, I plan to implement it into my project termcrypt.
It would be useful to open the discussions tab to talk about different ideas.

Improvement suggestion

When I try to handle errors with ? I recieve this:

error[E0277]: the trait bound `bybit::http::Error: std::error::Error` is not satisfied
   --> src/bybit_exchange/bybit_inter.rs:19:61
    |
19  |             let tickers = api.fetch_tickers("BTCUSDT").await?;
    |                                                             ^ the trait `std::error::Error` is not implemented for `bybit::http::Error`

Is there some way to impliment std:error:Error for bybit:http:Error ?

ErrorCode 10004 Invalid Sign (Market Order)

When sending the below object into the module

PlaceActiveOrderData {
    symbol: "BTCUSDT",
    side: Buy,
    qty: 0.013,
    order_type: Market,
    price: None,
    time_in_force: PostOnly,
    close_on_trigger: None,
    order_link_id: None,
    take_profit: Some(
        47200.0,
    ),
    stop_loss: Some(
        46150.0,
    ),
    tp_trigger_by: None,
    sl_trigger_by: None,
    reduce_only: None,
}

Using this code:

let order_result = api.place_active_order(order_data).await?;

I recieve this error:
!! Function Exited: ErrorCode { code: 10004, msg: "error sign! origin_string[api_key=[API KEY]&close_on_trigger=&order_link_id=&order_type=Market&price=&qty=0.013&reduce_only=&side=Buy&sl_trigger_by=&stop_loss=46150.0&symbol=BTCUSDT&take_profit=47200.0&time_in_force=PostOnly&timestamp=1641231577879&tp_trigger_by=]", ext_code: "", ext_info: "" } !!

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.