Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -33,7 +33,6 @@ public class ApiScheduler {
private final CoinoneAPIClient coinoneAPIClient;
private final VWAPMetricsRecorder recorder;
private final MeterRegistry meterRegistry;
private String ticker;

// @Scheduled(fixedRate = 5000)
public void MarketAllRequest() throws InterruptedException {
Expand All @@ -48,7 +47,6 @@ public void MarketAllRequest() throws InterruptedException {
}

public void MarketDataRequest(String ticker){
this.ticker = ticker;
String rawJson = bithumbAPIClient.get(ticker); //api raw데이터
// String rawJson = getMarketDataWithFallback(ticker);
List<Ticks> gson = tickParser.parseGson(rawJson); //json을 list로 변환
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

@Slf4j
@Component
@Profile("h2-mem")
@Profile({"(dev & !it & !mariadb-local) | h2-mem"})
@RequiredArgsConstructor
public class H2UnitPriceRefresher implements ApplicationRunner {
private final UnitPriceRefresher unitPriceRefresher;

@Override
public void run(ApplicationArguments args){
log.info("Running Unit Price Refresher (h2-mem)...");
unitPriceRefresher.initializeUnitPrices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.cleanengine.coin.realitybot.parser.TickParserTest;
import com.cleanengine.coin.realitybot.service.PlatformVWAPServiceTest;
import com.cleanengine.coin.realitybot.service.TickServiceManagerTest;
import com.cleanengine.coin.realitybot.service.VWAPerrorInJectionSchedulerTest;
import com.cleanengine.coin.realitybot.vo.DeviationPricePolicyTest;
import com.cleanengine.coin.realitybot.vo.OrderPricePolicyTest;
import com.cleanengine.coin.realitybot.vo.UnitPricePolicyTest;
Expand All @@ -34,7 +33,6 @@
TicksTest.class,
TickParserTest.class,
OpeningPriceParserTest.class,
VWAPerrorInJectionSchedulerTest.class,
OrderPricePolicyTest.class,
DeviationPricePolicyTest.class
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
import com.cleanengine.coin.order.adapter.out.persistentce.asset.AssetRepository;
import com.cleanengine.coin.order.domain.Asset;
import com.cleanengine.coin.realitybot.domain.APIVWAPState;
import com.cleanengine.coin.realitybot.domain.VWAPMetricsRecorder;
import com.cleanengine.coin.realitybot.dto.Ticks;
import com.cleanengine.coin.realitybot.parser.TickParser;
import com.cleanengine.coin.realitybot.service.OrderGenerateService;
import com.cleanengine.coin.realitybot.service.TickServiceManager;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.List;
Expand All @@ -20,6 +25,7 @@
@ExtendWith(MockitoExtension.class)
public class ApiSchedulerTest {

@Spy
@InjectMocks
private ApiScheduler apiScheduler;

Expand All @@ -30,16 +36,32 @@ public class ApiSchedulerTest {
@Mock
private OrderGenerateService orderGenerateService;
@Mock
APIVWAPState apiVWAPState;
private APIVWAPState apiVWAPState;
@Mock
private TickServiceManager tickServiceManager;
@Mock
private AssetRepository assetRepository;
@Mock
private MeterRegistry meterRegistry;
@Mock
private Timer timer;
@Mock
private VWAPMetricsRecorder recorder;


@BeforeEach
void setUp() {
when(meterRegistry.timer(anyString())).thenReturn(timer);
// Timer의 record 메서드가 람다를 실행하도록 설정
doAnswer(invocation -> {
Runnable runnable = invocation.getArgument(0);
runnable.run();
return null;
}).when(timer).record(any(Runnable.class));
}

@Test
void marketAllRequestCallsAllTickers() throws InterruptedException {
// Given
List<Asset> assets = List.of(
new Asset("BTC", "비트코인", null),
new Asset("TRUMP", "트럼프", null),
Expand All @@ -53,26 +75,23 @@ void marketAllRequestCallsAllTickers() throws InterruptedException {
new Asset("WLD", "월드코인", null)
);
List<Ticks> testTicks = List.of(
new Ticks("BTC","2025-06-01","11:30:25","2025-06-01T11:30:25.123Z",95730000.0f,0.0082,95000000.0f,730000.0,"ASK",100001L),
new Ticks("ETH","2025-06-01","11:31:10","2025-06-01T11:31:10.456Z",4850000.0f,1.25,4800000.0f,50000.0,"BID",100002L),
new Ticks("DOGE","2025-06-01","11:32:45","2025-06-01T11:32:45.789Z",185.5f,9500.0,180.0f,5.5,"ASK", 100003L));
Ticks ticks = new Ticks("BTC","2025-06-01","11:30:25","2025-06-01T11:30:25.123Z",95730000.0f,0.0082,95000000.0f,730000.0,"ASK",100001L);
//given
new Ticks("BTC", "2025-06-01", "11:30:25", "2025-06-01T11:30:25.123Z", 95730000.0f, 0.0082, 95000000.0f, 730000.0, "ASK", 100001L),
new Ticks("ETH", "2025-06-01", "11:31:10", "2025-06-01T11:31:10.456Z", 4850000.0f, 1.25, 4800000.0f, 50000.0, "BID", 100002L),
new Ticks("DOGE", "2025-06-01", "11:32:45", "2025-06-01T11:32:45.789Z", 185.5f, 9500.0, 180.0f, 5.5, "ASK", 100003L)
);

when(assetRepository.findAll()).thenReturn(assets);
when(apiClient.get(anyString())).thenReturn("[{data:...}]");
when(tickParser.parseGson(anyString())).thenReturn(testTicks);
when(tickServiceManager.getService(anyString())).thenReturn(apiVWAPState);
doNothing().when(apiVWAPState).addTick(any());
System.out.println(assets.size());
//when
doNothing().when(recorder).recordApiVwap(anyString(),anyDouble());

// When
apiScheduler.MarketAllRequest();

//then
// verify(apiScheduler,times(assets.size())).MarketDataRequest(anyString());
// Then
verify(apiScheduler, times(assets.size())).MarketDataRequest(anyString());
verify(orderGenerateService,times(assets.size())).generateOrder(anyString(),anyDouble(),anyDouble());
}

@Test
void marketDataRequest() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cleanengine.coin.realitybot.domain.PlatformVWAPState;
import com.cleanengine.coin.trade.entity.Trade;
import com.cleanengine.coin.trade.repository.TradeRepository;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -22,6 +23,9 @@ public class PlatformVWAPServiceTest {
@InjectMocks
private PlatformVWAPService platformVWAPService;

@Mock
private TradeRepository tradeRepository;

@Mock
private PlatformVWAPState platformVwapState;

Expand All @@ -36,6 +40,7 @@ void testCalculateVWAPLessThan10Trades() {
new Trade(3, "BTC", LocalDateTime.now(), 2, 1, 12000.0, 10.0) // 120000
);//이게 적용되면 10000원대
double apiVWAP = 1000.0; //0.1%의 보정값
when(tradeRepository.findTop10ByTickerOrderByTradeTimeDesc(ticker)).thenReturn(trades);

//when
double result = platformVWAPService.calculateVWAPbyTrades(ticker, apiVWAP);
Expand Down Expand Up @@ -64,8 +69,10 @@ void testCalculateVWAPMoreThan10Trades() {
new Trade(11, "BTC", LocalDateTime.now(), 2, 1, 20000.0, 10.0) // 200000
);
double apiVWAP = 1000.0;
when(tradeRepository.findTop10ByTickerOrderByTradeTimeDesc(ticker)).thenReturn(trades);
when(platformVwapState.getVWAP()).thenReturn(15000.0);
platformVWAPService.vwapMap.put(ticker, platformVwapState);

//when
double result = platformVWAPService.calculateVWAPbyTrades(ticker, apiVWAP);

Expand Down

This file was deleted.

This file was deleted.

Loading