Chapter 1 Stream live cryptocurrency prices from the Binance WSS 1.1 Objectives
- create a new umbrella app
- create a supervised application inside an umbrella
- connect to Binance’s WebSocket Stream using the WebSockex module
- define a TradeEvent struct that will hold incoming data
- decode incoming events using the Jason module
Connect to Binance API Web Socket Stream (wss)
- The base endpoint is:
wss://stream.binance.com:9443
- Raw streams are accessed at
/ws/<streamName>
- All symbols for streams are lowercase
- Stream Name: @trade ->
wss://stream.binance.com:9443/ws/xrpusdt@trade
- WebSocket To establish a connection to Binance API’s stream
Chapter 2 Create a naive trading strategy
a single trader process without supervision 2.1 Objectives
- create another supervised application inside the umbrella to store our trading strategy
- define callbacks for events dependent on the state of the trader
- push events from the streamer app to the naive app
- binance API
- binance testnet
- binance academy
- binance create test wallet
- binance fund test account
- decimal (avoid precisions issues)
# USE TEST NET!
iex> Naive.Trader.start_link(%{symbol: "BTCUSDT", profit_interval: "-0.01"})
iex> Streamer.Binance.start_link("BTCUSDT")
Currently Streamer
-send_event-> Naive -GenServer.call-> Naive.Trader (single process)
To be able to run in parallel we need to remove the GenServer call process with a single name
Also remove the dependency between Streamer and Trader.
Streamer will broadcast and the traders will subscribe
Streamer -broadcast-> PubSub -subscribe-> Trader1 -subscribe-> Trader2 -subscribe-> Trader3
Current:
Trader -oder_limit_buy-> Binance -oder_limit_sell->
Post:
Trader -oder_limit_buy-> Config -> Binance -oder_limit_sell_/ _> BinanceMock
Streamer.start_streaming("BTCUSDT")
Naive.trade("BTCUSDT", "-0.001")