Skip to content

Commit

Permalink
Merge pull request #69 from pazwicker/FEATURE-account-history
Browse files Browse the repository at this point in the history
Feature: account history
  • Loading branch information
hammem authored Jan 20, 2024
2 parents 878801d + e4a1e7a commit cdd8aa7
Show file tree
Hide file tree
Showing 2 changed files with 234 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ As of writing this README, the following methods are supported:
- `get_accounts` - gets all the accounts linked to Monarch Money
- `get_account_holdings` - gets all of the securities in a brokerage or similar type of account
- `get_account_type_options` - all account types and their subtypes available in Monarch Money-
- `get_account_history` - gets all daily account history for the specified account
- `get_institutions` -- gets institutions linked to Monarch Money
- `get_budgets` — all the budgets and the corresponding actual amounts
- `get_subscription_details` - gets the Monarch Money account's status (e.g. paid or trial)
Expand Down
233 changes: 233 additions & 0 deletions monarchmoney/monarchmoney.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,239 @@ async def get_account_holdings(self, account_id: int) -> Dict[str, Any]:
variables=variables,
)

async def get_account_history(self, account_id: int) -> Dict[str, Any]:
"""
Gets historical account snapshot data for the requested account
Args:
account_id: Monarch account ID as an integer
Returns:
json object with all historical snapshots of requested account's balances
"""

query = gql(
"""
query AccountDetails_getAccount($id: UUID!, $filters: TransactionFilterInput) {
account(id: $id) {
id
...AccountFields
...EditAccountFormFields
isLiability
credential {
id
hasSyncInProgress
canBeForceRefreshed
disconnectedFromDataProviderAt
dataProvider
institution {
id
plaidInstitutionId
url
...InstitutionStatusFields
__typename
}
__typename
}
institution {
id
plaidInstitutionId
url
...InstitutionStatusFields
__typename
}
__typename
}
transactions: allTransactions(filters: $filters) {
totalCount
results(limit: 20) {
id
...TransactionsListFields
__typename
}
__typename
}
snapshots: snapshotsForAccount(accountId: $id) {
date
signedBalance
__typename
}
}
fragment AccountFields on Account {
id
displayName
syncDisabled
deactivatedAt
isHidden
isAsset
mask
createdAt
updatedAt
displayLastUpdatedAt
currentBalance
displayBalance
includeInNetWorth
hideFromList
hideTransactionsFromReports
includeBalanceInNetWorth
includeInGoalBalance
dataProvider
dataProviderAccountId
isManual
transactionsCount
holdingsCount
manualInvestmentsTrackingMethod
order
icon
logoUrl
type {
name
display
group
__typename
}
subtype {
name
display
__typename
}
credential {
id
updateRequired
disconnectedFromDataProviderAt
dataProvider
institution {
id
plaidInstitutionId
name
status
logo
__typename
}
__typename
}
institution {
id
name
logo
primaryColor
url
__typename
}
__typename
}
fragment EditAccountFormFields on Account {
id
displayName
deactivatedAt
displayBalance
includeInNetWorth
hideFromList
hideTransactionsFromReports
dataProvider
dataProviderAccountId
isManual
manualInvestmentsTrackingMethod
isAsset
invertSyncedBalance
canInvertBalance
type {
name
display
__typename
}
subtype {
name
display
__typename
}
__typename
}
fragment InstitutionStatusFields on Institution {
id
hasIssuesReported
hasIssuesReportedMessage
plaidStatus
status
balanceStatus
transactionsStatus
__typename
}
fragment TransactionsListFields on Transaction {
id
...TransactionOverviewFields
__typename
}
fragment TransactionOverviewFields on Transaction {
id
amount
pending
date
hideFromReports
plaidName
notes
isRecurring
reviewStatus
needsReview
dataProviderDescription
attachments {
id
__typename
}
isSplitTransaction
category {
id
name
icon
group {
id
type
__typename
}
__typename
}
merchant {
name
id
transactionsCount
__typename
}
tags {
id
name
color
order
__typename
}
__typename
}
"""
)

variables = {"id": str(account_id)}

account_details = await self.gql_call(
operation="AccountDetails_getAccount",
graphql_query=query,
variables=variables,
)

# Parse JSON
account_name = account_details["account"]["displayName"]
account_balance_history = account_details["snapshots"]

# Append account identification data to account balance history
for i in account_balance_history:
i.update(dict(accountId=str(account_id)))
i.update(dict(accountName=account_name))

return account_balance_history

async def get_institutions(self) -> Dict[str, Any]:
"""
Gets institution data from the account.
Expand Down

0 comments on commit cdd8aa7

Please sign in to comment.