Skip to content

nathan-alexander/csharp-binance-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C# Binance API

This project is an implementation of the Binance API in C# - it is intended to encourage people to start developing projects utilizing this code.

Getting Started

The API key and secret can be set in the BinanceClient/Binance.cs file OR be passed into the client

Setting in BinanceClient/Binance.cs

public class BinanceClient : IBinanceClient
    {
        private readonly HttpClient _httpClient;
        private string url = "https://www.binance.com/api/";
        private string key = "key";
        private string secret = "secret";

Initializing the Client/Service

using BinanceAPI;
using static BinanceAPI.BinanceClient;

var binanceClient = new BinanceAPI.BinanceClient();
var binanceService = new BinanceService(binanceClient);

Passing thru to BinanceClient

using BinanceAPI;
using static BinanceAPI.BinanceClient;

var binanceClient = new BinanceAPI.BinanceClient("key", "secret");
var binanceService = new BinanceService(binanceClient);

BinanceExecute/Examples.cs includes the following line in every example:

Task.WaitAll(getDepth);

This is done because the examples are written in a standard console application.

Get ticker depth

Signature

public async Task<dynamic> GetDepthAsync(string symbol)

Example

var getDepth = binanceService.GetDepthAsync("BNBBTC"); 
dynamic depth = getDepth.Result;
Console.WriteLine(depth);

Get account information

Signature

public async Task<dynamic> GetAccountAsync()

Example

var getAccount = binanceService.GetAccountAsync();
dynamic account = getAccount.Result;
Console.WriteLine(account);

Get orders for a symbol

Signature

public async Task<dynamic> GetOrdersAsync(string symbol, int limit = 500)

Example

var getOrders = binanceService.GetOrdersAsync("BNBBTC", 100);
dynamic orders = getOrders.Result;
Console.WriteLine(orders);

Get positions (trades) for your account

Signature

public async Task<dynamic> GetTradesAsync(string symbol)

Example

var getMyTrades = binanceService.GetTradesAsync("WTCBTC");
dynamic trades = getMyTrades.Result;
Console.WriteLine(trades);

Get all the latest prices for all symbols

Signature

public List<Prices> ListPrices();

Example

List<Prices> prices = new List<Prices>();
prices = binanceService.ListPrices();
Console.WriteLine(prices);

Get the price of a symbol

Signature

public double GetPriceOfSymbol(string symbol)

Example

double symbol = binanceService.GetPriceOfSymbol("BNBBTC");
Console.WriteLine("Price of BNB: " + symbol);

Place a BUY order

Signature

public async Task<dynamic> PlaceBuyOrderAsync(string symbol, double quantity, double price, string type = "LIMIT")

Example (LIMIT)

var placeBuyOrder = binanceService.PlaceBuyOrderAsync("NEOBTC", 1.00, 00.008851);
dynamic buyOrderResult = placeBuyOrder.Result;
Console.WriteLine(buyOrderResult);

Example (MARKET)

var placeBuyOrder = binanceService.PlaceBuyOrderAsync("NEOBTC", 1.00, 0, "MARKET");
dynamic buyOrderResult = placeBuyOrder.Result;
Console.WriteLine(buyOrderResult);

Place a SELL order

Signature

public async Task<dynamic> PlaceSellOrderAsync(string symbol, double quantity, double price, string type = "LIMIT")

Example (LIMIT)

var placeSellOrder = binanceService.PlaceSellOrderAsync("NEOBTC", 1.00, 00.008851);
dynamic sellOrderResult = placeSellOrder.Result;
Console.WriteLine(sellOrderResult);

Example (MARKET)

var placeSellOrder = binanceService.PlaceSellOrderAsync("NEOBTC", 1.00, 0, "MARKET");
dynamic sellOrderResult = placeSellOrder.Result;
Console.WriteLine(sellOrderResult);

Check an order's status

Signature

public async Task<dynamic> CheckOrderStatusAsync(string symbol, int orderId)

Example

var checkOrder = binanceService.CheckOrderStatusAsync("NEOBTC", 5436663);
dynamic checkOrderResult = checkOrder.Result;
Console.WriteLine(checkOrderResult);

Delete an order

Signature

public async Task<dynamic> CancelOrderAsync(string symbol, int orderId)

Example

var deleteOrder = binanceService.CancelOrderAsync("NEOBTC", 5436663);
dynamic deleteOrderResult = deleteOrder.Result;
Console.WriteLine(deleteOrderResult);

About

C# Implementation of binance api

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages