crypto orderbook exchange OpenAPI(REST) and AsyncAPI(WS) doc and clients
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:
- 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.
- 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.
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.
- gather both OpenAPI and AsyncAPI YAML per exchange (with the collective help by freelancers)
- 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 its code-gen 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, 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 |
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 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 |
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.
- 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
- gather initial assets
- 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 - 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 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.
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 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)