Git Product home page Git Product logo

ccxtsharp's Introduction

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 process
CcxtAPI ccxtAPI = new CcxtAPI(@"..\..\ccxt\ccxtAPI.exe");	 
// get list of avaliable exchanges
List<string> exchangeIds = await ccxtAPI.GetExchangIds();		
// print all exchange ids
exchangeIds.ForEach(id => Console.WriteLine(id));
// it's preferred to exit other process if your program will close
await ccxtAPI.Close();

List all markets.

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

Checking for implementation.

CcxtAPI ccxtAPI = new CcxtAPI(@"..\..\ccxt\ccxtAPI.exe");
// if cryptopia has support for fetch tickers then fetch them
if((await ccxtAPI.GetExchangeHas("cryptopia")).fetchTickers == Has.Capability.True)
{
  Dictionary<string, Ticker> tickers = await ccxtAPI.FetchTickers("cryptopia");
  // foreach ticker print their symbol and change
  foreach (var ticker in tickers.Values)
  {
    Console.WriteLine(ticker.symbol + ": " + ticker.change);
  }
}
await ccxtAPI.Close();

Private API.

CcxtAPI ccxtAPI = new CcxtAPI(@"..\..\ccxt\ccxtAPI.exe");
// Authenticate
await ccxtAPI.ExchangeApiKey("binance", "my_api_key");
await ccxtAPI.ExchangeSecret("binance", "my_api_secret");
// Place order
Order order =  await ccxtAPI.CreateOrder("binance", "ETH/USDT", OrderType.limit, OrderSide.buy, 1, 210);
// Cancel placed order
await ccxtAPI.CancelOrder("binance", order.id, "ETH/USDT");
await ccxtAPI.Close();

Exception handling

CcxtAPI ccxtAPI = new CcxtAPI(@"..\..\ccxt\ccxtAPI.exe");
try
{
  Dictionary<string, Market> markets = await ccxtAPI.LoadMarkets("_1broker");
}
catch (CCXTException ex)
{
  // exception is handled by ccxt python library
  if (ex.HandledByCCXT)
    Console.WriteLine(ex.exceptionType.Value.ToString() + ex.Message);
  else
  {
    // there is a bug either in python ccxt or in CCXTSharp
    Console.WriteLine(ex.Message);
    // restart process
    ccxtAPI.Kill(); // message will popup "Failed to execute script ccxtAPI.py"
    // reinitialize and continue execution
    ccxtAPI = new CcxtAPI(@"..\..\ccxt\ccxtAPI.exe");
  }
}
// ...
await ccxtAPI.Close();

ccxtsharp's People

Contributors

stock84-dev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ccxtsharp's Issues

bug about Balances..

Balances.info[9].value = 0.00009313
=> My balances I have now.

but, Balances.BTC.free => 9.31.... wow. Nice Counts I hope!

do you know how to fix it?

fetchOHLCV causing JsonReaderException

Example call:
long dt = DateTimeOffset.UtcNow.AddHours(-1).ToUnixTimeMilliseconds();
List c = await ccxtAPI.FetchOHLCV("coinbasepro", "BTC/USD", Timeframe.min1,dt);

Throws error:
Newtonsoft.Json.JsonReaderException: 'Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.'

ccxtApi.ShowPipeData = true shows OHLCV data being returned.

Sometimes.. We need a additional function about the balance infos.

in the Balances.cs

//original
public Dictionary<string, object> info { get; set; } = new Dictionary<string, object>();

//added function
public List<Dictionary<string, object> > infos { get; set; } = new List<Dictionary<string, object> >();

if (obj.Key == "info" && ExchangeName = "upbit")
{
//added function
if( ExchangeName == "upbit")
infos = obj.Value.ToObject<List<Dictionary<string, object> > >();

//origianl
else
info = obj.Value.ToObject<Dictionary<string, object> >();
}

I hope that in next release, It will be added on.

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.