-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4823 from aaron-jang/develop
[Upbit] add support for market orders and candlestick
- Loading branch information
Showing
14 changed files
with
286 additions
and
61 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
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
48 changes: 48 additions & 0 deletions
48
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,48 @@ | ||
package org.knowm.xchange.upbit.dto.marketdata; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.math.BigDecimal; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
@ToString | ||
@Getter | ||
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; | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
xchange-upbit/src/main/java/org/knowm/xchange/upbit/service/UpbitCandleStickPeriodType.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,43 @@ | ||
package org.knowm.xchange.upbit.service; | ||
|
||
public enum UpbitCandleStickPeriodType { | ||
WEEK("weeks", 60 * 60 * 24 * 7), | ||
DAY("days", 60 * 60 * 24), | ||
MINUTE("minutes", 60); | ||
|
||
private final String pathName; | ||
private final Integer periodInSeconds; | ||
|
||
UpbitCandleStickPeriodType(String pathName, Integer periodInSeconds) { | ||
this.pathName = pathName; | ||
this.periodInSeconds = periodInSeconds; | ||
} | ||
|
||
public String getPathName() { | ||
return pathName; | ||
} | ||
|
||
static UpbitCandleStickPeriodType getPeriodTypeFromSecs(long seconds) { | ||
UpbitCandleStickPeriodType result = null; | ||
for (UpbitCandleStickPeriodType period : UpbitCandleStickPeriodType.values()) { | ||
if (seconds % period.periodInSeconds == 0) { | ||
result = period; | ||
break; | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
public static long[] getSupportedPeriodsInSecs() { | ||
long[] result = new long[UpbitCandleStickPeriodType.values().length]; | ||
int index = 0; | ||
for (UpbitCandleStickPeriodType period : UpbitCandleStickPeriodType.values()) { | ||
result[index++] = period.periodInSeconds; | ||
} | ||
return result; | ||
} | ||
|
||
public long getUnitCount(long seconds) { | ||
return seconds / periodInSeconds; | ||
} | ||
} |
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.