bbgo_origin/apps/frontend/api/bbgo.ts

191 lines
4.2 KiB
TypeScript
Raw Normal View History

2022-06-11 00:57:54 +00:00
import axios from 'axios';
2021-01-25 09:40:37 +00:00
2022-06-11 00:57:54 +00:00
const baseURL =
process.env.NODE_ENV === 'development' ? 'http://localhost:8080' : '';
2021-01-25 09:40:37 +00:00
2021-02-04 12:21:16 +00:00
export function ping(cb) {
2022-06-11 00:57:54 +00:00
return axios.get(baseURL + '/api/ping').then((response) => {
cb(response.data);
});
2021-02-04 12:21:16 +00:00
}
2022-04-14 02:19:22 +00:00
export function queryOutboundIP(cb) {
2022-06-14 04:36:10 +00:00
return axios.get<any>(baseURL + '/api/outbound-ip').then((response) => {
2022-06-11 00:57:54 +00:00
cb(response.data.outboundIP);
});
2022-04-14 02:19:22 +00:00
}
2022-06-15 03:33:40 +00:00
export async function triggerSync() {
2022-06-14 07:33:22 +00:00
return axios.post<any>(baseURL + '/api/environment/sync');
2022-06-15 11:02:24 +00:00
}
2022-06-14 04:36:10 +00:00
2022-06-15 03:33:40 +00:00
export enum SyncStatus {
SyncNotStarted = 0,
Syncing = 1,
2022-06-15 11:02:24 +00:00
SyncDone = 2,
2022-06-15 03:33:40 +00:00
}
2022-06-14 04:36:10 +00:00
2022-06-15 03:33:40 +00:00
export async function querySyncStatus(): Promise<SyncStatus> {
2022-06-15 11:02:24 +00:00
const resp = await axios.get<any>(baseURL + '/api/environment/syncing');
return resp.data.syncing;
2021-02-21 10:08:22 +00:00
}
2021-02-17 06:57:29 +00:00
export function testDatabaseConnection(params, cb) {
2022-06-11 00:57:54 +00:00
return axios.post(baseURL + '/api/setup/test-db', params).then((response) => {
cb(response.data);
});
2021-02-02 09:26:35 +00:00
}
2021-02-17 06:57:29 +00:00
export function configureDatabase(params, cb) {
2022-06-11 00:57:54 +00:00
return axios
.post(baseURL + '/api/setup/configure-db', params)
.then((response) => {
cb(response.data);
2021-02-02 09:26:35 +00:00
});
}
export function saveConfig(cb) {
2022-06-11 00:57:54 +00:00
return axios.post(baseURL + '/api/setup/save').then((response) => {
cb(response.data);
});
}
2021-02-04 12:21:16 +00:00
export function setupRestart(cb) {
2022-06-11 00:57:54 +00:00
return axios.post(baseURL + '/api/setup/restart').then((response) => {
cb(response.data);
});
2021-02-04 12:21:16 +00:00
}
2021-02-02 09:26:35 +00:00
export function addSession(session, cb) {
2022-06-11 00:57:54 +00:00
return axios.post(baseURL + '/api/sessions', session).then((response) => {
cb(response.data || []);
});
2021-02-02 09:26:35 +00:00
}
2021-02-02 18:26:41 +00:00
export function attachStrategyOn(session, strategyID, strategy, cb) {
2022-06-11 00:57:54 +00:00
return axios
.post(
baseURL + `/api/setup/strategy/single/${strategyID}/session/${session}`,
strategy
)
.then((response) => {
cb(response.data);
2021-02-02 18:26:41 +00:00
});
}
2021-02-02 09:26:35 +00:00
export function testSessionConnection(session, cb) {
2022-06-11 00:57:54 +00:00
return axios
.post(baseURL + '/api/sessions/test', session)
.then((response) => {
cb(response.data);
});
}
export function queryStrategies(cb) {
2022-06-14 04:36:10 +00:00
return axios.get<any>(baseURL + '/api/strategies/single').then((response) => {
2022-06-11 00:57:54 +00:00
cb(response.data.strategies || []);
});
}
2021-01-25 10:29:31 +00:00
export function querySessions(cb) {
2022-06-14 04:36:10 +00:00
return axios.get<any>(baseURL + '/api/sessions', {}).then((response) => {
2022-06-11 00:57:54 +00:00
cb(response.data.sessions || []);
});
2021-01-25 10:29:31 +00:00
}
export function querySessionSymbols(sessionName, cb) {
2022-06-11 00:57:54 +00:00
return axios
2022-06-14 04:36:10 +00:00
.get<any>(baseURL + `/api/sessions/${sessionName}/symbols`, {})
2022-06-11 00:57:54 +00:00
.then((response) => {
2022-06-14 04:36:10 +00:00
cb(response.data?.symbols || []);
2022-06-11 00:57:54 +00:00
});
}
2021-01-29 10:48:39 +00:00
export function queryTrades(params, cb) {
2022-06-14 07:33:22 +00:00
axios
.get<any>(baseURL + '/api/trades', { params: params })
.then((response) => {
cb(response.data.trades || []);
});
2021-01-29 10:48:39 +00:00
}
2021-01-29 10:34:03 +00:00
export function queryClosedOrders(params, cb) {
2022-06-11 00:57:54 +00:00
axios
2022-06-14 04:36:10 +00:00
.get<any>(baseURL + '/api/orders/closed', { params: params })
2022-06-11 00:57:54 +00:00
.then((response) => {
cb(response.data.orders || []);
});
2021-01-29 08:50:06 +00:00
}
2021-01-25 09:40:37 +00:00
export function queryAssets(cb) {
2022-06-14 04:36:10 +00:00
axios.get<any>(baseURL + '/api/assets', {}).then((response) => {
2022-06-11 00:57:54 +00:00
cb(response.data.assets || []);
});
2021-01-25 09:40:37 +00:00
}
2021-01-26 10:10:08 +00:00
export function queryTradingVolume(params, cb) {
2022-06-11 00:57:54 +00:00
axios
2022-06-14 04:36:10 +00:00
.get<any>(baseURL + '/api/trading-volume', { params: params })
2022-06-11 00:57:54 +00:00
.then((response) => {
cb(response.data.tradingVolumes || []);
});
2021-01-26 10:10:08 +00:00
}
2022-06-15 10:55:51 +00:00
2022-06-16 04:36:45 +00:00
export interface GridStrategy {
id: string;
instanceID: string;
strategy: string;
grid: {
symbol: string;
};
2022-06-16 08:47:35 +00:00
stats: GridStats;
2022-06-16 04:36:45 +00:00
status: string;
startTime: number;
}
2022-06-16 08:47:35 +00:00
export interface GridStats {
oneDayArbs: number;
totalArbs: number;
investment: number;
totalProfits: number;
gridProfits: number;
floatingPNL: number;
currentPrice: number;
lowestPrice: number;
highestPrice: number;
}
2022-06-16 04:36:45 +00:00
export async function queryStrategiesMetrics(): Promise<GridStrategy[]> {
2022-06-16 10:17:59 +00:00
const temp = {
id: 'uuid',
instanceID: 'testInstanceID',
strategy: 'grid',
grid: {
symbol: 'BTCUSDT',
},
stats: {
oneDayArbs: 0,
totalArbs: 3,
investment: 100,
2022-06-16 14:30:05 +00:00
totalProfits: 5.6,
2022-06-16 10:17:59 +00:00
gridProfits: 2.5,
floatingPNL: 3.1,
currentPrice: 29000,
lowestPrice: 25000,
highestPrice: 35000,
2022-06-15 11:02:24 +00:00
},
2022-06-16 10:17:59 +00:00
status: 'RUNNING',
startTime: 1654938187102,
2022-06-16 14:30:05 +00:00
};
2022-06-16 10:17:59 +00:00
const testArr = [];
2022-06-16 14:30:05 +00:00
for (let i = 0; i < 11; i++) {
const cloned = { ...temp };
cloned.id = 'uuid' + i;
2022-06-16 10:17:59 +00:00
testArr.push(cloned);
2022-06-16 14:30:05 +00:00
}
2022-06-16 10:17:59 +00:00
2022-06-16 14:30:05 +00:00
return testArr;
2022-06-15 11:02:24 +00:00
}