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

Commit

Permalink
removed profile_id from queries
Browse files Browse the repository at this point in the history
  • Loading branch information
coltoneshaw committed Dec 1, 2021
1 parent 4de22e3 commit 8fc7565
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 21 deletions.
1 change: 0 additions & 1 deletion src/app/Features/3Commas/DataQueries/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const getAccountDataFunction = async (profileData: Type_Profile) => {
WHERE
account_id IN ( ${accountIdString} )
and currency_code IN ( ${currencyString} )
and profile_id = '${currentProfileID}';
`
let accountData: Type_Query_Accounts[] | [] = await window.ThreeCPM.Repository.Database.query(currentProfileID, query)

Expand Down
4 changes: 1 addition & 3 deletions src/app/Features/3Commas/DataQueries/bots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const fetchBotPerformanceMetrics = async (profileData: Type_Profile, oDate?: Dat
closed_at is not null
and deals.account_id in (${accountIdString})
and deals.currency in (${currencyString})
and deals.profile_id = '${currentProfileID}'
${fromSQL} ${toSQL}
GROUP BY
bot_id;`
Expand All @@ -67,8 +66,7 @@ const botQuery = async (currentProfile: Type_Profile): Promise<Type_Query_bots[]
FROM
bots
WHERE
profile_id = '${currentProfileID}'
and from_currency in (${currencyString})
from_currency in (${currencyString})
and (account_id in (${accountIdString}) OR origin = 'custom')`

let databaseQuery: Type_Query_bots[] | [] = await window.ThreeCPM.Repository.Database.query(currentProfileID, queryString);
Expand Down
4 changes: 0 additions & 4 deletions src/app/Features/3Commas/DataQueries/deals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const fetchDealDataFunction = async (profileData: Type_Profile) => {
and account_id in ( ${accountIdString} )
and currency in (${currencyString} )
and closed_at_iso_string > ${startString}
and profile_id = '${currentProfileID}'
GROUP BY
closed_at_str
ORDER BY
Expand Down Expand Up @@ -126,7 +125,6 @@ const fetchPerformanceDataFunction = async (profileData: Type_Profile, oDate?: D
and account_id in (${accountIdString} )
and currency in (${currencyString} )
and closed_at_iso_string > ${startString}
and profile_id = '${currentProfileID}'
${fromSQL} ${toSQL}
GROUP BY
performance_id;`
Expand Down Expand Up @@ -168,7 +166,6 @@ const getActiveDealsFunction = async (profileData: Type_Profile) => {
finished = 0
and account_id in (${accountIdString} )
and currency in (${currencyString} )
and profile_id = '${currentProfileID}'
`
let activeDeals: Type_ActiveDeals[] | [] = await window.ThreeCPM.Repository.Database.query(currentProfileID, query)

Expand Down Expand Up @@ -223,7 +220,6 @@ const fetchSoData = async (currentProfile: Type_Profile, oDate?: DateRange) => {
account_id in (${accountIdString} )
and currency in (${currencyString} )
and closed_at_iso_string > ${startString}
and profile_id = '${currentProfileID}'
${fromSQL} ${toSQL}
group by
completed_safety_orders_count;`
Expand Down
2 changes: 0 additions & 2 deletions src/app/Features/3Commas/DataQueries/pairs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const fetchPairPerformanceMetrics = async (profileData: Type_Profile, oDate?: Da
closed_at is not null
and account_id in (${accountIdString})
and currency in (${currencyString})
and profile_id = '${currentProfileID}'
${fromSQL} ${toSQL}
GROUP BY
pair;`
Expand Down Expand Up @@ -75,7 +74,6 @@ const getSelectPairDataByDate = async (profileData: Type_Profile, pairs: string[
and from_currency IN ( ${currencyString} )
and pair in (${pairString})
and closed_at_iso_string > ${startString}
and profile_id = '${currentProfileID}'
and pair in (${pairString}) ${fromSQL} ${toSQL}
GROUP BY
date, pair;
Expand Down
11 changes: 3 additions & 8 deletions src/app/Pages/DailyStats/Components/3Commas/dailyDashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const queryDealByPairByDay = async (profileData: Type_Profile, utcDateRange: utc
and account_id in (${filters.accounts} )
and currency in (${filters.currency} )
and closed_at_iso_string BETWEEN ${utcDateRange.utcStartDate} and ${utcDateRange.utcEndDate}
and profile_id = '${profileData.id}'
GROUP BY
pair;`

Expand Down Expand Up @@ -74,7 +73,6 @@ const queryDealByBotByDay = async (profileData: Type_Profile, utcDateRange: utcD
and account_id in (${filters.accounts} )
and currency in (${filters.currency} )
and closed_at_iso_string BETWEEN ${utcDateRange.utcStartDate} and ${utcDateRange.utcEndDate}
and profile_id = '${profileData.id}'
GROUP BY
bot_id;`

Expand Down Expand Up @@ -116,8 +114,7 @@ const getHistoricalProfits = async (profitArray: Type_Profit[] | [], filters: fi
or finished = 1
and account_id in (${filters.accounts} )
and currency in (${filters.currency} )
and closed_at_iso_string BETWEEN ${utcStart - daysInMilli.thirty} and ${utcStart}
and profile_id = '${currentProfileID}';`
and closed_at_iso_string BETWEEN ${utcStart - daysInMilli.thirty} and ${utcStart};`

let sixtyDayProfit = await window.ThreeCPM.Repository.Database.query(currentProfileID, sixtyQuery);
const totalDays = profitArray.length
Expand Down Expand Up @@ -160,8 +157,7 @@ const getTotalProfit = async (profileData: Type_Profile, filters: filters): Prom
closed_at != null
or finished = 1
and account_id in (${filters.accounts} )
and currency in (${filters.currency} )
and profile_id = '${profileData.id}';`
and currency in (${filters.currency} );`

const total = await window.ThreeCPM.Repository.Database.query(profileData.id, totalProfit);
return total[0].final_profit
Expand All @@ -185,7 +181,6 @@ const queryProfitDataByDay = async (profileData: Type_Profile, utcDateRange: utc
and account_id in (${filters.accounts} )
and currency in (${filters.currency} )
and closed_at_iso_string BETWEEN ${utcStart} and ${utcDateRange.utcEndDate}
and profile_id = '${profileData.id}'
GROUP BY
closed_at_str
ORDER BY
Expand Down Expand Up @@ -279,7 +274,7 @@ const getActiveDealsFunction = async (profileData: Type_Profile, filters: filter
finished = 0
and account_id in (${filters.accounts} )
and currency in (${filters.currency} )
and profile_id = '${profileData.id}'
`
let activeDeals: Type_ActiveDeals[] | [] = await window.ThreeCPM.Repository.Database.query(profileData.id, query)

Expand Down
6 changes: 3 additions & 3 deletions src/main/3Commas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async function getAccountData(profileData: Type_Profile): Promise<void> {
.then(async data => {
// 2. Delete all the data in the database that exist in the API response
const accountIds = data.map(account => account.account_id);
await run(profileData.id, `DELETE FROM accountData WHERE account_id in ( ${accountIds.join()}) and profile_id='${profileData.id}';`)
await run(profileData.id, `DELETE FROM accountData WHERE account_id in ( ${accountIds.join()});`)
return data
})
//3. Post the API response to the database.
Expand Down Expand Up @@ -95,10 +95,10 @@ async function getAndStoreBotData(profileData: Type_Profile): Promise<void> {
const botIDs = data.map(bot => bot.id)
const { id } = profileData

await run(id, `DELETE FROM bots WHERE id not in ( ${botIDs.join()}) and profile_id = '${id}' ;`)
await run(id, `DELETE FROM bots WHERE id not in ( ${botIDs.join()});`)

// // grabbing the existing bots
const currentBots = await query(id, `select id, hide from bots where origin = 'sync' and profile_id = '${id}';`)
const currentBots = await query(id, `select id, hide from bots where origin = 'sync';`)

data = data.map(bot => {
const current = currentBots.find(b => b.id == bot.id)
Expand Down

0 comments on commit 8fc7565

Please sign in to comment.