Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #12 from coltoneshaw/v0.2.1
Browse files Browse the repository at this point in the history
V0.2.1
  • Loading branch information
coltoneshaw authored Aug 23, 2021
2 parents 6c168b6 + 2ec2779 commit 3a7ecb6
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 24 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# v0.2.1

## Enhancements
- Added a calculated tooltip to avg deal hours

## Bug
- Manually typing into the date selector would crash the application.
- Avg Deal hours was incorrectly averaging the sum by date instead of by deal.

# v0.2.0

## Enhancements
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "3c-portfolio-manager",
"productName": "3C Portfolio Manager",
"version": "0.1.1",
"version": "0.2.1",
"description": "An application to manage your 3Commas portfolio.",
"private": true,
"main": "./dist/main.js",
Expand Down
12 changes: 9 additions & 3 deletions src/app/Components/Charts/DataCards/metrics/AverageDealHours.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ import { parseNumber } from "@/utils/number_formatting"


interface Type_Card {
metric: number
metric: number,
additionalData: {
totalClosedDeals: number
totalDealHours: number
}
}

/**
*
* @param metric - accepts the averageDailyProfit metric from the global data store.
*/
const Card_AverageDealHours = ({metric}:Type_Card) => {
const Card_AverageDealHours = ({metric, additionalData}:Type_Card) => {

const {totalClosedDeals, totalDealHours} = additionalData

const title = "Avg. Deal Hours"
const message = descriptions.metrics.averageDealHours
const message = descriptions.calculations.averageDealHours( totalClosedDeals, totalDealHours)
const key = title.replace(/\s/g, '')
return (
<Card title={title} message={message} key={key} metric={metric.toFixed(2)} />
Expand Down
3 changes: 2 additions & 1 deletion src/app/Context/DataContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ const defaultMetrics = {
position: 0,
on_orders: 0,
totalInDeals: 0,
reservedFundsTotal: 0
reservedFundsTotal: 0,
totalClosedDeals: 0
}


Expand Down
14 changes: 10 additions & 4 deletions src/app/Features/3Commas/3Commas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ const fetchDealDataFunction = async () => {
SELECT
substr(closed_at, 0, 11) as closed_at_str,
sum(final_profit) as final_profit,
sum(deal_hours) as deal_hours
sum(deal_hours) as deal_hours,
count(id) as total_deals
FROM
deals
WHERE
Expand Down Expand Up @@ -106,21 +107,26 @@ const fetchDealDataFunction = async () => {
profitArray.push({
utc_date: day.closed_at_str,
profit: day.final_profit,
runningSum: runningSum
runningSum: runningSum,
total_deals: day.total_deals
})
})


const totalProfit = (profitArray.length > 0) ? +profitArray[profitArray.length - 1].runningSum : 0
const averageDailyProfit = (profitArray.length > 0) ? totalProfit / (profitArray.length + 1) : 0;
const averageDealHours = (profitArray.length > 0) ? totalDealHours / (profitArray.length + 1) : 0;
const totalClosedDeals = (profitArray.length > 0) ? profitArray.map(day => day.total_deals).reduce( (sum:number, total_deals: number) => sum + total_deals) : 0;
const averageDealHours = (profitArray.length > 0) ? totalDealHours / totalClosedDeals : 0;
console.log({totalDealHours, profitArray, totalClosedDeals})

return {
profitData: profitArray,
metrics: {
totalProfit,
averageDailyProfit,
averageDealHours
averageDealHours,
totalClosedDeals,
totalDealHours
}
}

Expand Down
13 changes: 12 additions & 1 deletion src/app/Features/Changelog/changelogText.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

const mostRecent = '0.1.1'
const mostRecent = '0.2.1'


const versionInformation = [
Expand Down Expand Up @@ -155,6 +155,17 @@ const versionInformation = [
'Added additional filters to Bot / Pair performance charts'
]
},
{
version: '0.2.1',
enhancements: [
'Added a calculated tooltip to avg deal hours',
],
bugs: [
'Manually typing into the date selector would crash the application.',
'Avg Deal hours was incorrectly averaging the sum by date instead of by deal.'
],
new: []
},
]

export {
Expand Down
4 changes: 2 additions & 2 deletions src/app/Pages/Settings/Components/SaveSubmitButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const SaveSubmitButtons = ({setOpen}: SubmitButtons) => {
const { reset, setConfigBulk } = configState

const dataState = useGlobalData()
const {actions: {updateAllData}} = dataState
const {actions: { updateAllData }, data: { isSyncing}} = dataState
const [ loader, setLoaderIcon ] = useState(false)

const callback = () => setOpen(true)
Expand Down Expand Up @@ -55,7 +55,7 @@ const SaveSubmitButtons = ({setOpen}: SubmitButtons) => {
}}
disableElevation
>
{( loader) ? <> Syncing... <LoaderIcon /> </> : "Save"}
{( isSyncing) ? <> Syncing... <LoaderIcon /> </> : "Save"}
</Button>
</div>
)
Expand Down
17 changes: 10 additions & 7 deletions src/app/Pages/Settings/Components/StartDatePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getTime, parseISO, formatISO } from 'date-fns'
import { getTime, parseISO, formatISO, isValid } from 'date-fns'
import React, { useContext, useState, useEffect, forwardRef } from 'react';
import DateFnsUtils from '@date-io/date-fns';

Expand All @@ -20,17 +20,20 @@ export default function StartDatePicker() {
const [localDate, setLocalDate] = useState<string>();

const handleDateChange = (date: any) => {
setLocalDate(date)
if (date != undefined && isValid(new Date(date))) {
setLocalDate(date)

// getting the shortform utc date, stripping and converting to ISO
const dateString = formatISO(date, { representation: 'date' })
const utcDate = dateString + 'T00:00:00Z'
updateDate(getTime(parseISO(utcDate)));
}

// getting the shortform utc date, stripping and converting to ISO
const dateString = formatISO(date, { representation: 'date' })
const utcDate = dateString + 'T00:00:00Z'
updateDate(getTime(parseISO(utcDate)));
};

// converting the date into a ISO date and storing it.
useEffect(() => {
const adjustedTime = date + ( (new Date()).getTimezoneOffset() * 60000 )
const adjustedTime = date + ((new Date()).getTimezoneOffset() * 60000)
const dateString = new Date(adjustedTime).toUTCString()
console.log(dateString)
setLocalDate(dateString)
Expand Down
4 changes: 2 additions & 2 deletions src/app/Pages/Stats/Stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const StatsPage = () => {
const { config, state: { reservedFunds } } = configState
const state = useGlobalData()
const { data: { metricsData, isSyncing }, actions: { updateAllData } } = state
const { activeDealCount, totalInDeals, maxRisk, totalBankroll, position, on_orders, totalProfit, totalBoughtVolume, reservedFundsTotal, maxRiskPercent, totalDeals, boughtVolume, totalProfit_perf, averageDailyProfit, averageDealHours } = metricsData
const { activeDealCount, totalInDeals, maxRisk, totalBankroll, position, on_orders, totalProfit, totalBoughtVolume, reservedFundsTotal, maxRiskPercent, totalDeals, boughtVolume, totalProfit_perf, averageDailyProfit, averageDealHours, totalClosedDeals, totalDealHours } = metricsData

const [currentView, changeView] = useState('summary-stats')
const date: undefined | number = dotProp.get(config, 'statSettings.startDate')
Expand Down Expand Up @@ -97,7 +97,7 @@ const StatsPage = () => {
<Card_TotalDeals metric={totalDeals} />
<Card_TotalRoi additionalData={{ totalProfit_perf, boughtVolume }} />
<Card_AverageDailyProfit metric={averageDailyProfit} />
<Card_AverageDealHours metric={averageDealHours} />
<Card_AverageDealHours metric={averageDealHours} additionalData={{totalClosedDeals, totalDealHours}}/>
</>)
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/descriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ const descriptions = {
totalInDeals: ( on_orders:number , totalBoughtVolume:number ) => ` adds together the total amount of funds that you have within a deal. This consists of funds on order of ${parseNumber(on_orders)} and total bought volume of your deals of ${parseNumber(totalBoughtVolume)}.`,
totalProfit: ` is the sum of all the profit you've made within the filtered time period.`,
totalRoi: ( totalProfit_perf:number , boughtVolume:number ) => ` calculates the total return on your investment based on the bought volume of ${parseNumber(boughtVolume)} divided by the total profit of ${parseNumber(totalProfit_perf)}`,
averageDealHours: (totalClosedDeals:number , totalDealHours:number ) => ` is the average amount of time it takes for your deals to close. You have ${parseNumber(totalClosedDeals)} deals and ${parseNumber(totalDealHours)} hours in those deals.`,


},
metrics: {
totalBoughtVolume: ` is the total that your bots have put into a deal.`,
totalDeals: ` is the total amount of deals closed during the filtered period.`,
averageDailyProfit: ` is the amount of total profit you've made divided by the total number of days included in your filter.`,
averageDealHours: ` is the total average amount of time it takes for your deals to close.`,
todaysProfit: ` is the sum of the profit you've made in UTC today. Note this does not always reset at midnight, depending on your timezone`,
activeDealReserves: ` is the sum of all your deals current profit. This number can be postive / negative based on where all your deals are currently.`
}
Expand Down
9 changes: 7 additions & 2 deletions src/types/3Commas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ export interface Type_Query_DealData {
closed_at: string
id: number
deal_hours: number,
total_deals: number
}

export type Type_Profit = {
utc_date: string
profit: number
runningSum: number
total_deals: number

}


Expand Down Expand Up @@ -228,10 +231,12 @@ export interface Type_MetricData {
bankrollAvailable: number
totalBankroll: number
position: number
on_orders: number
on_orders: number // total number of funds in an exchange order that's not filled
totalInDeals: number
availableBankroll: number,
reservedFundsTotal: number
reservedFundsTotal: number,
totalClosedDeals: number, // total number of deals closed for the filtered time
totalDealHours: number // this is the total hours in deals you have for the filtered time
}

export interface Type_MarketOrders {
Expand Down

0 comments on commit 3a7ecb6

Please sign in to comment.