This project is an implementation of the Binance API in C# - it is intended to encourage people to start developing projects utilizing this code.
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.
Signature
public async Task<dynamic> GetDepthAsync(string symbol)Example
var getDepth = binanceService.GetDepthAsync("BNBBTC");
dynamic depth = getDepth.Result;
Console.WriteLine(depth);Signature
public async Task<dynamic> GetAccountAsync()Example
var getAccount = binanceService.GetAccountAsync();
dynamic account = getAccount.Result;
Console.WriteLine(account);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);Signature
public async Task<dynamic> GetTradesAsync(string symbol)Example
var getMyTrades = binanceService.GetTradesAsync("WTCBTC");
dynamic trades = getMyTrades.Result;
Console.WriteLine(trades);Signature
public List<Prices> ListPrices();Example
List<Prices> prices = new List<Prices>();
prices = binanceService.ListPrices();
Console.WriteLine(prices);Signature
public double GetPriceOfSymbol(string symbol)Example
double symbol = binanceService.GetPriceOfSymbol("BNBBTC");
Console.WriteLine("Price of BNB: " + symbol);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);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);Signature
public async Task<dynamic> CheckOrderStatusAsync(string symbol, int orderId)Example
var checkOrder = binanceService.CheckOrderStatusAsync("NEOBTC", 5436663);
dynamic checkOrderResult = checkOrder.Result;
Console.WriteLine(checkOrderResult);Signature
public async Task<dynamic> CancelOrderAsync(string symbol, int orderId)Example
var deleteOrder = binanceService.CancelOrderAsync("NEOBTC", 5436663);
dynamic deleteOrderResult = deleteOrder.Result;
Console.WriteLine(deleteOrderResult);