Update vitejs + fix bot saving
This commit is contained in:
@@ -59,8 +59,7 @@
|
||||
"viem": "2.28.0",
|
||||
"wagmi": "^2.15.0",
|
||||
"web3": "^4.16.0",
|
||||
"zustand": "^4.4.1",
|
||||
"@gmx-io/sdk": "0.2.0"
|
||||
"zustand": "^4.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/elliptic": "^6.4.18",
|
||||
@@ -83,7 +82,7 @@
|
||||
"prettier-plugin-tailwind-css": "^1.5.0",
|
||||
"tailwindcss": "^3.0.23",
|
||||
"typescript": "^5.7.3",
|
||||
"vite": "^6.0.11",
|
||||
"vite": "^6.3.5",
|
||||
"whatwg-fetch": "^3.6.2"
|
||||
},
|
||||
"msw": {
|
||||
|
||||
@@ -56,14 +56,14 @@ const BacktestCards: React.FC<IBacktestCards> = ({ list, setBacktests }) => {
|
||||
const client = new BotClient({}, apiUrl)
|
||||
|
||||
const request: StartBotRequest = {
|
||||
accountName: backtest.accountName,
|
||||
botName: backtest.ticker + '-' + backtest.timeframe.toString(),
|
||||
accountName: backtest.config.accountName,
|
||||
name: backtest.config.ticker + '-' + backtest.config.timeframe?.toString(),
|
||||
botType: BotType.ScalpingBot,
|
||||
isForWatchOnly: isForWatchOnly,
|
||||
moneyManagementName: backtest.moneyManagement?.name,
|
||||
scenario: backtest.scenario,
|
||||
ticker: backtest.ticker as Ticker,
|
||||
timeframe: backtest.timeframe,
|
||||
moneyManagementName: backtest.config.moneyManagement?.name,
|
||||
scenario: backtest.config.scenarioName,
|
||||
ticker: backtest.config.ticker as Ticker,
|
||||
timeframe: backtest.config.timeframe,
|
||||
initialTradingBalance: 1000,
|
||||
}
|
||||
|
||||
@@ -87,21 +87,23 @@ const BacktestCards: React.FC<IBacktestCards> = ({ list, setBacktests }) => {
|
||||
|
||||
await client
|
||||
.backtest_Run(
|
||||
backtest.accountName,
|
||||
backtest.botType,
|
||||
backtest.ticker as Ticker,
|
||||
backtest.scenario,
|
||||
backtest.timeframe,
|
||||
backtest.config.accountName,
|
||||
backtest.config.botType,
|
||||
backtest.config.ticker as Ticker,
|
||||
backtest.config.scenarioName,
|
||||
backtest.config.timeframe,
|
||||
false, // watchOnly
|
||||
backtest.walletBalances[0].value, // balance
|
||||
'', // moneyManagementName (empty since we're passing the optimized moneyManagement object)
|
||||
startDate, // startDate
|
||||
endDate, // endDate
|
||||
false, // save
|
||||
backtest.optimizedMoneyManagement // moneyManagement object
|
||||
backtest.config.cooldownPeriod,
|
||||
backtest.config.maxLossStreak,
|
||||
backtest.config.moneyManagement as MoneyManagement, // moneyManagement object
|
||||
)
|
||||
.then((backtest: Backtest) => {
|
||||
t.update('success', `${backtest.ticker} Backtest Succeeded`)
|
||||
t.update('success', `${backtest.config.ticker} Backtest Succeeded`)
|
||||
setBacktests((arr) => [...arr, backtest])
|
||||
})
|
||||
.catch((err) => {
|
||||
@@ -177,7 +179,7 @@ const BacktestCards: React.FC<IBacktestCards> = ({ list, setBacktests }) => {
|
||||
<button
|
||||
className="text-xs"
|
||||
onClick={() =>
|
||||
saveMoneyManagement(backtest.moneyManagement)
|
||||
saveMoneyManagement(backtest.config.moneyManagement)
|
||||
}
|
||||
>
|
||||
Save money management
|
||||
@@ -193,7 +195,7 @@ const BacktestCards: React.FC<IBacktestCards> = ({ list, setBacktests }) => {
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
{backtest.ticker}
|
||||
{backtest.config.ticker}
|
||||
{botStatusResult(
|
||||
backtest.growthPercentage,
|
||||
backtest.hodlPercentage
|
||||
@@ -203,19 +205,19 @@ const BacktestCards: React.FC<IBacktestCards> = ({ list, setBacktests }) => {
|
||||
<div>
|
||||
<CardText
|
||||
title="Ticker"
|
||||
content={backtest.ticker}
|
||||
content={backtest.config.ticker}
|
||||
></CardText>
|
||||
<CardText
|
||||
title="Account"
|
||||
content={backtest.accountName}
|
||||
content={backtest.config.accountName}
|
||||
></CardText>
|
||||
<CardText
|
||||
title="Scenario"
|
||||
content={backtest.scenario}
|
||||
content={backtest.config.scenarioName}
|
||||
></CardText>
|
||||
<CardText
|
||||
title="Timeframe"
|
||||
content={backtest.timeframe}
|
||||
content={backtest.config.timeframe?.toString()}
|
||||
></CardText>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -4,15 +4,15 @@ import {type SubmitHandler, useForm} from 'react-hook-form'
|
||||
|
||||
import useApiUrlStore from '../../../app/store/apiStore'
|
||||
import {
|
||||
AccountClient,
|
||||
BacktestClient,
|
||||
BotType,
|
||||
DataClient,
|
||||
MoneyManagement,
|
||||
MoneyManagementClient,
|
||||
ScenarioClient,
|
||||
Ticker,
|
||||
Timeframe,
|
||||
AccountClient,
|
||||
BacktestClient,
|
||||
BotType,
|
||||
DataClient,
|
||||
MoneyManagement,
|
||||
MoneyManagementClient,
|
||||
ScenarioClient,
|
||||
Ticker,
|
||||
Timeframe,
|
||||
} from '../../../generated/ManagingApi'
|
||||
import type {BacktestModalProps, IBacktestsFormInput,} from '../../../global/type'
|
||||
import {Loader, Slider} from '../../atoms'
|
||||
@@ -123,7 +123,7 @@ const BacktestModal: React.FC<BacktestModalProps> = ({
|
||||
customMoneyManagement
|
||||
);
|
||||
|
||||
t.update('success', `${backtest.ticker} Backtest Succeeded`)
|
||||
t.update('success', `${backtest.config.ticker} Backtest Succeeded`)
|
||||
setBacktests((arr) => [...arr, backtest])
|
||||
|
||||
if (showLoopSlider && selectedLoopQuantity > loopCount) {
|
||||
|
||||
@@ -50,16 +50,18 @@ const BacktestTable: React.FC<IBacktestCards> = ({ list, isFetching, setBacktest
|
||||
moneyManagementName.toLowerCase().includes('custom');
|
||||
|
||||
const request: StartBotRequest = {
|
||||
accountName: backtest.accountName,
|
||||
botName: botName,
|
||||
botType: backtest.botType,
|
||||
accountName: backtest.config.accountName,
|
||||
botType: backtest.config.botType,
|
||||
isForWatchOnly: isForWatchOnly,
|
||||
// Only use the money management name if it's not a custom money management
|
||||
moneyManagementName: isCustomMoneyManagement ? '' : moneyManagementName,
|
||||
scenario: backtest.scenario,
|
||||
ticker: backtest.ticker as Ticker,
|
||||
timeframe: backtest.timeframe,
|
||||
scenario: backtest.config.scenarioName,
|
||||
ticker: backtest.config.ticker as Ticker,
|
||||
timeframe: backtest.config.timeframe,
|
||||
initialTradingBalance: initialTradingBalance,
|
||||
cooldownPeriod: backtest.config.cooldownPeriod,
|
||||
maxLossStreak: backtest.config.maxLossStreak,
|
||||
name: botName,
|
||||
}
|
||||
|
||||
await client
|
||||
@@ -162,26 +164,26 @@ const BacktestTable: React.FC<IBacktestCards> = ({ list, isFetching, setBacktest
|
||||
{
|
||||
Filter: SelectColumnFilter,
|
||||
Header: 'Ticker',
|
||||
accessor: 'ticker',
|
||||
accessor: 'config.ticker',
|
||||
disableSortBy: true,
|
||||
},
|
||||
|
||||
{
|
||||
Filter: SelectColumnFilter,
|
||||
Header: 'Timeframe',
|
||||
accessor: 'timeframe',
|
||||
accessor: 'config.timeframe',
|
||||
disableSortBy: true,
|
||||
},
|
||||
{
|
||||
Filter: SelectColumnFilter,
|
||||
Header: 'Scenario',
|
||||
accessor: 'scenario',
|
||||
accessor: 'config.scenarioName',
|
||||
disableSortBy: true,
|
||||
},
|
||||
{
|
||||
Filter: SelectColumnFilter,
|
||||
Header: 'BotType',
|
||||
accessor: 'botType',
|
||||
accessor: 'config.botType',
|
||||
disableSortBy: true,
|
||||
},
|
||||
],
|
||||
|
||||
@@ -2544,13 +2544,9 @@ export interface Backtest {
|
||||
winRate: number;
|
||||
growthPercentage: number;
|
||||
hodlPercentage: number;
|
||||
ticker: Ticker;
|
||||
scenario: string;
|
||||
config: TradingBotConfig;
|
||||
positions: Position[];
|
||||
signals: Signal[];
|
||||
timeframe: Timeframe;
|
||||
botType: BotType;
|
||||
accountName: string;
|
||||
candles: Candle[];
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
@@ -2558,12 +2554,46 @@ export interface Backtest {
|
||||
fees: number;
|
||||
walletBalances: KeyValuePairOfDateTimeAndDecimal[];
|
||||
optimizedMoneyManagement: MoneyManagement;
|
||||
moneyManagement: MoneyManagement;
|
||||
user: User;
|
||||
strategiesValues: { [key in keyof typeof StrategyType]?: StrategiesResultBase; };
|
||||
score: number;
|
||||
}
|
||||
|
||||
export interface TradingBotConfig {
|
||||
accountName: string;
|
||||
moneyManagement: MoneyManagement;
|
||||
ticker: Ticker;
|
||||
scenarioName: string;
|
||||
timeframe: Timeframe;
|
||||
isForWatchingOnly: boolean;
|
||||
botTradingBalance: number;
|
||||
botType: BotType;
|
||||
isForBacktest: boolean;
|
||||
cooldownPeriod: number;
|
||||
maxLossStreak: number;
|
||||
flipPosition: boolean;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface MoneyManagement {
|
||||
name: string;
|
||||
timeframe: Timeframe;
|
||||
stopLoss: number;
|
||||
takeProfit: number;
|
||||
leverage: number;
|
||||
user?: User | null;
|
||||
}
|
||||
|
||||
export enum Timeframe {
|
||||
FiveMinutes = "FiveMinutes",
|
||||
FifteenMinutes = "FifteenMinutes",
|
||||
ThirtyMinutes = "ThirtyMinutes",
|
||||
OneHour = "OneHour",
|
||||
FourHour = "FourHour",
|
||||
OneDay = "OneDay",
|
||||
OneMinute = "OneMinute",
|
||||
}
|
||||
|
||||
export enum Ticker {
|
||||
AAVE = "AAVE",
|
||||
ADA = "ADA",
|
||||
@@ -2673,6 +2703,12 @@ export enum Ticker {
|
||||
Unknown = "Unknown",
|
||||
}
|
||||
|
||||
export enum BotType {
|
||||
SimpleBot = "SimpleBot",
|
||||
ScalpingBot = "ScalpingBot",
|
||||
FlippingBot = "FlippingBot",
|
||||
}
|
||||
|
||||
export interface Position {
|
||||
accountName: string;
|
||||
date: Date;
|
||||
@@ -2697,25 +2733,6 @@ export enum TradeDirection {
|
||||
Long = "Long",
|
||||
}
|
||||
|
||||
export interface MoneyManagement {
|
||||
name: string;
|
||||
timeframe: Timeframe;
|
||||
stopLoss: number;
|
||||
takeProfit: number;
|
||||
leverage: number;
|
||||
user?: User | null;
|
||||
}
|
||||
|
||||
export enum Timeframe {
|
||||
FiveMinutes = "FiveMinutes",
|
||||
FifteenMinutes = "FifteenMinutes",
|
||||
ThirtyMinutes = "ThirtyMinutes",
|
||||
OneHour = "OneHour",
|
||||
FourHour = "FourHour",
|
||||
OneDay = "OneDay",
|
||||
OneMinute = "OneMinute",
|
||||
}
|
||||
|
||||
export interface Trade {
|
||||
fee?: number;
|
||||
date: Date;
|
||||
@@ -2850,12 +2867,6 @@ export enum SignalType {
|
||||
Context = "Context",
|
||||
}
|
||||
|
||||
export enum BotType {
|
||||
SimpleBot = "SimpleBot",
|
||||
ScalpingBot = "ScalpingBot",
|
||||
FlippingBot = "FlippingBot",
|
||||
}
|
||||
|
||||
export interface PerformanceMetrics {
|
||||
count?: number;
|
||||
sharpeRatio?: number;
|
||||
@@ -2970,6 +2981,9 @@ export interface StartBotRequest {
|
||||
moneyManagementName?: string | null;
|
||||
isForWatchOnly?: boolean;
|
||||
initialTradingBalance?: number;
|
||||
cooldownPeriod?: number;
|
||||
maxLossStreak?: number;
|
||||
name?: string | null;
|
||||
}
|
||||
|
||||
export interface TradingBot {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { ColorSwatchIcon, TrashIcon, XIcon } from '@heroicons/react/solid'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import {ColorSwatchIcon, TrashIcon} from '@heroicons/react/solid'
|
||||
import {useQuery} from '@tanstack/react-query'
|
||||
import React, {useEffect, useState} from 'react'
|
||||
|
||||
import 'react-toastify/dist/ReactToastify.css'
|
||||
import useApiUrlStore from '../../app/store/apiStore'
|
||||
import { Loader } from '../../components/atoms'
|
||||
import { Modal, Toast } from '../../components/mollecules'
|
||||
import { BacktestModal, BacktestTable } from '../../components/organism'
|
||||
import type { Backtest } from '../../generated/ManagingApi'
|
||||
import { BacktestClient } from '../../generated/ManagingApi'
|
||||
import {Loader} from '../../components/atoms'
|
||||
import {Modal, Toast} from '../../components/mollecules'
|
||||
import {BacktestModal, BacktestTable} from '../../components/organism'
|
||||
import type {Backtest} from '../../generated/ManagingApi'
|
||||
import {BacktestClient} from '../../generated/ManagingApi'
|
||||
|
||||
const BacktestScanner: React.FC = () => {
|
||||
const [backtestingResult, setBacktest] = useState<Backtest[]>([])
|
||||
@@ -28,19 +28,6 @@ const BacktestScanner: React.FC = () => {
|
||||
}
|
||||
}, [backtests])
|
||||
|
||||
function deleteAllBacktests() {
|
||||
const t = new Toast('Deleting all backtests')
|
||||
client
|
||||
.backtest_DeleteBacktests()
|
||||
.then(() => {
|
||||
t.update('success', 'Backtest Succeeded')
|
||||
refetch()
|
||||
})
|
||||
.catch((err) => {
|
||||
t.update('error', 'Error :' + err)
|
||||
})
|
||||
}
|
||||
|
||||
const openModalRemoveBacktests = () => {
|
||||
setShowModalRemoveBacktest(true)
|
||||
}
|
||||
@@ -111,11 +98,6 @@ const BacktestScanner: React.FC = () => {
|
||||
<TrashIcon width="20"></TrashIcon>
|
||||
</button>
|
||||
</div>
|
||||
<div className="tooltip" data-tip="Delete all backtests">
|
||||
<button className="btn btn-error text-xs" onClick={deleteAllBacktests}>
|
||||
<XIcon width="20"></XIcon>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<BacktestTable list={backtestingResult} isFetching={isLoading} setBacktests={setBacktest} />
|
||||
|
||||
|
||||
@@ -1,47 +1,12 @@
|
||||
import React, { useState } from 'react'
|
||||
import { toast } from 'react-toastify'
|
||||
import { SettingsClient } from '../../../generated/ManagingApi'
|
||||
import React, {useState} from 'react'
|
||||
import {toast} from 'react-toastify'
|
||||
import {SettingsClient} from '../../../generated/ManagingApi'
|
||||
import useApiUrlStore from '../../../app/store/apiStore'
|
||||
import { GmxSdk } from '@gmx-io/sdk'
|
||||
import { createClient, createTestClient, createWalletClient, http, publicActions, walletActions } from 'viem'
|
||||
import { getClient, getConnectorClient } from '@wagmi/core'
|
||||
import { privyWagmiConfig } from '../../../config/privy'
|
||||
import { arbitrum } from 'viem/chains'
|
||||
import { GmxSdkConfig } from '@gmx-io/sdk/build/src/types/sdk'
|
||||
|
||||
const DefaultConfig: React.FC = () => {
|
||||
const [isCreating, setIsCreating] = useState(false)
|
||||
const { apiUrl } = useApiUrlStore()
|
||||
|
||||
const client = createWalletClient({
|
||||
account: "0x9f7198eb1b9Ccc0Eb7A07eD228d8FbC12963ea33",
|
||||
chain: arbitrum,
|
||||
transport: http(),
|
||||
})
|
||||
|
||||
const testClient = createTestClient({
|
||||
chain: arbitrum,
|
||||
mode: "hardhat",
|
||||
transport: http(),
|
||||
})
|
||||
.extend(publicActions)
|
||||
.extend(walletActions);
|
||||
|
||||
|
||||
const arbitrumSdkConfig: GmxSdkConfig = {
|
||||
chainId: arbitrum.id,
|
||||
account: "0x9f7198eb1b9Ccc0Eb7A07eD228d8FbC12963ea33",
|
||||
oracleUrl: "https://arbitrum-api.gmxinfra.io",
|
||||
rpcUrl: "https://arb1.arbitrum.io/rpc",
|
||||
walletClient: client,
|
||||
subsquidUrl: "https://gmx.squids.live/gmx-synthetics-arbitrum:live/api/graphql",
|
||||
subgraphUrl: "https://subgraph.satsuma-prod.com/3b2ced13c8d9/gmx/synthetics-arbitrum-stats/api",
|
||||
};
|
||||
|
||||
const sdk = new GmxSdk(arbitrumSdkConfig)
|
||||
|
||||
console.log(sdk)
|
||||
|
||||
const createDefaultConfig = async () => {
|
||||
try {
|
||||
const client = new SettingsClient({}, apiUrl)
|
||||
|
||||
Reference in New Issue
Block a user