Skip to content

Commit

Permalink
[gateio] large structure refactor operation #2432
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Mar 26, 2018
1 parent bbc6741 commit 36de8fe
Show file tree
Hide file tree
Showing 18 changed files with 285 additions and 285 deletions.
14 changes: 7 additions & 7 deletions xchange-gateio/api-specification.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Gate.io Exchange API specification
================================
Public API
Documentation
-------------
Gate.io Exchange API specification
================================

Public API

Documentation
-------------
https://gate.io/api2
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
package org.knowm.xchange.gateio;

import java.io.IOException;
import java.util.Map;

import org.knowm.xchange.BaseExchange;
import org.knowm.xchange.Exchange;
import org.knowm.xchange.ExchangeSpecification;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.gateio.dto.marketdata.GateioMarketInfoWrapper.GateioMarketInfo;
import org.knowm.xchange.gateio.service.GateioAccountService;
import org.knowm.xchange.gateio.service.GateioMarketDataService;
import org.knowm.xchange.gateio.service.GateioMarketDataServiceRaw;
import org.knowm.xchange.gateio.service.GateioTradeService;
import org.knowm.xchange.utils.nonce.AtomicLongIncrementalTime2013NonceFactory;

import si.mazi.rescu.SynchronizedValueFactory;

public class GateioExchange extends BaseExchange implements Exchange {

private SynchronizedValueFactory<Long> nonceFactory = new AtomicLongIncrementalTime2013NonceFactory();

@Override
protected void initServices() {
this.marketDataService = new GateioMarketDataService(this);
this.accountService = new GateioAccountService(this);
this.tradeService = new GateioTradeService(this);
}

@Override
public ExchangeSpecification getDefaultExchangeSpecification() {

ExchangeSpecification exchangeSpecification = new ExchangeSpecification(this.getClass().getCanonicalName());
exchangeSpecification.setSslUri("https://data.gate.io");
exchangeSpecification.setHost("gate.io");
exchangeSpecification.setExchangeName("Gateio");

return exchangeSpecification;
}

@Override
public SynchronizedValueFactory<Long> getNonceFactory() {

return nonceFactory;
}

@Override
public void remoteInit() throws IOException {

Map<CurrencyPair, GateioMarketInfo> currencyPair2BTERMarketInfoMap = ((GateioMarketDataServiceRaw) marketDataService).getBTERMarketInfo();
exchangeMetaData = GateioAdapters.adaptToExchangeMetaData(currencyPair2BTERMarketInfoMap);
}
}
package org.knowm.xchange.gateio;

import java.io.IOException;
import java.util.Map;

import org.knowm.xchange.BaseExchange;
import org.knowm.xchange.Exchange;
import org.knowm.xchange.ExchangeSpecification;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.gateio.dto.marketdata.GateioMarketInfoWrapper.GateioMarketInfo;
import org.knowm.xchange.gateio.service.GateioAccountService;
import org.knowm.xchange.gateio.service.GateioMarketDataService;
import org.knowm.xchange.gateio.service.GateioMarketDataServiceRaw;
import org.knowm.xchange.gateio.service.GateioTradeService;
import org.knowm.xchange.utils.nonce.AtomicLongIncrementalTime2013NonceFactory;

import si.mazi.rescu.SynchronizedValueFactory;

public class GateioExchange extends BaseExchange implements Exchange {

private SynchronizedValueFactory<Long> nonceFactory = new AtomicLongIncrementalTime2013NonceFactory();

@Override
protected void initServices() {
this.marketDataService = new GateioMarketDataService(this);
this.accountService = new GateioAccountService(this);
this.tradeService = new GateioTradeService(this);
}

@Override
public ExchangeSpecification getDefaultExchangeSpecification() {

ExchangeSpecification exchangeSpecification = new ExchangeSpecification(this.getClass().getCanonicalName());
exchangeSpecification.setSslUri("https://data.gate.io");
exchangeSpecification.setHost("gate.io");
exchangeSpecification.setExchangeName("Gateio");

return exchangeSpecification;
}

@Override
public SynchronizedValueFactory<Long> getNonceFactory() {

return nonceFactory;
}

@Override
public void remoteInit() throws IOException {

Map<CurrencyPair, GateioMarketInfo> currencyPair2BTERMarketInfoMap = ((GateioMarketDataServiceRaw) marketDataService).getBTERMarketInfo();
exchangeMetaData = GateioAdapters.adaptToExchangeMetaData(currencyPair2BTERMarketInfoMap);
}
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
package org.knowm.xchange.gateio.dto.marketdata;

import java.util.List;

import org.knowm.xchange.gateio.dto.GateioBaseResponse;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Data object representing depth from Bter
*/
public class GateioDepth extends GateioBaseResponse {

private final List<GateioPublicOrder> asks;
private final List<GateioPublicOrder> bids;

/**
* Constructor
*
* @param asks
* @param bids
*/
private GateioDepth(@JsonProperty("asks") List<GateioPublicOrder> asks, @JsonProperty("bids") List<GateioPublicOrder> bids,
@JsonProperty("result") boolean result) {

super(result, null);
this.asks = asks;
this.bids = bids;
}

public List<GateioPublicOrder> getAsks() {

return asks;
}

public List<GateioPublicOrder> getBids() {

return bids;
}

@Override
public String toString() {

return "GateioDepth [asks=" + asks.toString() + ", bids=" + bids.toString() + "]";
}

}
package org.knowm.xchange.gateio.dto.marketdata;

import java.util.List;

import org.knowm.xchange.gateio.dto.GateioBaseResponse;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Data object representing depth from Bter
*/
public class GateioDepth extends GateioBaseResponse {

private final List<GateioPublicOrder> asks;
private final List<GateioPublicOrder> bids;

/**
* Constructor
*
* @param asks
* @param bids
*/
private GateioDepth(@JsonProperty("asks") List<GateioPublicOrder> asks, @JsonProperty("bids") List<GateioPublicOrder> bids,
@JsonProperty("result") boolean result) {

super(result, null);
this.asks = asks;
this.bids = bids;
}

public List<GateioPublicOrder> getAsks() {

return asks;
}

public List<GateioPublicOrder> getBids() {

return bids;
}

@Override
public String toString() {

return "GateioDepth [asks=" + asks.toString() + ", bids=" + bids.toString() + "]";
}

}
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
package org.knowm.xchange.gateio.service;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.knowm.xchange.Exchange;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.dto.marketdata.OrderBook;
import org.knowm.xchange.dto.marketdata.Ticker;
import org.knowm.xchange.dto.marketdata.Trades;
import org.knowm.xchange.gateio.GateioAdapters;
import org.knowm.xchange.gateio.dto.marketdata.GateioDepth;
import org.knowm.xchange.gateio.dto.marketdata.GateioTicker;
import org.knowm.xchange.gateio.dto.marketdata.GateioTradeHistory;
import org.knowm.xchange.service.marketdata.MarketDataService;

public class GateioMarketDataService extends GateioMarketDataServiceRaw implements MarketDataService {

/**
* Constructor
*
* @param exchange
*/
public GateioMarketDataService(Exchange exchange) {

super(exchange);
}

@Override
public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws IOException {

GateioTicker ticker = super.getBTERTicker(currencyPair.base.getCurrencyCode(), currencyPair.counter.getCurrencyCode());

return GateioAdapters.adaptTicker(currencyPair, ticker);
}

@Override
public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws IOException {

GateioDepth gateioDepth = super.getBTEROrderBook(currencyPair.base.getCurrencyCode(), currencyPair.counter.getCurrencyCode());

return GateioAdapters.adaptOrderBook(gateioDepth, currencyPair);
}

public Map<CurrencyPair, OrderBook> getOrderBooks() throws IOException {

Map<CurrencyPair, GateioDepth> gateioDepths = super.getGateioDepths();
Map<CurrencyPair, OrderBook> orderBooks = new HashMap<>(gateioDepths.size());

gateioDepths.forEach((currencyPair, gateioDepth) -> {
OrderBook orderBook = GateioAdapters.adaptOrderBook(gateioDepth, currencyPair);
orderBooks.put(currencyPair, orderBook);
});

return orderBooks;
}

@Override
public Trades getTrades(CurrencyPair currencyPair, Object... args) throws IOException {

GateioTradeHistory tradeHistory = (args != null && args.length > 0 && args[0] != null && args[0] instanceof String) ?
super.getBTERTradeHistorySince(currencyPair.base.getCurrencyCode(), currencyPair.counter.getCurrencyCode(), (String) args[0]) :
super.getBTERTradeHistory(currencyPair.base.getCurrencyCode(), currencyPair.counter.getCurrencyCode());

return GateioAdapters.adaptTrades(tradeHistory, currencyPair);
}

}
package org.knowm.xchange.gateio.service;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.knowm.xchange.Exchange;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.dto.marketdata.OrderBook;
import org.knowm.xchange.dto.marketdata.Ticker;
import org.knowm.xchange.dto.marketdata.Trades;
import org.knowm.xchange.gateio.GateioAdapters;
import org.knowm.xchange.gateio.dto.marketdata.GateioDepth;
import org.knowm.xchange.gateio.dto.marketdata.GateioTicker;
import org.knowm.xchange.gateio.dto.marketdata.GateioTradeHistory;
import org.knowm.xchange.service.marketdata.MarketDataService;

public class GateioMarketDataService extends GateioMarketDataServiceRaw implements MarketDataService {

/**
* Constructor
*
* @param exchange
*/
public GateioMarketDataService(Exchange exchange) {

super(exchange);
}

@Override
public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws IOException {

GateioTicker ticker = super.getBTERTicker(currencyPair.base.getCurrencyCode(), currencyPair.counter.getCurrencyCode());

return GateioAdapters.adaptTicker(currencyPair, ticker);
}

@Override
public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws IOException {

GateioDepth gateioDepth = super.getBTEROrderBook(currencyPair.base.getCurrencyCode(), currencyPair.counter.getCurrencyCode());

return GateioAdapters.adaptOrderBook(gateioDepth, currencyPair);
}

public Map<CurrencyPair, OrderBook> getOrderBooks() throws IOException {

Map<CurrencyPair, GateioDepth> gateioDepths = super.getGateioDepths();
Map<CurrencyPair, OrderBook> orderBooks = new HashMap<>(gateioDepths.size());

gateioDepths.forEach((currencyPair, gateioDepth) -> {
OrderBook orderBook = GateioAdapters.adaptOrderBook(gateioDepth, currencyPair);
orderBooks.put(currencyPair, orderBook);
});

return orderBooks;
}

@Override
public Trades getTrades(CurrencyPair currencyPair, Object... args) throws IOException {

GateioTradeHistory tradeHistory = (args != null && args.length > 0 && args[0] != null && args[0] instanceof String) ?
super.getBTERTradeHistorySince(currencyPair.base.getCurrencyCode(), currencyPair.counter.getCurrencyCode(), (String) args[0]) :
super.getBTERTradeHistory(currencyPair.base.getCurrencyCode(), currencyPair.counter.getCurrencyCode());

return GateioAdapters.adaptTrades(tradeHistory, currencyPair);
}

}
Loading

0 comments on commit 36de8fe

Please sign in to comment.