quick end-to-end test
And some bug fixes too!
This commit is contained in:
52
e2e.sh
Executable file
52
e2e.sh
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
|
||||
BASE_URL="http://localhost:8080/api"
|
||||
|
||||
echo "=== E2E Pseudo Test ==="
|
||||
echo ""
|
||||
|
||||
echo "POST /api/orderupdate - Place SELL order"
|
||||
curl -s -X POST "$BASE_URL/orderupdate" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"delivery_start_time": "2024-01-15T10:00:00",
|
||||
"delivery_end_time": "2024-01-15T10:15:00",
|
||||
"order_side": "SELL",
|
||||
"quantity": 10,
|
||||
"price": 50.00
|
||||
}' | jq .
|
||||
echo ""
|
||||
|
||||
echo "POST /api/orderupdate - Place matching BUY order"
|
||||
curl -s -X POST "$BASE_URL/orderupdate" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"delivery_start_time": "2024-01-15T10:00:00",
|
||||
"delivery_end_time": "2024-01-15T10:15:00",
|
||||
"order_side": "BUY",
|
||||
"quantity": 5,
|
||||
"price": 50.00
|
||||
}' | jq .
|
||||
echo ""
|
||||
|
||||
echo "POST /api/orderupdate - Place another SELL order"
|
||||
curl -s -X POST "$BASE_URL/orderupdate" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"delivery_start_time": "2024-01-15T10:15:00",
|
||||
"delivery_end_time": "2024-01-15T10:30:00",
|
||||
"order_side": "SELL",
|
||||
"quantity": 20,
|
||||
"price": 45.00
|
||||
}' | jq .
|
||||
echo ""
|
||||
|
||||
echo "GET /api/market/overview - Get market overview"
|
||||
curl -s -X GET "$BASE_URL/market/overview" | jq .
|
||||
echo ""
|
||||
|
||||
echo "GET /api/purchases/average - Get average purchase price"
|
||||
curl -s -X GET "$BASE_URL/purchases/average" | jq .
|
||||
echo ""
|
||||
|
||||
echo "=== Done ==="
|
||||
@@ -2,16 +2,21 @@ package com.frankenergie.smartasset.service
|
||||
|
||||
import com.frankenergie.smartasset.domain.OrderBook
|
||||
import com.frankenergie.smartasset.model.DeliveryPeriod
|
||||
import com.frankenergie.smartasset.model.ExecutedPurchase
|
||||
import com.frankenergie.smartasset.model.MarketOverviewResponse
|
||||
import com.frankenergie.smartasset.model.OrderSide
|
||||
import com.frankenergie.smartasset.model.OrderUpdateRequest
|
||||
import com.frankenergie.smartasset.model.OrderUpdateResponse
|
||||
import com.frankenergie.smartasset.model.QuarterOverview
|
||||
import org.springframework.stereotype.Service
|
||||
import java.math.BigDecimal
|
||||
import java.time.Instant
|
||||
import java.util.UUID
|
||||
|
||||
@Service
|
||||
class OrderBookService {
|
||||
class OrderBookService(
|
||||
private val purchaseTrackerService: PurchaseTrackerService
|
||||
) {
|
||||
|
||||
private val orderBook = OrderBook()
|
||||
|
||||
@@ -21,13 +26,23 @@ class OrderBookService {
|
||||
val period = DeliveryPeriod(request.deliveryStartTime, request.deliveryEndTime)
|
||||
val matchedQuantity = orderBook.processOrder(period, request.orderSide, request.quantity, request.price)
|
||||
|
||||
val status = when {
|
||||
matchedQuantity == request.quantity -> "FILLED"
|
||||
matchedQuantity > java.math.BigDecimal.ZERO -> "PARTIALLY_FILLED"
|
||||
else -> "ACCEPTED"
|
||||
if (matchedQuantity > BigDecimal.ZERO && request.orderSide == OrderSide.BUY) {
|
||||
purchaseTrackerService.recordPurchase(
|
||||
ExecutedPurchase(
|
||||
groupId = "default",
|
||||
deliveryStart = request.deliveryStartTime,
|
||||
deliveryEnd = request.deliveryEndTime,
|
||||
quantity = matchedQuantity,
|
||||
pricePerMWh = request.price
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// TODO: write this to a file
|
||||
val status = when {
|
||||
matchedQuantity == request.quantity -> "FILLED"
|
||||
matchedQuantity > BigDecimal.ZERO -> "PARTIALLY_FILLED"
|
||||
else -> "ACCEPTED"
|
||||
}
|
||||
|
||||
return OrderUpdateResponse(orderId = orderId, status = status, timestamp = Instant.now())
|
||||
}
|
||||
|
||||
@@ -11,10 +11,12 @@ import java.time.LocalDateTime
|
||||
class OrderBookServiceTest {
|
||||
|
||||
private lateinit var service: OrderBookService
|
||||
private lateinit var purchaseTrackerService: PurchaseTrackerService
|
||||
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
service = OrderBookService()
|
||||
purchaseTrackerService = PurchaseTrackerService()
|
||||
service = OrderBookService(purchaseTrackerService)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user