const { asyncHandler } = require('../middleware/errorHandler');
const ApiResponse = require("../utils/apiResponse");
const spotService = require("../services/spotService");

exports.getSpotData = asyncHandler(async (req, res) => {
  const markets = await spotService.getSpotData(req.user.id);
  ApiResponse.success(res, markets );
})

exports.tradeSpot = asyncHandler(async (req, res) => {
  const result = await spotService.tradeSpot(req.user.id, req.body);
  ApiResponse.success(res, result);
});

exports.cancelSpotOrder = asyncHandler(async (req, res) => {
  const result = await spotService.cancelSpotOrder(req.user.id, req.params.id);
  ApiResponse.success(res, result);
});

exports.getOpenSpotOrders = asyncHandler(async (req, res) => {
  const result = await spotService.getOpenSpotOrders(req.user.id, req.query);
  ApiResponse.success(res, result);
});

exports.getSpotOrderHistory = asyncHandler(async (req, res) => {
  const result = await spotService.getSpotOrderHistory(req.user.id, req.query);
  ApiResponse.success(res, result);
});

exports.getSpotTrades = asyncHandler(async (req, res) => {
  const result = await spotService.getSpotTrades(req.user.id, req.query);
  ApiResponse.success(res, result);
});

exports.getSpotOrderBook = asyncHandler(async (req, res) => {
  const result = await spotService.getSpotOrderBook(req.query);
  ApiResponse.success(res, result);
});
