Skip to content

kanekoshoyu/exchange-collection

Repository files navigation

exchange-collection

crypto orderbook exchange OpenAPI(REST) and AsyncAPI(WS) doc and clients

doc license discord

problem with other cross-exchange libraries/frameworks

Most of the trading strategies require data and execution at different exchanges. There are trading libraries that provides abstraction over multiple exchanges.

library / framework multi-exchange primary language wrapper language
ccxt yes js python, php, csharp
hummingbot yes python, cpp n/a
openlimits yes rust python, js, go
barter-rs yes rust n/a
kelp yes go n/a

They have issues in the below aspects:

  1. marginal integration effort: there are many crypto exchanges (N) and programming languages (L). The effort to convert those written API doc into exchange library is B, then the overall effort is N * L * B.
  2. document consistecy: exchanges freqently update API and there is no proper versioning pipeline, causing API doc inconsistency.
  3. opinionated framework: cross-exchange libraries often designed as complex framework,and often fails to meet the business needs.
  4. multi-language support: generally people prefer python for proof of concept and rust for production. we should use rust as backbone, then provide python support on top, but also provide flexibility for native python vertical integration.

proposal

I propose a streamlined integration of exchange API with a new approach, by using machine-readable API documents; OpenAPI for REST and AsyncAPI for WebSocket.

  1. gather both OpenAPI and AsyncAPI YAML per exchange (with the collective help by freelancers)
  2. Set up codegen CI for generating REST/WS clients.
  3. Implement trading traits per generated model. I have set up trading traits in guilder. If you do not like it, feel free to still use the this repo for the OpenAPI / AsyncAPI and its code-gen clients.

structure

location feature
asset OpenAPI and AsyncAPI YAML
codegen codegen script in rust, run locally to generate and push
target generated code in python and rust
index.html OpenAPI / AsyncAPI viewer, hosted here

guidelines

specs guidelines
OpenAPI format {exchange}_rest_openapi.yaml, v3.X.Y, convert swagger to OpenAPI here
AsyncAPI format {exchange}_ws_asyncapi.yaml, YAML, v2.X.Y, codegen does not work well with v3 apparently
codegen written in Rust
official codegen output support rust python
unofficial support typescript csharp golang java dart kotlin php cplusplus scala

codegen commands

initial set up

install OpenAPI CLI

npm install -g @openapitools/openapi-generator-cli

install AsyncAPI CLI

npm install -g @asyncapi/generator

each codegen command

language input command
rust openapi (REST, reqwest) openapi-generator-cli generate -i example_openapi.yaml -g <language> -o output/example_rust_model --additional-properties=library=reqwest
rust asyncapi (WS, tokio-tungstenite) asyncapi generate fromTemplate asyncapi.yaml asyncapi-rust-ws-template
python openapi (REST, asyncio) openapi-generator-cli generate -i asset/binance_rest_openapi.yaml -g python -o ./target_binance_rest --additional-properties=asyncio=true
python asyncapi (WS, asyncio-websockets) wip

exchange integration status

below are the list of exchanges planned for integration. Please contact me if you want to integrate for orderbook exchange.

Exchange API Custodial REST (OpenAPI) WS (AsyncAPI)
ccxtrest / done /
hyperliquid no done done
bitwyre yes done done
bitget yes done done
binance yes done done
coinbase yes done done
hashkey (HK) yes done done
krakenfutures yes done done
gateio yes WIP WIP
okx yes WIP WIP
dydx no postponed /
polkadex no postponed /
zkex no postponed /
gmx no postponed /
bybit yes planned planned
kucoin yes planned planned
htx yes planned planned
bitflyer (JP) yes planned planned
coincheck (JP) yes planned planned
korbit (KR) yes planned planned
bitkub (TH) yes planned planned

I currently have no plan of supporting FIX protocol due to limited number of supported exchanges. But it is definitely an interesting one to try in the future.

TODO

  • gather assets
    • gather initial assets
      • gather 3 exchanges in OpenAPI
      • gather 3 exchanges in AsyncAPI
    • gather 10 exchanges for single exchange trading
    • gather 20 exchanges for cross exchange trading
  • set up CI for codegen model
    • rust codegen
      • REST (reqwest) client
      • WS (tokio-tungstenite) client template
      • CI for release on crates.io
    • python codegen
      • REST client
      • WS (asyncio-websockets)
      • CI for release on pip
  • set up guilder trading library
    • define market data traits
    • define order placement traits
    • define ledger traits
    • implement traits on top of the codegen model
    • package models with opinionated trait per language

notes

  • the ag command seems to be deprecated and cannot generate code properly
  • you can install asyncapi-preview extension on vs code for preview
  • comnunity AsyncAPI templates like python-sanic-template are not working properly

partnership

I keep this project opensource so that everyone can take part of it. If you have any OpenAPI / AsyncAPI document for a crypto exchange, you are more than welcome to add with a pull request, or I am willing to purchase as well.
If you want to get an exchange integrated, I can help get that up for an one-off cost in one week, just enough to pay my freelancing partner to get it done.
Please contact Sho Kaneko for details.

recruitment

OpenAPI / AsyncAPI Author

I am gathering API doc with @pakTech786 would be great if more people can help with it.

TypeScript AsyncAPI Template Developer

asyncapi-rust-ws-template

I have set up a repo to develop AsyncAPI template for Rust WS in React.
I am not a TS expert, so I would love to have an expert to accelarate development.

see also