Skip to content

Commit

Permalink
Merge pull request #64 from CalvinChanCan/main
Browse files Browse the repository at this point in the history
feat: Manual Account Creation, Create Transaction Behavior, and Documentation Updates
  • Loading branch information
hammem authored Jan 9, 2024
2 parents 9a49267 + c682dce commit 1240127
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 4 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ 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_budgets` — all the budgets and the corresponding actual amounts
- `get_subscription_details` - gets the Monarch Money account's status (e.g. paid or trial)
- `get_transactions_summary` - gets the transaction summary data from the transactions page
- `get_transactions` - gets transaction data, defaults to returning the last 100 transactions; can also be searched by date range
- `get_transaction_categories` - gets all of the categories configured in the account
- `get_transaction_category_groups` all category groups configured in the account-
- `get_transaction_details` - gets detailed transaction data for a single transaction
- `get_transaction_splits` - gets transaction splits for a single transaction
- `get_transaction_tags` - gets all of the tags configured in the account
Expand All @@ -77,12 +79,15 @@ As of writing this README, the following methods are supported:
## Mutating Methods

- `delete_transaction_category` - deletes a category for transactions
- `request_accounts_refresh` - requests a syncronization / refresh of all accounts linked to Monarch Money. This is a **non-blocking call**. If the user wants to check on the status afterwards, they must call `is_accounts_refresh_complete`.
- `request_accounts_refresh_and_wait` - requests a syncronization / refresh of all accounts linked to Monarch Money. This is a **blocking call** and will not return until the refresh is complete or no longer running.
- `delete_transaction_categories` - deletes a list of transaction categories for transactions
- `request_accounts_refresh` - requests a synchronization / refresh of all accounts linked to Monarch Money. This is a **non-blocking call**. If the user wants to check on the status afterwards, they must call `is_accounts_refresh_complete`.
- `request_accounts_refresh_and_wait` - requests a synchronization / refresh of all accounts linked to Monarch Money. This is a **blocking call** and will not return until the refresh is complete or no longer running.
- `create_transaction` - creates a transaction with the given attributes
- `update_transaction` - modifes one or more attributes for an existing transaction
- `update_transaction_splits` - modifes how a transaction is split (or not)
- `update_transaction` - modifies one or more attributes for an existing transaction
- `delete_transaction` - deletes a given transaction by the provided transaction id
- `update_transaction_splits` - modifies how a transaction is split (or not)
- `set_budget_amount` - sets a budget's value to the given amount (date allowed, will only apply to month specified by default). A zero amount value will "unset" or "clear" the budget for the given category.
- `create_manual_account` - creates a new manual account

# Contributing

Expand Down
96 changes: 96 additions & 0 deletions monarchmoney/monarchmoney.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,100 @@ async def get_accounts(self) -> Dict[str, Any]:
graphql_query=query,
)

async def get_account_type_options(self) -> Dict[str, Any]:
"""
Retrieves a list of available account types and their subtypes.
"""
query = gql(
"""
query GetAccountTypeOptions {
accountTypeOptions {
type {
name
display
group
possibleSubtypes {
display
name
__typename
}
__typename
}
subtype {
name
display
__typename
}
__typename
}
}
"""
)
return await self.gql_call(
operation="GetAccountTypeOptions",
graphql_query=query,
)

async def create_manual_account(
self,
account_type: str,
account_sub_type: str,
is_in_net_worth: bool,
account_name: str,
account_balance: float = 0,
) -> Dict[str, Any]:
"""
Creates a new manual account
:param account_type: The string of account group type (i.e. loan, other_liability, other_asset, etc)
:param account_sub_type: The string sub type of the account (i.e. auto, commercial, mortgage, line_of_credit, etc)
:param is_in_net_worth: A boolean if the account should be considered in the net worth calculation
:param account_name: The string of the account name
:param display_balance: a float of the amount of the account balance when the account is created
"""
query = gql(
"""
mutation Web_CreateManualAccount($input: CreateManualAccountMutationInput!) {
createManualAccount(input: $input) {
account {
id
__typename
}
errors {
...PayloadErrorFields
__typename
}
__typename
}
}
fragment PayloadErrorFields on PayloadError {
fieldErrors {
field
messages
__typename
}
message
code
__typename
}
"""
)
variables = {
"input": {
"type": account_type,
"subtype": account_sub_type,
"includeInNetWorth": is_in_net_worth,
"name": account_name,
"displayBalance": account_balance,
},
}

return await self.gql_call(
operation="Common_CreateTransactionMutation",
graphql_query=query,
variables=variables,
)

async def request_accounts_refresh(self, account_ids: List[str]) -> bool:
"""
Requests Monarch to refresh account balances and transactions with
Expand Down Expand Up @@ -848,6 +942,7 @@ async def create_transaction(
merchant_name: str,
category_id: str,
notes: str = "",
update_balance: bool = False,
) -> Dict[str, Any]:
"""
Creates a transaction with the given parameters
Expand Down Expand Up @@ -888,6 +983,7 @@ async def create_transaction(
"merchantName": merchant_name,
"categoryId": category_id,
"notes": notes,
"shouldUpdateBalance": update_balance,
}
}

Expand Down

0 comments on commit 1240127

Please sign in to comment.