mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
159 lines
3.7 KiB
TypeScript
159 lines
3.7 KiB
TypeScript
import axios from 'axios';
|
|
|
|
const baseURL =
|
|
process.env.NODE_ENV === 'development' ? 'http://localhost:8080' : '';
|
|
|
|
export function ping(cb) {
|
|
return axios.get(baseURL + '/api/ping').then((response) => {
|
|
cb(response.data);
|
|
});
|
|
}
|
|
|
|
export function queryOutboundIP(cb) {
|
|
return axios.get<any>(baseURL + '/api/outbound-ip').then((response) => {
|
|
cb(response.data.outboundIP);
|
|
});
|
|
}
|
|
|
|
export async function triggerSync() {
|
|
return axios.post<any>(baseURL + '/api/environment/sync');
|
|
}
|
|
|
|
export enum SyncStatus {
|
|
SyncNotStarted = 0,
|
|
Syncing = 1,
|
|
SyncDone = 2,
|
|
}
|
|
|
|
export async function querySyncStatus(): Promise<SyncStatus> {
|
|
const resp = await axios.get<any>(baseURL + '/api/environment/syncing');
|
|
return resp.data.syncing;
|
|
}
|
|
|
|
export function testDatabaseConnection(params, cb) {
|
|
return axios.post(baseURL + '/api/setup/test-db', params).then((response) => {
|
|
cb(response.data);
|
|
});
|
|
}
|
|
|
|
export function configureDatabase(params, cb) {
|
|
return axios
|
|
.post(baseURL + '/api/setup/configure-db', params)
|
|
.then((response) => {
|
|
cb(response.data);
|
|
});
|
|
}
|
|
|
|
export function saveConfig(cb) {
|
|
return axios.post(baseURL + '/api/setup/save').then((response) => {
|
|
cb(response.data);
|
|
});
|
|
}
|
|
|
|
export function setupRestart(cb) {
|
|
return axios.post(baseURL + '/api/setup/restart').then((response) => {
|
|
cb(response.data);
|
|
});
|
|
}
|
|
|
|
export function addSession(session, cb) {
|
|
return axios.post(baseURL + '/api/sessions', session).then((response) => {
|
|
cb(response.data || []);
|
|
});
|
|
}
|
|
|
|
export function attachStrategyOn(session, strategyID, strategy, cb) {
|
|
return axios
|
|
.post(
|
|
baseURL + `/api/setup/strategy/single/${strategyID}/session/${session}`,
|
|
strategy
|
|
)
|
|
.then((response) => {
|
|
cb(response.data);
|
|
});
|
|
}
|
|
|
|
export function testSessionConnection(session, cb) {
|
|
return axios
|
|
.post(baseURL + '/api/sessions/test', session)
|
|
.then((response) => {
|
|
cb(response.data);
|
|
});
|
|
}
|
|
|
|
export function queryStrategies(cb) {
|
|
return axios.get<any>(baseURL + '/api/strategies/single').then((response) => {
|
|
cb(response.data.strategies || []);
|
|
});
|
|
}
|
|
|
|
export function querySessions(cb) {
|
|
return axios.get<any>(baseURL + '/api/sessions', {}).then((response) => {
|
|
cb(response.data.sessions || []);
|
|
});
|
|
}
|
|
|
|
export function querySessionSymbols(sessionName, cb) {
|
|
return axios
|
|
.get<any>(baseURL + `/api/sessions/${sessionName}/symbols`, {})
|
|
.then((response) => {
|
|
cb(response.data?.symbols || []);
|
|
});
|
|
}
|
|
|
|
export function queryTrades(params, cb) {
|
|
axios
|
|
.get<any>(baseURL + '/api/trades', { params: params })
|
|
.then((response) => {
|
|
cb(response.data.trades || []);
|
|
});
|
|
}
|
|
|
|
export function queryClosedOrders(params, cb) {
|
|
axios
|
|
.get<any>(baseURL + '/api/orders/closed', { params: params })
|
|
.then((response) => {
|
|
cb(response.data.orders || []);
|
|
});
|
|
}
|
|
|
|
export function queryAssets(cb) {
|
|
axios.get<any>(baseURL + '/api/assets', {}).then((response) => {
|
|
cb(response.data.assets || []);
|
|
});
|
|
}
|
|
|
|
export function queryTradingVolume(params, cb) {
|
|
axios
|
|
.get<any>(baseURL + '/api/trading-volume', { params: params })
|
|
.then((response) => {
|
|
cb(response.data.tradingVolumes || []);
|
|
});
|
|
}
|
|
|
|
export async function queryStrategiesMetrics() {
|
|
return [
|
|
{
|
|
id: 'uuid',
|
|
instanceID: 'testInstanceID',
|
|
strategy: 'grid',
|
|
grid: {
|
|
symbol: 'BTCUSDT',
|
|
},
|
|
stats: {
|
|
oneDayArbs: 0,
|
|
totalArbs: 3,
|
|
investment: 100,
|
|
totalProfits: 5.6,
|
|
gridProfits: 2.5,
|
|
floatingPNL: 3.1,
|
|
currentPrice: 29000,
|
|
lowestPrice: 25000,
|
|
highestPrice: 35000,
|
|
},
|
|
status: 'RUNNING',
|
|
startTime: 1654938187102,
|
|
},
|
|
];
|
|
}
|