machine-readable crypto exchange OpenAPI / AsyncAPI doc and clients
Many trading strategies require data and execution at multiple exchanges. Trading libraries 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:
- 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.
- document consistecy: exchanges freqently update API and there is no proper versioning pipeline, causing API doc inconsistency.
- opinionated framework: cross-exchange libraries often designed as complex framework,and often fails to meet the business needs.
- 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.
by gathering OpenAPI / AsyncAPI docuements, we can build a CI pipeline that generate and test versioned clients for different languages solving the above issues.
- crowdsource both OpenAPI / AsyncAPI YAML per exchange.
- Set up codegen CI for generating REST/WS clients.
- 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 proprietary clients.
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 |
specs | guidelines |
---|---|
OpenAPI format | {exchange}_rest_openapi.yaml , v3.X.Y, convert swagger to OpenAPI here |
AsyncAPI format | {exchange}_ws_asyncapi.yaml , YAML, v3.0.X, codegen topology natively supports V3 now |
codegen | written in Rust |
official codegen output support | rust python (codegen coming soon) |
unofficial support | typescript csharp golang java dart kotlin php cplusplus scala |
install OpenAPI CLI
npm install -g @openapitools/openapi-generator-cli
install AsyncAPI CLI
npm install -g @asyncapi/generator
language | input | command |
---|---|---|
rust | openapi (REST, reqwest) | openapi-generator-cli generate -i {YAML} -g rust -o {OUTPUT_DIR} --additional-properties=library=reqwest |
rust | asyncapi (WS, tokio-tungstenite) | asyncapi generate fromTemplate {YAML} asyncapi-rust-ws-template -p exchange={EXCHANGE} |
python | openapi (REST, asyncio) | openapi-generator-cli generate -i {YAML} -g python -o {OUTPUT_DIR} --additional-properties=asyncio=true |
python | asyncapi (WS, asyncio-websockets) | wip |
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 |
okx | yes | done | done |
krakenfutures | yes | done | done |
gateio | 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 |
bitbank (JP) | 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.
- gather assets
- gather 3 sets of API docs initial assets
- gather 10 exchanges to validate the idea
- gather 100 exchanges to have a competitive trading library
- set up CI for codegen model
- 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
- the
ag
command seems to be deprecated and cannot generate code properly, use 'asyncapi generate' instead - you can install
asyncapi-preview
extension on vs code for preview - comnunity AsyncAPI templates like
python-sanic-template
are not working properly
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 at reasonable cost 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 for partnerships.
I am gathering API doc with @pakTech786 would be great if more people can help with it.
I have set up a repo to develop AsyncAPI template for Rust WS in React. I want a version for python as well. I am not a TS expert, so I would love to have an expert to accelarate development.
- guilder - Unopinionated Cross-Exchange Crypto Trading Library
- asyncapi-rust-ws-template - AsyncAPI Template for Generating Rust WebSocket Client
- kucoin-arbitrage - KuCoin Cyclic Arbitrage, in Tokio Rust (legacy)
- typed-websocket - rust typed websocket client