This project allows a user to create "batches" of limit orders that are a specific percentage above/below the current price for a specific market. A background job retrieves new prices from trades on Coinfalcon and then updates and batches where the price has gotten closer to the limit.
It will then delete the orders in a batch and create new ones using the percentage specified at by the batch.
It will also push any updates to batch prices / order_ids to the client browser using actioncable and websockets.
- Ruby >= 2.3
- Rails 5
- Redis (locally)
- ActiveJob
- ActionCable
Batches have many orders which use the batch percent and type to create the orders on coinfalcon. In the database an order is just a reference to a batch and a coinfalcon_id.
On the delayed jobs side of things, there is a background job called PriceUpdateJob that will:
- get latest prices
- enqueue a job for batches if there is a new price for their market using BatchUpdateJob
- Enqueue a new PriceUpdateJob for 15 seconds from now (this means the prices and batches will stay up to date) with the old prices so that the job can determine which markets have changed price.
Locally it is using Redis for the ActionCable pub/sub in order to allow testing updates with new prices from a seperate rails console instance.
When a batch is updated for a new market price (which I've called "balancing orders") it will broadcast the new order_ids and new batch price to an ActionCable stream called "batches" on the frontend there is some plain js to update the view when a batch is "balanced".
- Any Coinfalcon requests are limited to 3 requests per 2 seconds (the Coinfalcon API limits requets to 3 / 1 second).
- Due to the api requiring prices for limit orders to be no more than 5 units after the decimal (precision '%.5f') all orders are priced using this convention.
git clone https://github.com/NickPapacostas/coinfalcon-demo
cd coinfalcon-demo
bundle install
rake db:create
rake db:migrate
redis-server &
- set coinfalcon api key and secret as
CF_KEY
andCF_SECRET
rails s
rspec