Skip to content

Commit 6aa73ed

Browse files
authored
Merge pull request #163 from CleanEngine/feat/trade-core
Feat/trade core
2 parents ace20d0 + 2229a56 commit 6aa73ed

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/main/java/com/cleanengine/coin/trade/application/TradeExecutor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,16 @@ public void executeTrade(WaitingOrders waitingOrders, TradePair<Order, Order> tr
7171
tradeService.updateOrder(sellOrder);
7272

7373
// 예수금 처리
74+
// - 매도 예수금 처리
75+
this.increaseAccountCash(sellOrder, totalTradedPrice);
76+
7477
// - 매수 잔여금액 반환
7578
if (!isMarketOrder(buyOrder) && buyOrder.getPrice() > tradedPrice) { // 매도 호가보다 높은 가격에 매수를 시도한 경우, 차액 반환
79+
log.debug("[{}] 매도 호가보다 높은 가격에 매수를 시도한 경우, 차액 반환", Thread.currentThread().threadId());
7680
double totalRefundAmount = (buyOrder.getPrice() - tradedPrice) * tradedSize;
7781
this.increaseAccountCash(buyOrder, totalRefundAmount);
7882
}
7983

80-
// - 매도 예수금 처리
81-
this.increaseAccountCash(sellOrder, totalTradedPrice);
82-
8384
// 지갑 누적계산
8485
this.updateWalletAfterTrade(buyOrder, ticker, tradedSize, totalTradedPrice);
8586
this.updateWalletAfterTrade(sellOrder, ticker, tradedSize, totalTradedPrice);

src/main/java/com/cleanengine/coin/user/info/application/AccountService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.cleanengine.coin.user.info.infra.WalletRepository;
77
import lombok.RequiredArgsConstructor;
88
import org.springframework.stereotype.Service;
9+
import org.springframework.transaction.annotation.Isolation;
910
import org.springframework.transaction.annotation.Transactional;
1011

1112
import java.util.Optional;
@@ -38,7 +39,7 @@ public Account createNewAccount(Integer userId, double cash) {
3839
return accountRepository.save(account);
3940
}
4041

41-
@Transactional
42+
@Transactional(isolation = Isolation.READ_COMMITTED)
4243
public void resetBot(String ticker) {
4344
Account sellBotAccount = accountRepository.findByUserId(SELL_ORDER_BOT_ID).orElseThrow();
4445
sellBotAccount.setCash(0.0);

0 commit comments

Comments
 (0)