@BitNow: wow, that looks like some nice sources! If I had knew, that such a lib exists, I might have never started my own exchange API implementations. Congrats!
My lib still lacks the database part, so maybe we could collaborate at some point.
Things are really easy. Those are the entities:
1) Exchange
2) Market
3) FeeAPI_Type
4) API
5) Fee
Exchange holds the exchanges info:
Market holds Market info:
- code: market code (ex: BTC, BTC_USD, BTC_EUR, BTC_GBP, etc...
- description: market description (ex: for BTC_GBP -> "BTC_GBP market")
FeeAPI_Type holds Fee and API type's information:
- market: market code (ex: BTC_EUR)
- type: type of API/fee (ex: ORDERBOOK/DEPOSIT/WITHDRAW/TICKER...)
API holds API info:
Fee holds Fee info (similar to API):
- exchange: exchange code (ex: BITFINEX)
- type_market: market code (ex: FIAT_IWT)
- type_type: market type (ex: DEPOSIT)
- unit: fee unit (ex: $, €, £, BTC...)
- value: fee value (ex: 0.1)
- note: other notes about that fee entity
In
bold primary keys.
Than in the code I have a RESTInterface which every Exchange inherits so that you can easily load the appropriate interface for the correct API: adapt the interface to the API response for that particular exchange (ex: JSON, SOAP, XML...).
RESTInterface:
package com.gconsulting.webapp.rest.interfaces;
import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;
import com.gconsulting.model.Market;
import com.gconsulting.webapp.model.Orderbook;
public interface RESTInterface {
public List getPairs(JSONObject source);
public Orderbook getOrderbook(JSONObject source, String market) throws JSONException;
}
Ex Bitfinex exchange:
package com.gconsulting.webapp.rest.interfaces;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.gconsulting.model.Market;
import com.gconsulting.webapp.model.Order;
import com.gconsulting.webapp.model.Orderbook;
public class BITFINEXInterface implements RESTInterface {
@Override
public List getPairs(JSONObject source) {
// TODO Auto-generated method stub
return null;
}
@Override
public Orderbook getOrderbook(JSONObject source, String market)
throws JSONException {
Orderbook result = new Orderbook();
JSONArray asks = source.getJSONArray("asks");
JSONArray bids = source.getJSONArray("bids");
List sellOrders = new ArrayList<>();
List buyOrders = new ArrayList<>();
double cumValue = 0.0;
double price = 0.0;
double amount = 0.0;
for (int i = 0; i < asks.length(); i++) {
JSONObject jsonobject = asks.getJSONObject(i);
price = jsonobject.getDouble("price");
amount = jsonobject.getDouble("amount");
cumValue += price * amount;
sellOrders.add(new Order(price, amount, cumValue));
}
result.setSellOrders(sellOrders);
cumValue = 0.0;
price = 0.0;
amount = 0.0;
for (int i = 0; i < bids.length(); i++) {
JSONObject jsonobject = bids.getJSONObject(i);
price = jsonobject.getDouble("price");
amount = jsonobject.getDouble("amount");
cumValue += price * amount;
buyOrders.add(new Order(price, amount, cumValue));
}
result.setBuyOrders(buyOrders);
return result;
}
}
With that structure you can easily manage 90% of Exchanges API/Fee structures.