Code Monkey home page Code Monkey logo

bitmex.net's Introduction

Bitmex.NET

Wrapper for BitMEX.com REST API

Quick Start

Install NuGet package Install-Package Bitmex.NET

Create default API service:

First approach, creating default instance

var bitmexAuthorization = new BitmexAuthorization() 
{
  BitmexEnvironment = Bitmex.NET.Models.BitmexEnvironment.Test,
  Key = "your api key",
  Secret = "your api secret"
};
var bitmexApiService = BitmexApiService.CreateDefaultApi(bitmexAuthorization);

Another, registering in a DI container (e.g. Unity). Example

Container.RegisterType<IBitmexApiProxy, BitmexApiProxy>();
Container.RegisterType<IBitmexApiService, BitmexApiService>();

var authorization = new BitmexAuthorization
{
  BitmexEnvironment = Bitmex.NET.Models.BitmexEnvironment.Test,
  Key = "your api key",
  Secret = "your api secret"
};

Container.RegisterInstance<IBitmexAuthorization>(authorization);

place an order Example:

private async void Sell()
{
  var posOrderParams = OrderPOSTRequestParams.CreateSimpleMarket("XBTUSD", Size, OrderSide.Sell);
  await _bitmexApiService.Execute(BitmexApiUrls.Order.PostOrder, posOrderParams).ContinueWith(ProcessPostOrderResult);
}

Extensibility

I haven't implemented and tested all the existing methods yet so that you might want to call BitMEX APIs that haven't been done so far. To make you be able to call all APIs using the existing service I've tried to make the classes extensible. So... To implement your own API method please create your own parameters class (or use existing) deriving it from QueryStringParams (for GET requests) or JsonQueryParams(for POST/PUT/DELETE requests) and a class for requests (or use existing)

private class SomeQueryStringParams : QueryStringParams
{
  [DisplayName("val")]
  public string Value { get; set; }
}

private class SomeJsonParams : QueryJsonParams
{
  [JsonProperty("symbol")]
  public string Symbol { get; set; }
}

private class AResult
{
  [JsonProperty("value")]
  public string Value { get; set; }
}

Call it

var result = await bitmexApiService.Execute(new ApiActionAttributes<SomeJsonParams, AResult>("anApiMethod", HttpMethods.POST), new SomeJsonParams(){Symbol = "XBTUSD"});

// if the method returns an array of objects
var result = await bitmexApiService.Execute(new ApiActionAttributes<SomeJsonParams, List<AResult>>("anApiMethod", HttpMethods.POST), new SomeJsonParams(){Symbol = "XBTUSD"});

Progress

The following methods were implemented and covered with the integration tests

Method REST API Method
GET execution
GET execution/tradeHistory
GET instrument
GET instrument/active
GET instrument/activeAndIndices
GET instrument/activeIntervals
GET instrument/compositeIndex
GET instrument/indices
GET order
PUT order
POST order
DELETE order
DELETE order/all
PUT order/bulk
POST order/bulk
POST order/cancelAllAfter
POST order/closePosition
GET orderBook/L2
GET position
POST position/isolate
POST position/leverage
POST position/riskLimit
POST position/transferMargin
GET quote
GET quote/bucketed
GET trade
GET trade/bucketed

Examples

Please see example of simple Buy&Sell application here

Integration Tests

You will find a live example for all the implemented APIs within integration tests project here

Other

API was taken from testnet.bitmex.com

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.