Crates.io | kucoin_arbitrage |
lib.rs | kucoin_arbitrage |
version | 0.0.14 |
source | src |
created_at | 2023-03-16 17:09:24.113233 |
updated_at | 2023-10-21 18:29:28.349502 |
description | Event-Driven Kucoin Arbitrage Framework in Async Rust |
homepage | |
repository | https://github.com/kanekoshoyu/kucoin_arbitrage |
max_upload_size | |
id | 811654 |
size | 157,514 |
This is an async Rust project to implement zero-risk crypto trinagular arbitrage, explore technical feasiblity of generating passsive income (i.e. sleep to earn!).
Say we hold USDT, it checks all the listed crypto (e.g. ETH) that can trade against BTC and USDT, and compare the profit by either:
The above is triangular arbitrage, which is the simplest form of cyclic arbitrage. We can make more complex say finding the most profitable routes, or placing order at maker price for reduced fees.
2 years ago I have made a python script that runs the triangular arbitrage in KuCoin, but it had several technical issues and ended up not following up.
https://github.com/kanekoshoyu/Kucoin-Triangular-Arbitrage
[KuCoin Credentials]
api_key="YOUR_API_KEY"
secret_key="YOUR_SECRET_KEY"
passphrase="YOUR_PASSPHRASE"
[Behaviour]
# Performance monitor interval in seconds
monitor_interval_sec=120
# max amount of USD to use in a single cyclic arbitrage
usd_cyclic_arbitrage=100
cargo run --bin event_triangular
event_triangular
is one of the example executables that implements [XXX-BTC, XXX-USDT, BTC-USDT] triangular arbitrage. There are other executables in the bin
directory.
The project is split into these components:
bin
contains example executable codes. Some of them are for network testing purpose.model
has internal generic data structures used for abstracted representations of markets. This should be independent of exchange APIs so that the the arbitrage strategy algorithm can be conducted across different exchanges.event
has the events used to pass states and data passed across different components. It uses the internal model for the same reason.strategy
has the implementations of arbitrage strategy algorithm. The algorithms are built upon internal model and event.monitor
has the counter used to monitor MPS (message per seconds) for each broadcast channels, and a timers mapped globally by string for easy debug access.translator
has the conversion of exchange API objects into internal models and vice versa. It uses traits and the traits are implemented per API models.broker
has the tasks that runs API calls, and converts into internal data structure.Event broadcasts empowers the modularity of tasks. Each async task communicates with eachother using events, pub/sub via tokio's broadcast. Here is the exmaple for event_triangular.rs
Channel | Publisher | Subscriber |
---|---|---|
orderbook | task_pub_orderbook_event | task_monitor_channel_mps, task_sync |
orderbook_best | task_sync | task_monitor_channel_mps, task_pub_chance_all_taker_btc_usd |
chance | task_pub_chance_all_taker_btc_usd | task_monitor_channel_mps, task_gatekeep_chances |
order | task_gatekeep_chances | task_monitor_channel_mps, task_place_order |
orderchange | task_pub_orderchange_event | task_monitor_channel_mps, task_gatekeep_chances |
Tasks are grouped and spawned using JoinSets. We can either await for all the tasks to end with join!
or await until a single task ends with select!
or join_next
. This provides full control over how we want to control these tasks. Here is the exmaple for task pools declared in core function of event_triangular.rs
TaskPool | Task |
---|---|
taskpool_infrastructure | task_sync_orderbook, task_pub_chance_all_taker_btc_usd, task_gatekeep_chances, task_place_order |
taskpool_subscription | task_pub_orderbook_event, task_pub_orderchange_event |
taskpool_monitor | task_monitor_channel_mps, task_log_mps |
When a task in taskpool returns, its result is received by join_next
, which are received by core's select!
.
When an external signal is received, or core returns error, it gets detected by select!
at the main and terminates the program.
Feature | Status |
---|---|
Whitelist all coins that can trade against two other quote coins (e.g. ETH, for ETH-BTC, ETH-USDT) | Available |
Look for arbitrage chance based on best ask/bid price and calculate the profit in percentage | Available |
Copy and sync local orderbook in real-time | Available |
Structurally allow multiple strategies to run in pararrel | Available |
Order placement upon triangular arbitrage chance | Available |
Resort against limit order that could not get filled | Pending |
Full triangular arbitrage with the middle coin other than BTC (e.g. ETH-USD, ALT-ETH, ALT-USD) | Pending |
Please refer to my another repo implementing service-level wrappers: chaiwala