update refactor
This commit is contained in:
parent
01abc7e446
commit
55ad0607f3
39 changed files with 4304 additions and 584 deletions
11
src/handlers/candleHandler.ts
Normal file
11
src/handlers/candleHandler.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { BybitService } from '../services/bybitService';
|
||||
import * as indicatorService from '../services/indicatorService';
|
||||
|
||||
export const analyzeCandles = async (req: Request, res: Response) => {
|
||||
const { symbol, interval } = req.params;
|
||||
const bybitService = new BybitService(process.env.BYBIT_API_KEY!, process.env.BYBIT_API_SECRET!);
|
||||
const candles = await bybitService.getCandles({ symbol, interval: '5', category: 'linear', limit: 200 });
|
||||
const analysis = indicatorService.analyze(candles);
|
||||
res.json(analysis);
|
||||
};
|
||||
21
src/handlers/orderHandler.ts
Normal file
21
src/handlers/orderHandler.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { BybitService } from '../services/bybitService';
|
||||
|
||||
const bybitService = new BybitService(process.env.BYBIT_API_KEY!, process.env.BYBIT_API_SECRET!);
|
||||
|
||||
export const createOrder = async (req: Request, res: Response) => {
|
||||
// TODO: Lấy client từ credential
|
||||
const order = await bybitService.createOrder(req.body);
|
||||
res.json(order);
|
||||
};
|
||||
|
||||
export const listOrders = async (req: Request, res: Response) => {
|
||||
const orders = await bybitService.listOrders({ category: 'linear' });
|
||||
res.json(orders);
|
||||
};
|
||||
|
||||
export const cancelOrder = async (req: Request, res: Response) => {
|
||||
const { orderId } = req.params;
|
||||
const result = await bybitService.cancelOrder({ orderId, symbol: 'BTCUSDT', category: 'linear' });
|
||||
res.json(result);
|
||||
};
|
||||
8
src/handlers/positionHandler.ts
Normal file
8
src/handlers/positionHandler.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { BybitService } from '../services/bybitService';
|
||||
|
||||
export const listPositions = async (req: Request, res: Response) => {
|
||||
const bybitService = new BybitService(process.env.BYBIT_API_KEY!, process.env.BYBIT_API_SECRET!);
|
||||
const positions = await bybitService.listPositions({ category: 'linear' });
|
||||
res.json(positions);
|
||||
};
|
||||
14
src/handlers/userHandler.ts
Normal file
14
src/handlers/userHandler.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { Request, Response } from 'express';
|
||||
import * as supabaseService from '../services/supabaseService';
|
||||
|
||||
export const saveCredential = async (req: Request, res: Response) => {
|
||||
const { userId, apiKey, apiSecret } = req.body;
|
||||
const result = await supabaseService.saveBybitCredential(userId, apiKey, apiSecret);
|
||||
res.json(result);
|
||||
};
|
||||
|
||||
export const getCredential = async (req: Request, res: Response) => {
|
||||
const { userId } = req.params;
|
||||
const result = await supabaseService.getBybitCredential(userId);
|
||||
res.json(result);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue