모의투자 로직 변경
This commit is contained in:
@@ -19,37 +19,32 @@ public class PaperTradingController {
|
||||
|
||||
private final PaperTradingService paperTradingService;
|
||||
|
||||
private Long userId(Map<String, String> h) {
|
||||
String v = h.get("x-user-id");
|
||||
return v != null ? Long.parseLong(v) : null;
|
||||
}
|
||||
|
||||
private String deviceId(Map<String, String> h) {
|
||||
return h.getOrDefault("x-device-id", "anonymous");
|
||||
}
|
||||
|
||||
@GetMapping("/summary")
|
||||
public ResponseEntity<PaperSummaryDto> summary(@RequestHeader Map<String, String> h) {
|
||||
return ResponseEntity.ok(paperTradingService.getSummary(userId(h), deviceId(h), null));
|
||||
long uid = TradingControllerSupport.requireRegisteredUser(h);
|
||||
return ResponseEntity.ok(paperTradingService.getSummary(uid, null));
|
||||
}
|
||||
|
||||
@PostMapping("/summary")
|
||||
public ResponseEntity<PaperSummaryDto> summaryWithMarks(
|
||||
@RequestHeader Map<String, String> h,
|
||||
@RequestBody(required = false) Map<String, Double> markPrices) {
|
||||
return ResponseEntity.ok(paperTradingService.getSummary(userId(h), deviceId(h), markPrices));
|
||||
long uid = TradingControllerSupport.requireRegisteredUser(h);
|
||||
return ResponseEntity.ok(paperTradingService.getSummary(uid, markPrices));
|
||||
}
|
||||
|
||||
@GetMapping("/allocations")
|
||||
public ResponseEntity<List<PaperAllocationDto>> allocations(@RequestHeader Map<String, String> h) {
|
||||
return ResponseEntity.ok(paperTradingService.listAllocations(userId(h), deviceId(h), null));
|
||||
long uid = TradingControllerSupport.requireRegisteredUser(h);
|
||||
return ResponseEntity.ok(paperTradingService.listAllocations(uid, null));
|
||||
}
|
||||
|
||||
@PutMapping("/allocations/bulk")
|
||||
public ResponseEntity<List<PaperAllocationDto>> bulkAllocations(
|
||||
@RequestHeader Map<String, String> h,
|
||||
@RequestBody PaperAllocationBulkRequest body) {
|
||||
return ResponseEntity.ok(paperTradingService.bulkAllocations(userId(h), deviceId(h), body));
|
||||
long uid = TradingControllerSupport.requireRegisteredUser(h);
|
||||
return ResponseEntity.ok(paperTradingService.bulkAllocations(uid, body));
|
||||
}
|
||||
|
||||
@PatchMapping("/allocations/{symbol}")
|
||||
@@ -57,7 +52,8 @@ public class PaperTradingController {
|
||||
@RequestHeader Map<String, String> h,
|
||||
@PathVariable String symbol,
|
||||
@RequestBody PaperAllocationPatchRequest body) {
|
||||
return ResponseEntity.ok(paperTradingService.patchAllocation(userId(h), deviceId(h), symbol, body));
|
||||
long uid = TradingControllerSupport.requireRegisteredUser(h);
|
||||
return ResponseEntity.ok(paperTradingService.patchAllocation(uid, symbol, body));
|
||||
}
|
||||
|
||||
@GetMapping("/trades")
|
||||
@@ -70,12 +66,13 @@ public class PaperTradingController {
|
||||
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime to,
|
||||
@RequestParam(defaultValue = "0") int page,
|
||||
@RequestParam(required = false) Integer size) {
|
||||
long uid = TradingControllerSupport.requireRegisteredUser(h);
|
||||
if (size == null && symbol == null && side == null && source == null && from == null && to == null) {
|
||||
return ResponseEntity.ok(paperTradingService.listTradesLegacy(userId(h), deviceId(h)));
|
||||
return ResponseEntity.ok(paperTradingService.listTradesLegacy(uid));
|
||||
}
|
||||
int pageSize = size != null ? size : 50;
|
||||
return ResponseEntity.ok(paperTradingService.listTrades(
|
||||
userId(h), deviceId(h), symbol, side, source, from, to, page, pageSize));
|
||||
uid, symbol, side, source, from, to, page, pageSize));
|
||||
}
|
||||
|
||||
@GetMapping("/ledger")
|
||||
@@ -85,7 +82,8 @@ public class PaperTradingController {
|
||||
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime to,
|
||||
@RequestParam(defaultValue = "0") int page,
|
||||
@RequestParam(defaultValue = "50") int size) {
|
||||
return ResponseEntity.ok(paperTradingService.listLedger(userId(h), deviceId(h), from, to, page, size));
|
||||
long uid = TradingControllerSupport.requireRegisteredUser(h);
|
||||
return ResponseEntity.ok(paperTradingService.listLedger(uid, from, to, page, size));
|
||||
}
|
||||
|
||||
@GetMapping("/snapshots/daily")
|
||||
@@ -93,30 +91,35 @@ public class PaperTradingController {
|
||||
@RequestHeader Map<String, String> h,
|
||||
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate from,
|
||||
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate to) {
|
||||
return ResponseEntity.ok(paperTradingService.listDailySnapshots(userId(h), deviceId(h), from, to));
|
||||
long uid = TradingControllerSupport.requireRegisteredUser(h);
|
||||
return ResponseEntity.ok(paperTradingService.listDailySnapshots(uid, from, to));
|
||||
}
|
||||
|
||||
@GetMapping("/orders")
|
||||
public ResponseEntity<List<PaperOrderDto>> pendingOrders(@RequestHeader Map<String, String> h) {
|
||||
return ResponseEntity.ok(paperTradingService.listPendingOrders(userId(h), deviceId(h)));
|
||||
long uid = TradingControllerSupport.requireRegisteredUser(h);
|
||||
return ResponseEntity.ok(paperTradingService.listPendingOrders(uid));
|
||||
}
|
||||
|
||||
@PostMapping("/orders")
|
||||
public ResponseEntity<PaperPlaceOrderResult> placeOrder(
|
||||
@RequestHeader Map<String, String> h,
|
||||
@RequestBody PaperOrderRequest body) {
|
||||
return ResponseEntity.ok(paperTradingService.placeOrder(userId(h), deviceId(h), body));
|
||||
long uid = TradingControllerSupport.requireRegisteredUser(h);
|
||||
return ResponseEntity.ok(paperTradingService.placeOrder(uid, body));
|
||||
}
|
||||
|
||||
@PostMapping("/orders/{id}/cancel")
|
||||
public ResponseEntity<PaperOrderDto> cancelOrder(
|
||||
@RequestHeader Map<String, String> h,
|
||||
@PathVariable Long id) {
|
||||
return ResponseEntity.ok(paperTradingService.cancelOrder(userId(h), deviceId(h), id));
|
||||
long uid = TradingControllerSupport.requireRegisteredUser(h);
|
||||
return ResponseEntity.ok(paperTradingService.cancelOrder(uid, id));
|
||||
}
|
||||
|
||||
@PostMapping("/reset")
|
||||
public ResponseEntity<PaperSummaryDto> reset(@RequestHeader Map<String, String> h) {
|
||||
return ResponseEntity.ok(paperTradingService.resetAccount(userId(h), deviceId(h)));
|
||||
long uid = TradingControllerSupport.requireRegisteredUser(h);
|
||||
return ResponseEntity.ok(paperTradingService.resetAccount(uid));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user