GithubHelp home page GithubHelp logo

foonsun / bitmex-rs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dovahcrow/bitmex-rs

0.0 1.0 0.0 199 KB

Bitmex (non-official) client for rust WIP

License: MIT License

Rust 88.03% Jupyter Notebook 11.97%

bitmex-rs's Introduction

bitmex-rs Crates.io Build Status MIT licensed

BitMEX (non-official) client for rust, with async/await support!

Documentation

Caveat

Please run the tests before you use since BitMEX often introduces breaking changes without changing their Swagger API definition.

Also, the Swagger definition somehow is not aligned with BitMEX's realworld API. Since bitmex-rs auto-generates the code from swagger.json, you may experience some API breakage. Please do not hesitate to file an issue!

Usage

Add this to your Cargo.toml

[dependencies]
bitmex = "0.2"

Basic usage

// This will give you a BitMEX instance, which the only purpose is to create connection.
let bm = bitmex::BitMEX::with_credential(&std::env::var("BITMEX_KEY")?, &std::env::var("BITMEX_SECRET")?);

// All the requests to BitMEX server afterwards will go through HTTP Restful API.

// The request models reside in "bitmex::models" module, with the
// naming convention of "Method+camelCase(endpoint)+Request", e.g. "GET /trade/bucketed" would be
// "bitmex::models::GetTradeBucketedRequest" in bitmex-rs.
let req = bitmex::models::GetTradeBucketedRequest {
    bin_size: Some(bitmex::models::BinSize::D1),
    ..Default::default()
};

// Request to BitMEX server is made by giving "BitMEX::request" the request object.
// The return type of "BitMEX::request" is a future of the response so that you can await on it.
let resp = bm.request(req).await?;
println!("Bucketed trades: {:?}", resp);  

// A websocket is created by "BitMEX::websocket".
let mut ws = bm.websocket().await?;

// The websocket is a duplex channel which means you can send "bitmex::websocket::Command" to BitMEX and 
// receive "bitmex::websocket::Message" from BitMEX using it.
let expires = (Utc::now() + Duration::seconds(30)).timestamp();
ws.send(Command::authenticate(&bm, expires).unwrap()).await?;

// In order to get the ws messages, just poll the ws stream.
while let Some(message) = ws.next().await {
    println!("Subscription message received {:?}", message);
}

More examples located in the examples and tests folder.

Implementation status

Currently all the API features are implemented, including websocket!

bitmex-rs's People

Contributors

dovahcrow avatar tkawachi avatar tylerrichie avatar

Watchers

James Cloos avatar

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.