Code Monkey home page Code Monkey logo

money-exchange-rater's Introduction

Money Exchange Rater

An open source artifact that consults different API's for exchange rates.

This library contains a structure that can easily been scanned by the main class, named ApiManager, this class can scan for available implemented java object that make request and parse the public information retrieved by an exchange public api.

How to include a new exchange parser

With this library you can add new public api for currency exchange easily, just need to implement ExchangeRaterApi interface (also you can extends from AbstractExchangeRaterApi if you want to save some line codes) create the required methods and objects and put your package in the package named org.darkestapp.money_exchange_rater.api. One last step is to include:

@Api(enabled = true)

at the beginning of your ExchangeRaterApi implementation and done, the ApiManager can scan the new api implementation.

How to include new supported currencies

You can include a new currency adding a new element in PublicCurrencyCode enum, after that, any api can use this new currency within its implementation.

How to implement in your application

Just create a new instance of ApiManager class, this class contains a method named:

Map<String, ExchangeRaterApi> getAvailableApiMap()

The method returns a map with all the supported api's, just select one ExchangeRaterApi from the retrieved map and use the method:

getApiObject(CurrencyPair currencyPair)

The currencyPair object must contains the currency to rate, for example:

    public static void main(String[] args) {

        try {
            ApiManager manager = new ApiManager();
            Map<String, ExchangeRaterApi> apiMap = manager.getAvailableApiMap();
            CurrencyPair currencyPair = CurrencyPairBuilder.build(
                    PublicCurrencyCode.USDT,
                    PublicCurrencyCode.BTC);
            ExchangeRaterApi api;
            ApiObject apiObject;
            for(Map.Entry<String, ExchangeRaterApi> entry : apiMap.entrySet()) {
                api = entry.getValue();
                if(api.getApiId().getShortName().equals("BITT")) {
                    System.out.println("Checking Bittrex API:");

                    apiObject = api.getApiObject(currencyPair);
                    System.out.println(apiObject);

                    //To get buy price
                    System.out.println("Buy price for " + currencyPair.getCurrenciesCodes() + "\n"
                            + "\t" + apiObject.getBuyPrice());

                    //To get sell price
                    System.out.println("Sell price for " + currencyPair.getCurrenciesCodes() + "\n"
                            + "\t" +apiObject.getSellPrice());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

If you want to use this artifact in your Kotlin application, you can use the following lines as example:

    fun main(args: Array<String>) {

        try {
            val manager = ApiManager()
            val map = manager.availableApiMap
            val currencyPair = CurrencyPairBuilder.build(
                    PublicCurrencyCode.USDT,
                    PublicCurrencyCode.BTC)
            for((code, api) in map) {
                if(api.apiId.shortName.equals("BITT")) {
                    println("Checking Bittrex API:")

                    val apiObject = api.getApiObject(currencyPair)
                    println(apiObject)

                    //To get buy price
                    println("Buy price for " + currencyPair.currenciesCodes + "\n"
                            + "\t" + apiObject.buyPrice)

                    //To get sell price
                    println("Sell price for " + currencyPair.currenciesCodes + "\n"
                            + "\t" + apiObject.sellPrice)
                }
                println(code)
            }
        }
        catch (e: Exception) {
            e.printStackTrace()
        }
    }

How to include in your app.

The artifact is hosted in jcenter, you need to include jcenter in your repositories sources. If you are using gradle, to include this library using the following lines:

    compile 'org.darkestapp.money-exchange-rater:money-exchange-rater:1.0.2'

For maven users, you can include in your pom file:

<dependency>
  <groupId>org.darkestapp.money-exchange-rater</groupId>
  <artifactId>money-exchange-rater</artifactId>
  <version>1.0.2</version>
  <type>pom</type>
</dependency>

money-exchange-rater's People

Contributors

darkestpriest avatar

Watchers

James Cloos avatar  avatar

money-exchange-rater's Issues

Refactor on getApiObject method from ExchangeRaterApi

It is required to ensure to use CurrencyPair directly as argument in the getApiObject to ensure that any ExchangeRaterApi implementation allows to use CurrencyPair.

The implementation must be handle this refactor, without issue.

Dependencies are not loading in runtime.

When the artifact is compiled using gradle its dependencies are not fully loaded in rutime, for example, the reflections library is not getting loaded in runtime when an example app is tested.

Possible fixes:

  • Create a fat-jar artifact and deploy it to the main repository.
  • Research a way to include this dependencies in the pom used in the repository.

Implement proxy support

The actual version does not support proxy connections.

It is required:

  • Get the default proxy from the system.
  • If proxy exists, allow make request using the default proxy.

Implement a class that retrieves the echange rate for any currency pair, independent for the API requested.

For the next release is required a class that retrieve the exchange rate for any currency pair, does not matter the api requested, for example:
The API A only retrieves exchange rater for currency pair X-Y, the API B only retrieves the rate for Y-Z, but, an user requires the exchange rate for X-Z, the artifact must implement a class that allows this kind of behaviour.

For fix this issue is required:

  • A class with a static method that retrieve the exchange rate for any currency pair.
  • This class will consult all the available (supported) APIs to get the required rate.
  • If is not possible the exchange rate, must be return a proper response, try to not throw an exception in this case.
  • The returned object must be contains the "path" required to allow the exchange rate for the specific currency pair.

Implement redirection in http requester.

In 1.0.0 version if the API redirects the request for attacks protection the HTTP request cannot handle this kind of actions.
It is required to the HTTP requester to handle this cases.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.