-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[Upbit] add support for market orders and candlestick #4823
Merged
Merged
Changes from 2 commits
Commits
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
36 changes: 0 additions & 36 deletions
36
...ge-examples/src/main/java/org/knowm/xchange/examples/upbit/trade/UpbitLimitOrderDemo.java
This file was deleted.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
xchange-examples/src/main/java/org/knowm/xchange/examples/upbit/trade/UpbitTradeDemo.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,66 @@ | ||
package org.knowm.xchange.examples.upbit.trade; | ||
|
||
import java.io.IOException; | ||
import java.math.BigDecimal; | ||
import java.util.Collection; | ||
import org.knowm.xchange.Exchange; | ||
import org.knowm.xchange.currency.Currency; | ||
import org.knowm.xchange.currency.CurrencyPair; | ||
import org.knowm.xchange.dto.Order; | ||
import org.knowm.xchange.dto.Order.OrderType; | ||
import org.knowm.xchange.dto.trade.LimitOrder; | ||
import org.knowm.xchange.dto.trade.MarketOrder; | ||
import org.knowm.xchange.examples.upbit.UpbitDemoUtils; | ||
import org.knowm.xchange.service.trade.TradeService; | ||
|
||
/** Demonstrate requesting limit order at Upbit */ | ||
public class UpbitTradeDemo { | ||
|
||
public static void main(String[] args) throws Exception { | ||
Exchange upbit = UpbitDemoUtils.createExchange(); | ||
generic(upbit.getTradeService()); | ||
} | ||
|
||
private static void generic(TradeService tradeService) throws IOException, InterruptedException { | ||
|
||
limitOrder(tradeService); | ||
marketOrderBuy(tradeService); | ||
marketOrderSell(tradeService); | ||
} | ||
|
||
private static void limitOrder(TradeService tradeService) | ||
throws IOException, InterruptedException { | ||
LimitOrder limitOrder = | ||
new LimitOrder.Builder(OrderType.BID, new CurrencyPair(Currency.ETH, Currency.KRW)) | ||
.originalAmount(new BigDecimal("0.01")) | ||
.limitPrice(new BigDecimal("200000")) | ||
.build(); | ||
String id = tradeService.placeLimitOrder(limitOrder); | ||
Thread.sleep(3000); | ||
Collection<Order> orders = tradeService.getOrder(id); | ||
orders.forEach(System.out::println); | ||
System.out.println(tradeService.cancelOrder(id)); | ||
} | ||
|
||
private static void marketOrderBuy(TradeService tradeService) | ||
throws IOException, InterruptedException { | ||
MarketOrder marketOrder = | ||
new MarketOrder.Builder(OrderType.BID, CurrencyPair.BTC_KRW) | ||
.originalAmount(new BigDecimal("50000")) | ||
.build(); | ||
final String orderId = tradeService.placeMarketOrder(marketOrder); | ||
final Collection<Order> order = tradeService.getOrder(orderId); | ||
order.forEach(System.out::println); | ||
} | ||
|
||
private static void marketOrderSell(TradeService tradeService) | ||
throws IOException, InterruptedException { | ||
MarketOrder marketOrder = | ||
new MarketOrder.Builder(OrderType.ASK, CurrencyPair.BTC_KRW) | ||
.originalAmount(new BigDecimal("0.00076675")) | ||
.build(); | ||
final String orderId = tradeService.placeMarketOrder(marketOrder); | ||
final Collection<Order> order = tradeService.getOrder(orderId); | ||
order.forEach(System.out::println); | ||
} | ||
} |
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
120 changes: 120 additions & 0 deletions
120
xchange-upbit/src/main/java/org/knowm/xchange/upbit/dto/marketdata/UpbitCandleStickData.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,120 @@ | ||
package org.knowm.xchange.upbit.dto.marketdata; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.math.BigDecimal; | ||
|
||
public class UpbitCandleStickData { | ||
|
||
private final String market; | ||
private final String candleDateTimeUtc; | ||
private final String candleDateTimeKst; | ||
private final BigDecimal openingPrice; | ||
private final BigDecimal highPrice; | ||
private final BigDecimal lowPrice; | ||
private final BigDecimal tracePrice; | ||
private final Long timestamp; | ||
private final BigDecimal candleAccTradePrice; | ||
private final BigDecimal candleAccTradeVolume; | ||
private final String firstDayOfPeriod; | ||
|
||
public UpbitCandleStickData( | ||
@JsonProperty("market") String market, | ||
@JsonProperty("candle_date_time_utc") String candleDateTimeUtc, | ||
@JsonProperty("candle_date_time_kst") String candleDateTimeKst, | ||
@JsonProperty("opening_price") BigDecimal openingPrice, | ||
@JsonProperty("high_price") BigDecimal highPrice, | ||
@JsonProperty("low_price") BigDecimal lowPrice, | ||
@JsonProperty("trade_price") BigDecimal tracePrice, | ||
@JsonProperty("timestamp") Long timestamp, | ||
@JsonProperty("candle_acc_trade_price") BigDecimal candleAccTradePrice, | ||
@JsonProperty("candle_acc_trade_volume") BigDecimal candleAccTradeVolume, | ||
@JsonProperty("first_day_of_period") String firstDayOfPeriod) { | ||
this.market = market; | ||
this.candleDateTimeUtc = candleDateTimeUtc; | ||
this.candleDateTimeKst = candleDateTimeKst; | ||
this.openingPrice = openingPrice; | ||
this.highPrice = highPrice; | ||
this.lowPrice = lowPrice; | ||
this.tracePrice = tracePrice; | ||
this.timestamp = timestamp; | ||
this.candleAccTradePrice = candleAccTradePrice; | ||
this.candleAccTradeVolume = candleAccTradeVolume; | ||
this.firstDayOfPeriod = firstDayOfPeriod; | ||
} | ||
|
||
public String getMarket() { | ||
return market; | ||
} | ||
|
||
public String getCandleDateTimeUtc() { | ||
return candleDateTimeUtc; | ||
} | ||
|
||
public String getCandleDateTimeKst() { | ||
return candleDateTimeKst; | ||
} | ||
|
||
public BigDecimal getOpeningPrice() { | ||
return openingPrice; | ||
} | ||
|
||
public BigDecimal getHighPrice() { | ||
return highPrice; | ||
} | ||
|
||
public BigDecimal getLowPrice() { | ||
return lowPrice; | ||
} | ||
|
||
public BigDecimal getTracePrice() { | ||
return tracePrice; | ||
} | ||
|
||
public Long getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
public BigDecimal getCandleAccTradePrice() { | ||
return candleAccTradePrice; | ||
} | ||
|
||
public BigDecimal getCandleAccTradeVolume() { | ||
return candleAccTradeVolume; | ||
} | ||
|
||
public String getFirstDayOfPeriod() { | ||
return firstDayOfPeriod; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "UpbitCandleStickData{" | ||
+ "market='" | ||
+ market | ||
+ '\'' | ||
+ ", candleDateTimeUtc='" | ||
+ candleDateTimeUtc | ||
+ '\'' | ||
+ ", candleDateTimeKst='" | ||
+ candleDateTimeKst | ||
+ '\'' | ||
+ ", openingPrice=" | ||
+ openingPrice | ||
+ ", highPrice=" | ||
+ highPrice | ||
+ ", lowPrice=" | ||
+ lowPrice | ||
+ ", tracePrice=" | ||
+ tracePrice | ||
+ ", timestamp=" | ||
+ timestamp | ||
+ ", candleAccTradePrice=" | ||
+ candleAccTradePrice | ||
+ ", candleAccTradeVolume=" | ||
+ candleAccTradeVolume | ||
+ ", firstDayOfPeriod='" | ||
+ firstDayOfPeriod | ||
+ '\'' | ||
+ '}'; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
xchange-upbit/src/main/java/org/knowm/xchange/upbit/dto/trade/UpbitOrderRequest.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
Oops, something went wrong.
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.
you can use lombok for boilerplate-code here
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.
@bigscoop Thanks for the suggestion! I've used Lombok to simplify the code.