Skip to content

Commit

Permalink
#11 Provides a price entry for every trade record
Browse files Browse the repository at this point in the history
  • Loading branch information
preslavrachev committed Aug 26, 2017
1 parent b405548 commit fec784c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,22 @@ class CryptotraderApplication {
LOGGER.info("Candlestick Pattern Strategy Decision: $decision -- time period $start/$end")

if (decision == TradingStrategyDecisionEnum.BUY) {
val trade = TradeRecord(amount = 0.00001f, quoteCurrency = "BTC", baseCurrency = "USDT", orderType = OrderTypeEnum.BUY)
val trade = TradeRecord(
amount = 0.00001f,
quoteCurrency = "BTC",
baseCurrency = "USDT",
baseCurrencyPrice = lastPair[0].content.estimateBuyingPrice(),
orderType = OrderTypeEnum.BUY
)
tradeRecordRepository.save(trade)
} else if (decision == TradingStrategyDecisionEnum.SELL) {
val trade = TradeRecord(amount = 0.00001f, quoteCurrency = "BTC", baseCurrency = "USDT", orderType = OrderTypeEnum.SELL)
val trade = TradeRecord(
amount = 0.00001f,
quoteCurrency = "BTC",
baseCurrency = "USDT",
baseCurrencyPrice = lastPair[0].content.estimateSellingPrice(),
orderType = OrderTypeEnum.SELL
)
tradeRecordRepository.save(trade)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ data class TradeRecord(
val amount: Float, /* always in relation to the quote currency */
val quoteCurrency: String, /* e.g. BTC in BTC/USDT */
val baseCurrency: String, /* e.g. USDT in BTC/USDT */
val baseCurrencyPrice: Float,
val executionDateTime: LocalDateTime = LocalDateTime.now(),
val orderType: OrderTypeEnum,
val orderScope: OrderScopeEnum = OrderScopeEnum.DEMO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@ data class Candlestick(
fun isBodyTop(): Boolean {
return bodyMidpoint() >= (MAX_HEIGHT_RATIO * shadowHeight())
}

fun estimateBuyingPrice(): Float {
return Math.min(open, close)
}

fun estimateSellingPrice(): Float {
return Math.max(open, close)
}
}

0 comments on commit fec784c

Please sign in to comment.