Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gateio fix #4853

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public GateioOrder toGateioOrder(MarketOrder marketOrder) {
return GateioOrder.builder()
.currencyPair((CurrencyPair) marketOrder.getInstrument())
.side(marketOrder.getType())
.clientOrderId(marketOrder.getUserReference())
.clientOrderId("t-"+marketOrder.getUserReference())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you change the provided clientOrderId on the fly, then the library consumer can't find the order by original clientOrderId. IMHO it is a responsibility of a library consumer to generate the client ids in proper format

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, but if the client id is not specified, the order cannot be placed correctly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to api doc, field text in Order is optional: https://www.gate.io/docs/developers/apiv4/en/#create-an-order

I also just verified it manually

.account("spot")
.type("market")
.timeInForce("ioc")
Expand All @@ -116,7 +116,7 @@ public GateioOrder toGateioOrder(LimitOrder limitOrder) {
return GateioOrder.builder()
.currencyPair((CurrencyPair) limitOrder.getInstrument())
.side(limitOrder.getType())
.clientOrderId(limitOrder.getUserReference())
.clientOrderId("t-"+limitOrder.getUserReference())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you change the provided clientOrderId on the fly, then the library consumer can't find the order by original clientOrderId. IMHO it is a responsibility of a library consumer to generate the client ids in proper format

.account("spot")
.type("limit")
.timeInForce("gtc")
Expand Down Expand Up @@ -147,8 +147,12 @@ public Order toOrder(GateioOrder gateioOrder) {
builder.cumulativeAmount(gateioOrder.getFilledTotalQuote());
}
else if (orderType == OrderType.ASK) {
BigDecimal filledAssetAmount = gateioOrder.getFilledTotalQuote().divide(gateioOrder.getAvgDealPrice(), MathContext.DECIMAL32);
builder.cumulativeAmount(filledAssetAmount);
if(gateioOrder.getAvgDealPrice()==null||gateioOrder.getFilledTotalQuote()==null){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please format with spaces

builder.cumulativeAmount(BigDecimal.ZERO);
}else {
BigDecimal filledAssetAmount = gateioOrder.getFilledTotalQuote().divide(gateioOrder.getAvgDealPrice(), MathContext.DECIMAL32);
builder.cumulativeAmount(filledAssetAmount);
}
}
else {
throw new IllegalArgumentException("Can't map " + orderType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public OrderBook toOrderBook(GateioOrderBookNotification notification) {
Stream<LimitOrder> asks = orderBookPayload.getAsks().stream()
.map(priceSizeEntry -> new LimitOrder(OrderType.ASK, priceSizeEntry.getSize(), orderBookPayload.getCurrencyPair(), null, null, priceSizeEntry.getPrice()));

Stream<LimitOrder> bids = orderBookPayload.getAsks().stream()
Stream<LimitOrder> bids = orderBookPayload.getBids().stream()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a good catch 👍 I'll change the test to check it and fix it in PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here it is #4854

.map(priceSizeEntry -> new LimitOrder(OrderType.BID, priceSizeEntry.getSize(), orderBookPayload.getCurrencyPair(), null, null, priceSizeEntry.getPrice()));

return new OrderBook(Date.from(orderBookPayload.getTimestamp()), asks, bids);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ public class GateioStreamingExchange extends GateioExchange implements Streaming
private StreamingMarketDataService streamingMarketDataService;
private StreamingTradeService streamingTradeService;
private StreamingAccountService streamingAccountService;
public static final String WS_CHANNEL_URI = "wss://api.gateio.ws/ws/v4/";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why moving the url from config?


public GateioStreamingExchange() {}

@Override
public Completable connect(ProductSubscription... args) {
streamingService = new GateioStreamingService(exchangeSpecification.getSslUri(), exchangeSpecification.getApiKey(), exchangeSpecification.getSecretKey());
streamingService = new GateioStreamingService(getApiUrl(), exchangeSpecification.getApiKey(), exchangeSpecification.getSecretKey());
applyStreamingSpecification(exchangeSpecification, streamingService);
streamingMarketDataService = new GateioStreamingMarketDataService(streamingService);
streamingTradeService = new GateioStreamingTradeService(streamingService);
Expand All @@ -30,6 +31,11 @@ public Completable connect(ProductSubscription... args) {
return streamingService.connect();
}


private String getApiUrl() {
return WS_CHANNEL_URI;
}

@Override
public Completable disconnect() {
GateioStreamingService service = streamingService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public GateioStreamingMarketDataService(GateioStreamingService service) {
@Override
public Observable<OrderBook> getOrderBook(CurrencyPair currencyPair, Object... args) {
Integer orderBookLevel = (Integer) ArrayUtils.get(args, 0, MAX_DEPTH_DEFAULT);
Duration updateSpeed = (Duration) ArrayUtils.get(args, 1, UPDATE_INTERVAL_DEFAULT);
Integer updateTime = Integer.parseInt(ArrayUtils.get(args, 1, UPDATE_INTERVAL_DEFAULT).toString());
Duration updateSpeed = Duration.ofMillis(updateTime);
return service
.subscribeChannel(Config.SPOT_ORDERBOOK_CHANNEL, new Object[]{currencyPair, orderBookLevel, updateSpeed})
.map(GateioOrderBookNotification.class::cast)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Data
public final class Config {

public static final String V4_URL = "wss://api.gateio.ws/ws/v4/";
public static final String V4_URL = "https://api.gateio.ws/";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this url is used for rest calls

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rest api cannot be called normally

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't have to do REST calls from xchange-stream-gateio module, all rest calls are done in xchange-gateio-v4 or xchange-gateio modules


public static final String SPOT_ORDERBOOK_CHANNEL = "spot.order_book";
public static final String SPOT_TRADES_CHANNEL = "spot.trades";
Expand Down
Loading