-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gateio] large structure refactor operation #2432
- Loading branch information
Your Name
committed
Mar 26, 2018
1 parent
bbc6741
commit 36de8fe
Showing
18 changed files
with
285 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
106 changes: 53 additions & 53 deletions
106
xchange-gateio/src/main/java/org/knowm/xchange/gateio/GateioExchange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
94 changes: 47 additions & 47 deletions
94
xchange-gateio/src/main/java/org/knowm/xchange/gateio/dto/marketdata/GateioDepth.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() + "]"; | ||
} | ||
|
||
} |
138 changes: 69 additions & 69 deletions
138
xchange-gateio/src/main/java/org/knowm/xchange/gateio/service/GateioMarketDataService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
Oops, something went wrong.