Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -13,7 +13,6 @@
import io.micrometer.core.instrument.Timer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
Expand All @@ -37,7 +36,7 @@ public class ApiScheduler {
private final MeterRegistry meterRegistry;
private String ticker;

@Scheduled(fixedRate = 5000)
// @Scheduled(fixedRate = 5000)
public void MarketAllRequest() throws InterruptedException {
Timer timer = meterRegistry.timer("apischeduler.request.duration");
timer.record(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import com.cleanengine.coin.realitybot.vo.UnitPricePolicy;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
Expand All @@ -19,19 +16,13 @@
@Slf4j
@Component
@RequiredArgsConstructor
public class UnitPriceRefresher implements ApplicationRunner {
public class UnitPriceRefresher {
private final UnitPricePolicy unitPricePolicy;
private final AssetRepository assetRepository;
private final BithumbAPIClient bithumbAPIClient;
private final OpeningPriceParser openingPriceParser;
private final Map<String ,Double> unitPriceCache = new ConcurrentHashMap<>();

@Override
public void run(ApplicationArguments args){
log.info("Running Unit Price Refresher...");
initializeUnitPrices();
}

public void initializeUnitPrices() {
List<Asset> tickers = assetRepository.findAll();
for (Asset ticker : tickers){
Expand All @@ -40,16 +31,6 @@ public void initializeUnitPrices() {
}
}

@Scheduled(cron = "${bot-handler.corn}")
public void refreshUnitPrices() {
initializeUnitPrices();
// List<Asset> tickers = assetRepository.findAll();
// for (Asset ticker : tickers){
// double unitPrice = fetchOpeningPriceFromAPI(ticker.getTicker());
// unitPriceCache.put(ticker.getTicker(),unitPrice);
// }

}

private double fetchOpeningPriceFromAPI(String ticker) {
String rawJson = bithumbAPIClient.getOpeningPrice(ticker); //api raw데이터
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.cleanengine.coin.realitybot.config;

import com.cleanengine.coin.realitybot.api.ApiScheduler;
import com.cleanengine.coin.realitybot.api.UnitPriceRefresher;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
Expand All @@ -18,17 +19,31 @@ public class SchedulerConfig implements SchedulingConfigurer {
// @Autowired
// private TaskScheduler apiScheduler;
private final ApiScheduler apiScheduler;
private final UnitPriceRefresher unitPriceRefresher;
@Value("${bot-handler.cron}")
private final String cron;
@Value("${bot-handler.fixed-rate}")
private final Duration fixedRate;

protected SchedulerConfig(ApiScheduler apiScheduler, @Value("${bot-handler.fixed-rate}") Duration fixedRate) {
protected SchedulerConfig(ApiScheduler apiScheduler, @Value("${bot-handler.fixed-rate}") Duration fixedRate, UnitPriceRefresher unitPriceRefresher,
@Value("${bot-handler.cron}")String cron) {
this.apiScheduler = apiScheduler;
this.fixedRate = fixedRate;
this.unitPriceRefresher = unitPriceRefresher;
this.cron = cron;
}

@Override
public void configureTasks(ScheduledTaskRegistrar registrar) {
// registrar.setScheduler(apiScheduler); //멀티 쓰레드 x
unitPriceRefresher.initializeUnitPrices(); //선반영

registrar.addCronTask(() -> {
try {
unitPriceRefresher.initializeUnitPrices();
} catch (Exception e) {
throw new RuntimeException(e);
}
}, cron);
registrar.addFixedRateTask(() -> {
try {
apiScheduler.MarketAllRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import com.cleanengine.coin.order.application.event.OrderInsertedToQueue;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;

@Slf4j
@Component
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ server:

bot-handler:
fixed-rate: 5000 # 5초마다 실행
corn : "0 0 0 * * *" # 매일 자정마다 호가
cron : "0 0 0 * * *" # 매일 자정마다 호가
order-level : 1,2,3,4,5 #오더북 단계 설정 - 주문량 증가
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.cleanengine.coin.realitybot.api.ApiSchedulerTest;
import com.cleanengine.coin.realitybot.api.BithumbAPIClientTest;
import com.cleanengine.coin.realitybot.api.RefresherRunnerTest;
import com.cleanengine.coin.realitybot.api.UnitPriceRefresherTest;
import com.cleanengine.coin.realitybot.config.ApiClientConfigTest;
import com.cleanengine.coin.realitybot.config.SchedulerConfigTest;
import com.cleanengine.coin.realitybot.domain.APIVWAPStateTest;
import com.cleanengine.coin.realitybot.domain.PlatformVWAPStateTest;
import com.cleanengine.coin.realitybot.domain.VWAPCalculatorTest;
Expand All @@ -24,13 +21,10 @@

@Suite
@SelectClasses({
RefresherRunnerTest.class,
BithumbAPIClientTest.class,
UnitPriceRefresherTest.class,
OpeningPriceTest.class,
PlatformVWAPStateTest.class,
UnitPricePolicyTest.class,
SchedulerConfigTest.class,
ApiSchedulerTest.class,
ApiClientConfigTest.class,
PlatformVWAPServiceTest.class,
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading