Skip to content

Commit

Permalink
Adding the bot data from the bots table plus bot_type to the charts
Browse files Browse the repository at this point in the history
  • Loading branch information
coltoneshaw committed Aug 14, 2021
1 parent 0d8cbda commit c898f57
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/app/Components/Charts/Bar/BotPerformanceBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const BotPerformanceBar = ({ title, data }: Type_BotPerformanceCharts) => {
type="category"
angle={45}
axisLine={false}
height={125}
height={75}
textLength={15}
textAnchor="start"

Expand Down Expand Up @@ -122,10 +122,11 @@ const BotPerformanceBar = ({ title, data }: Type_BotPerformanceCharts) => {
function CustomTooltip({ active, payload, label }: Type_Tooltip) {
if (active) {
const data: Type_Bot_Performance_Metrics = payload[0].payload
const { total_profit, avg_completed_so, avg_profit, avg_deal_hours, bought_volume, number_of_deals, bot_name } = data
const { total_profit, avg_completed_so, avg_profit, avg_deal_hours, bought_volume, number_of_deals, bot_name, type } = data
return (
<div className="tooltop">
<h4>{bot_name}</h4>
<p>{type}</p>
<p><strong>Bought Volume:</strong> ${parseNumber(bought_volume)} </p>
<p><strong>Deal Count:</strong> {number_of_deals} </p>
<p><strong>Total Profit:</strong> ${parseNumber(total_profit)} </p>
Expand Down
2 changes: 1 addition & 1 deletion src/server/threeC/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async function bots() {
take_profit,
take_profit_type,
trailing_deviation,
type,
type: type.split('::')[1],
drawdown: 0,
price_deviation: calc_deviation( +max_safety_orders, +safety_order_step_percentage, +martingale_step_coefficient),
maxCoveragePercent: null
Expand Down
1 change: 1 addition & 0 deletions src/types/3Commas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface Type_Bot_Performance_Metrics {
avg_profit: number
bought_volume: number
avg_deal_hours: number
type: string
}

export interface Type_Query_DealData {
Expand Down
23 changes: 15 additions & 8 deletions src/utils/3Commas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const getFiltersQueryString = async () => {
/**
* @description This kicks off the update process that updates all 3Commas data within the database.
*/
const updateThreeCData = async ( offset:number, type?:string ) => {
const updateThreeCData = async (offset: number, type?: string) => {

// @ts-ignore
await electron.api.update(offset, type);
Expand Down Expand Up @@ -206,7 +206,11 @@ const fetchPerformanceDataFunction = async () => {
/**
*
* @returns An array containing the data for specific bot metrics.
*
* TODO
* - Run a join on the bot table to correctly get the name / type or pull that information from the state.
*/

const fetchBotPerformanceMetrics = async () => {
const filtersQueryString = await getFiltersQueryString()
const { currencyString, accountIdString, startString } = filtersQueryString;
Expand All @@ -215,20 +219,23 @@ const fetchBotPerformanceMetrics = async () => {
const queryString = `
SELECT
bot_id,
bot_name,
sum(final_profit) as total_profit,
avg(final_profit) as avg_profit,
count(*) as number_of_deals,
sum(bought_volume) as bought_volume,
avg(deal_hours) as avg_deal_hours,
avg(completed_safety_orders_count + completed_manual_safety_orders_count) as avg_completed_so
avg(completed_safety_orders_count + completed_manual_safety_orders_count) as avg_completed_so,
bots.name as bot_name,
bots.type as type
FROM
deals
deals
JOIN
bots on deals.bot_id = bots.id
WHERE
closed_at is not null
and account_id in (${accountIdString})
and currency in (${currencyString})
and closed_at_iso_string > ${startString}
and deals.account_id in (${accountIdString})
and deals.currency in (${currencyString})
and deals.closed_at_iso_string > ${startString}
GROUP BY
bot_id;`

Expand All @@ -250,7 +257,7 @@ const fetchBotPerformanceMetrics = async () => {
*
* @returns An array containing the data for specific bot metrics.
*/
const fetchPairPerformanceMetrics = async () => {
const fetchPairPerformanceMetrics = async () => {
const filtersQueryString = await getFiltersQueryString()
const { currencyString, accountIdString, startString } = filtersQueryString;

Expand Down
6 changes: 6 additions & 0 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Store = require('electron-store');
const { run } = require('@/server/database')

import { defaultConfig, configSchema } from '@/utils/defaultConfig';

Expand All @@ -23,7 +24,12 @@ const config = new Store({
console.info('migrating the config store to 0.0.4')
console.log('adding a reserved funds array.')
store.set('statSettings.reservedFunds', []);
},
'0.1.0': ( store: any )=>{
console.info('migrating the config store to 0.1.0')
run('drop table bots;')
}

},
defaults: defaultConfig
});
Expand Down

0 comments on commit c898f57

Please sign in to comment.