This repository has been archived by the owner on Mar 7, 2023. It is now read-only.
forked from knowm/XChange
-
Notifications
You must be signed in to change notification settings - Fork 2
[Blockchain] marketDataService implementation #4
Open
scuevas-bc
wants to merge
3
commits into
bcdc-tradeservice-implementation
Choose a base branch
from
bcdc-marketservice-implementation
base: bcdc-tradeservice-implementation
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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
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
22 changes: 22 additions & 0 deletions
22
.../src/main/java/org/knowm/xchange/blockchain/dto/marketdata/BlockchainMarketDataOrder.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.knowm.xchange.blockchain.dto.marketdata; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.extern.jackson.Jacksonized; | ||
|
||
import java.math.BigDecimal; | ||
|
||
@Data | ||
@Builder | ||
@Jacksonized | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class BlockchainMarketDataOrder { | ||
|
||
@JsonProperty("px") | ||
private final BigDecimal price; | ||
@JsonProperty("qty") | ||
private final BigDecimal quantity; | ||
private final Long num; | ||
} |
23 changes: 23 additions & 0 deletions
23
...kchain/src/main/java/org/knowm/xchange/blockchain/dto/marketdata/BlockchainOrderBook.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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.knowm.xchange.blockchain.dto.marketdata; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.extern.jackson.Jacksonized; | ||
import org.knowm.xchange.currency.CurrencyPair; | ||
import org.knowm.xchange.utils.jackson.CurrencyPairDeserializer; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@Builder | ||
@Jacksonized | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class BlockchainOrderBook { | ||
|
||
@JsonDeserialize(using = CurrencyPairDeserializer.class) | ||
private final CurrencyPair symbol; | ||
private final List<BlockchainMarketDataOrder> bids; | ||
private final List<BlockchainMarketDataOrder> asks; | ||
} |
98 changes: 98 additions & 0 deletions
98
...chain/src/main/java/org/knowm/xchange/blockchain/service/BlockchainMarketDataService.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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package org.knowm.xchange.blockchain.service; | ||
|
||
import org.knowm.xchange.blockchain.BlockchainAdapters; | ||
import org.knowm.xchange.blockchain.BlockchainAuthenticated; | ||
import org.knowm.xchange.blockchain.BlockchainErrorAdapter; | ||
import org.knowm.xchange.blockchain.BlockchainExchange; | ||
import org.knowm.xchange.blockchain.dto.BlockchainException; | ||
import org.knowm.xchange.client.ResilienceRegistries; | ||
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.exceptions.NotYetImplementedForExchangeException; | ||
import org.knowm.xchange.instrument.Instrument; | ||
import org.knowm.xchange.service.marketdata.MarketDataService; | ||
import org.knowm.xchange.service.marketdata.params.Params; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static org.knowm.xchange.blockchain.BlockchainConstants.NOT_IMPLEMENTED_YET; | ||
|
||
public class BlockchainMarketDataService extends BlockchainMarketDataServiceRaw implements MarketDataService { | ||
|
||
public BlockchainMarketDataService(BlockchainExchange exchange, BlockchainAuthenticated blockchainApi, ResilienceRegistries resilienceRegistries) { | ||
super(exchange, blockchainApi, resilienceRegistries); | ||
} | ||
|
||
@Override | ||
public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws IOException { | ||
throw new NotYetImplementedForExchangeException(NOT_IMPLEMENTED_YET); | ||
} | ||
|
||
@Override | ||
public Ticker getTicker(Instrument instrument, Object... args) throws IOException { | ||
throw new NotYetImplementedForExchangeException(NOT_IMPLEMENTED_YET); | ||
} | ||
|
||
@Override | ||
public List<Ticker> getTickers(Params params) { | ||
throw new NotYetImplementedForExchangeException(NOT_IMPLEMENTED_YET); | ||
} | ||
|
||
@Override | ||
public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws IOException { | ||
try { | ||
return BlockchainAdapters.toOrderBook(this.getOrderBookL3(currencyPair)); | ||
} catch (BlockchainException e) { | ||
throw BlockchainErrorAdapter.adapt(e); | ||
} | ||
} | ||
|
||
@Override | ||
public OrderBook getOrderBook(Instrument instrument, Object... args) throws IOException { | ||
try { | ||
return BlockchainAdapters.toOrderBook(this.getOrderBookL3(BlockchainAdapters.toCurrencyPair(instrument))); | ||
} catch (BlockchainException e) { | ||
throw BlockchainErrorAdapter.adapt(e); | ||
} | ||
} | ||
|
||
@Override | ||
public Trades getTrades(CurrencyPair currencyPair, Object... args) throws IOException { | ||
try { | ||
Long startTime = null; | ||
Long endTime = null; | ||
Integer limit = null; | ||
String symbol = BlockchainAdapters.toSymbol(currencyPair); | ||
|
||
if (args != null) { | ||
switch (args.length) { | ||
case 2: | ||
if (args[1] != null && args[1] instanceof Long) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would create constants for these numbers... ZERO, ONE.. or even make them more self-declarative like START_DATE_INDEX, END_TIME_INDEX |
||
endTime = (Long) args[1]; | ||
} | ||
case 1: | ||
if (args[0] != null && args[0] instanceof Long) { | ||
startTime = (Long) args[0]; | ||
} | ||
} | ||
} | ||
|
||
return BlockchainAdapters.toTrades( | ||
this.getExchangeTrades(symbol, startTime, endTime, limit), | ||
currencyPair | ||
); | ||
}catch (BlockchainException e){ | ||
throw BlockchainErrorAdapter.adapt(e); | ||
} | ||
} | ||
|
||
@Override | ||
public Trades getTrades(Instrument instrument, Object... args) throws IOException { | ||
CurrencyPair currencyPair = BlockchainAdapters.toCurrencyPair(instrument); | ||
return getTrades(currencyPair,args); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...in/src/main/java/org/knowm/xchange/blockchain/service/BlockchainMarketDataServiceRaw.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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.knowm.xchange.blockchain.service; | ||
|
||
import org.knowm.xchange.blockchain.BlockchainAdapters; | ||
import org.knowm.xchange.blockchain.BlockchainAuthenticated; | ||
import org.knowm.xchange.blockchain.BlockchainExchange; | ||
import org.knowm.xchange.blockchain.dto.BlockchainException; | ||
import org.knowm.xchange.blockchain.dto.marketdata.BlockchainOrderBook; | ||
import org.knowm.xchange.blockchain.dto.trade.BlockchainOrder; | ||
import org.knowm.xchange.client.ResilienceRegistries; | ||
import org.knowm.xchange.currency.CurrencyPair; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static org.knowm.xchange.blockchain.BlockchainConstants.*; | ||
|
||
public class BlockchainMarketDataServiceRaw extends BlockchainBaseService{ | ||
|
||
protected BlockchainMarketDataServiceRaw(BlockchainExchange exchange, BlockchainAuthenticated blockchainApi, ResilienceRegistries resilienceRegistries) { | ||
super(exchange, blockchainApi, resilienceRegistries); | ||
} | ||
|
||
protected BlockchainOrderBook getOrderBookL3(CurrencyPair currencyPair) throws IOException, BlockchainException { | ||
return decorateApiCall(() -> this.blockchainApi.getOrderBookL3(BlockchainAdapters.toSymbol(currencyPair))) | ||
.withRetry(retry(GET_ORDER_BOOK_L3)) | ||
.withRateLimiter(rateLimiter(ENDPOINT_RATE_LIMIT)) | ||
.call(); | ||
} | ||
|
||
protected List<BlockchainOrder> getExchangeTrades(String symbol, Long startTime, Long endTime, Integer limit) throws IOException, BlockchainException { | ||
return decorateApiCall(() -> this.blockchainApi.getTrades(symbol, startTime, endTime, limit)) | ||
.withRetry(retry(GET_EXCHANGE_TRADES)) | ||
.withRateLimiter(rateLimiter(ENDPOINT_RATE_LIMIT)) | ||
.call(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an order or in order?