If you know Rust and are familiar with Binance, then this is for you.
I need a script written in Rust that will connect and listen to Binance user data stream for isolated margin trading…
This script takes a single argument as input.
When an event is received it will check for two conditions:
if the event status is one of the following: "PARTIALLY_FILLED", "FILLED".
if the symbol is the same as the argument used when starting the script.
If the conditions are met, the script will send a market order to Binance Futures for the same pair, the same order size but opposite direction.
So if the websockets receives the event: "BUY 0.1 BTCUSDT", then the futures order will be "SELL 0.1 BTCUSDT".
Things to pay attention to:
Binance user data streams need to be kept alive by refreshing the listen key. Someone familiar with Binance knows what I'm talking about.
The precision for the quantity are different. Figure out a way to know the precision from the moment the script is started. If the websocket event says "BUY 1.23456 BTCUSDT" then the futures order should be "SELL 1.234 BTCUSDT" because the isolated margin quantity precision is 5 decimals and futures quantity precision is 3 decimals.
There may be multiple events received by the websocket at the same time. The futures orders need to be sent concurrently (at the same time).
Feel free to use existing crates like barter-data. If you have any other ideas we can discuss them.
Also need logging to make sure everything works as expected.
Deliverables: source code