Skip to content

Latest commit

 

History

History
77 lines (63 loc) · 3.19 KB

README.md

File metadata and controls

77 lines (63 loc) · 3.19 KB

Exchange Spread Calculator

About

This application calculates the differences in the bid & ask price for different currency pairs across different exchanges.

The sorted output of this 'spread' is displayed on the console at periodic intervals.

Time : 2018-03-31T18:00:58.563
--------------------------------------------------------------------------------
  Sr Spread% Currency         Ask       Ask-Exch         Bid       Bid-Exch
--------------------------------------------------------------------------------
   1  0.1158  BCH-AUD    943.4601            ACX    845.5190     BTCMarkets
   2  0.0548  ETH-AUD    520.5717            ACX    493.5440     BTCMarkets
   3  0.0501  BTC-AUD   9176.2803            ACX   8738.0715     BTCMarkets

Program Execution

Execute using Maven : Execute run.bat to run the program.

Alternatively, use the command :

mvn exec:java -Dexec.mainClass="application.ApplicationRunner"

Configuration : File config.json

{
	"currencyPairs" : ["BTC-AUD", "ETH-AUD", "BCH-AUD"],
	"refreshInterval" : 5000,
	"threadPools" : {"poolACX" : 1, "poolBTC" : 10},
	"exchanges" : [
		{
			"id" : "BTCMarkets",
			"fee" : "0.95",
			"pollingLimit" : 2.5,
			"threadPool" : "poolBTC",
			"connectorClass" : "application.exchange.btcmarkets.BTCMarketsConnector"
		},
		{
			"id" : "ACX",
			"fee" : "0.99",
			"pollingLimit" : 2,
			"threadPool" : "poolACX",
			"connectorClass" : "application.exchange.acx.ACXConnector"
		}
	]
}

Approach

Observable - observer pattern has been used. There are three layers :

  • Event layer #1 : Query each exchange for the all currency pairs
  • Event layer #2 : After all exchanges have responded for any currency pair, calculate the spread for that currency pair
  • Event layer #3 : After all currency-pair spreads have been calculated, sort all of them and generate the output

(Logic implemented in the class : application.SpreadCalculatorTask)

Features

1. Scalability

  • Additional currency pairs : Easy to add more currency pairs. It simply involves configuring them in the JSON configuration file (property 'currencyPairs').
  • The number of threads to use for polling is configurable for each exchange separately (property 'ioThreads').

2. Design

  • Event driven reactive approach has been used to design the application.
  • Polling limit : it is configurable for each exchange (property 'pollingLimit'). The IO requests are throttled at this rate.
  • Resilient to IO failures : the failure of one web request won't affect spread calculation for the remaining currency pairs.
  • Responsive : the spread is always displayed at 5 second intervals. If any server response takes too much time, the last available cached data is used to display the results.

3. Good code quality

  • The code is easy to maintain and all configurations are externalized in a structured JSON format.
  • Modular approach to the addition of more exchanges (i.e. apart from ACX and BTCMarkets) - no modification of existing code needs to be done.
  • Exchange specific optimizations are done (e.g. for ACX, a single GET request polls the order book for all currency-pairs)