stock-tracker
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import axios from 'axios'
|
||||
import type {
|
||||
StockItem, KlineItem, RealtimeQuote,
|
||||
Collection, CollectionListItem, StockInput,
|
||||
ShareResponse, CollectionShare,
|
||||
} from '../types'
|
||||
|
||||
const http = axios.create({ baseURL: '/api' })
|
||||
|
||||
// --- Stock ---
|
||||
export const searchStocks = (q: string) =>
|
||||
http.get<{ data: StockItem[] }>('/stocks/search', { params: { q, limit: 20 } }).then(r => r.data.data)
|
||||
|
||||
export const getKline = (code: string, months = 12) =>
|
||||
http.get<{ data: KlineItem[] }>(`/stocks/kline/${code}`, { params: { months } }).then(r => r.data.data)
|
||||
|
||||
export const getRealtime = (code: string) =>
|
||||
http.get<{ data: RealtimeQuote | null }>(`/stocks/realtime/${code}`).then(r => r.data.data)
|
||||
|
||||
// --- Collection ---
|
||||
export const listCollections = () =>
|
||||
http.get<CollectionListItem[]>('/collections').then(r => r.data)
|
||||
|
||||
export const getCollection = (id: number) =>
|
||||
http.get<Collection>(`/collections/${id}`).then(r => r.data)
|
||||
|
||||
export const createCollection = (name: string, stocks: StockInput[]) =>
|
||||
http.post<Collection>('/collections', { name, stocks }).then(r => r.data)
|
||||
|
||||
export const updateCollection = (id: number, name: string) =>
|
||||
http.put<Collection>(`/collections/${id}`, { name }).then(r => r.data)
|
||||
|
||||
export const deleteCollection = (id: number) =>
|
||||
http.delete(`/collections/${id}`).then(r => r.data)
|
||||
|
||||
export const addStock = (colId: number, data: StockInput) =>
|
||||
http.post(`/collections/${colId}/stocks`, data).then(r => r.data)
|
||||
|
||||
export const removeStock = (colId: number, code: string) =>
|
||||
http.delete(`/collections/${colId}/stocks/${code}`).then(r => r.data)
|
||||
|
||||
export const shareCollection = (id: number) =>
|
||||
http.post<ShareResponse>(`/collections/${id}/share`).then(r => r.data)
|
||||
|
||||
// --- Share ---
|
||||
export const getSharedCollection = (shortCode: string) =>
|
||||
http.get<CollectionShare>(`/s/${shortCode}`).then(r => r.data)
|
||||
Reference in New Issue
Block a user