File size: 3,077 Bytes
590a501
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import axios from 'axios'

const api = axios.create({
  baseURL: '/api',
  timeout: 10000,
})

export const marketApi = {
  getQuotes: (params) => api.get('/market/quotes', { params }),
  getKlines: (symbol, limit = 200, interval = '1m') => api.get(`/market/klines/${encodeURIComponent(symbol)}?interval=${interval}&limit=${limit}`),
  getContracts: (params) => api.get('/market/contracts', { params }),
  getExchanges: () => api.get('/market/exchanges'),
  getCategories: () => api.get('/market/categories'),
  getContractDetail: (symbol) => api.get(`/market/contract/${encodeURIComponent(symbol)}`),
  getMode: () => api.get('/market/mode'),
  setMode: (mode) => api.post(`/market/mode?mode=${mode}`),
}

export const orderApi = {
  placeOrder: (data) => api.post('/orders', data),
  getOrders: (symbol) => api.get('/orders', { params: { symbol } }),
  cancelOrder: (orderId) => api.delete(`/orders/${orderId}`),
}

export const positionApi = {
  getPositions: () => api.get('/positions'),
}

export const accountApi = {
  getAccount: () => api.get('/account'),
}

export const tradeApi = {
  getTrades: (limit = 100) => api.get(`/trades?limit=${limit}`),
}

export const strategyApi = {
  getAvailable: () => api.get('/strategies/available'),
  getStrategies: () => api.get('/strategies'),
  addStrategy: (config) => api.post('/strategies', config),
  startStrategy: (id) => api.post(`/strategies/${id}/start`),
  stopStrategy: (id) => api.post(`/strategies/${id}/stop`),
  removeStrategy: (id) => api.delete(`/strategies/${id}`),
  getSignals: (id) => api.get(`/strategies/${id}/signals`),
  getPerformance: (id) => api.get(`/strategies/${id}/performance`),
}

export const riskApi = {
  getMetrics: () => api.get('/risk'),
}

export const patternApi = {
  getRegistry: () => api.get('/patterns/registry'),
  detect: (symbol, interval = '1m', limit = 200, patterns = null) => {
    let url = `/patterns/detect/${encodeURIComponent(symbol)}?interval=${interval}&limit=${limit}`
    if (patterns) url += `&patterns=${patterns}`
    return api.get(url)
  },
}

export const backtestApi = {
  getTemplates: () => api.get('/backtest/templates'),
  run: (payload) => api.post('/backtest/run', payload),
}

export const platformApi = {
  listServices: () => api.get('/platform/services'),
  getService: (id) => api.get(`/platform/services/${id}`),
  startService: (id) => api.post(`/platform/services/${id}/start`),
  stopService: (id) => api.post(`/platform/services/${id}/stop`),
  startAll: () => api.post('/platform/services/start-all'),
}

export const researchApi = {
  health: () => api.get('/research/health'),
  listFactors: () => api.get('/research/factors'),
  computeFactor: (name) => api.post(`/research/factors/${encodeURIComponent(name)}/compute`),
  backtestFactor: (name, body) => api.post(`/research/factors/${encodeURIComponent(name)}/backtest`, body),
  listOperators: () => api.get('/research/operators'),
  buildExpression: (body) => api.post('/research/operators/build', body),
  listStrategies: () => api.get('/research/strategies'),
}

export default api