Skip to content

Repository files navigation

CCXTSharp

This is a c# wrapper for popular trading library ccxt. Methods and documentation are pretty simmilar to ccxt.

Instalation

Package manager

Install-Package CCXTSharp

Updating ccxt library

  1. Install python 3.5+ (python 3.7 isn't currently supported by pyinstaller). And add python to system PATH if not already added by instalation.
  2. Open cmd.
  3. pip install ccxt // if libraries are already installed then type pip install ccxt --upgrade
  4. pip install cfscrape

Updating ccxtAPI program

  1. Update ccxt library
  2. Navigate to\your\project\ccxt\scripts in file explorer
  3. shift + right click, Open command window here
  4. pyinstaller -w -F ccxtAPI.py // program will be created in dist folder
  5. replace old file

Architecture

Package contains compiled python code that has original ccxt api. C# part creates new proccess and runs compiled python code. Inter process communication is done with named pipes.

Examples

List supported exchanges.

// initialize and start processCcxtAPIccxtAPI=newCcxtAPI(@"..\..\ccxt\ccxtAPI.exe");// get list of avaliable exchangesList<string>exchangeIds=awaitccxtAPI.GetExchangIds();// print all exchange idsexchangeIds.ForEach(id =>Console.WriteLine(id));// it's preferred to exit other process if your program will closeawaitccxtAPI.Close();

List all markets.

// initialize and run script in python interpreterCcxtAPIccxtAPI=newCcxtAPI(@"..\..\ccxt\scripts\ccxtAPI.py",@"D:\Program Files (x86)\Python36-32\python.exe");// gets list of markets on Binance exchange and prints their symbolsList<Market>markets=awaitccxtAPI.FetchMarkets("binance");markets.ForEach(m =>Console.WriteLine(m.symbol));awaitccxtAPI.Close();

Checking for implementation.

CcxtAPIccxtAPI=newCcxtAPI(@"..\..\ccxt\ccxtAPI.exe");// if cryptopia has support for fetch tickers then fetch themif((awaitccxtAPI.GetExchangeHas("cryptopia")).fetchTickers==Has.Capability.True){Dictionary<string,Ticker>tickers=awaitccxtAPI.FetchTickers("cryptopia");// foreach ticker print their symbol and changeforeach(vartickerintickers.Values){Console.WriteLine(ticker.symbol+": "+ticker.change);}}awaitccxtAPI.Close();

Private API.

CcxtAPIccxtAPI=newCcxtAPI(@"..\..\ccxt\ccxtAPI.exe");// AuthenticateawaitccxtAPI.ExchangeApiKey("binance","my_api_key");awaitccxtAPI.ExchangeSecret("binance","my_api_secret");// Place orderOrderorder=awaitccxtAPI.CreateOrder("binance","ETH/USDT",OrderType.limit,OrderSide.buy,1,210);// Cancel placed orderawaitccxtAPI.CancelOrder("binance",order.id,"ETH/USDT");awaitccxtAPI.Close();

Exception handling

CcxtAPIccxtAPI=newCcxtAPI(@"..\..\ccxt\ccxtAPI.exe");try{Dictionary<string,Market>markets=awaitccxtAPI.LoadMarkets("_1broker");}catch(CCXTExceptionex){// exception is handled by ccxt python libraryif(ex.HandledByCCXT)Console.WriteLine(ex.exceptionType.Value.ToString()+ex.Message);else{// there is a bug either in python ccxt or in CCXTSharpConsole.WriteLine(ex.Message);// restart processccxtAPI.Kill();// message will popup "Failed to execute script ccxtAPI.py"// reinitialize and continue executionccxtAPI=newCcxtAPI(@"..\..\ccxt\ccxtAPI.exe");}}// ...awaitccxtAPI.Close();

About

A cryptocurrency trading library with support for more than 100 bitcoin/altcoin exchanges. Uses original ccxt (python) code.

Topics

Resources

Stars

17 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages