bvanelli / actualpy

Python API implementation for Actual server - reference https://actualbudget.org/
20 stars 4 forks source link

[New Feature] - Add new Bank Sync Functionality #25

Closed latetedemelon closed 2 months ago

latetedemelon commented 3 months ago

Thanks for all the hard work putting this together. Please consider this request to add the new bank sync functionality:

https://github.com/actualbudget/actual/pull/2683

bvanelli commented 3 months ago

Hello @latetedemelon , thanks for your interest in the project! I was planning to integrate such functionality. I mapped the API calls from the

I think this info is for now enough for the API models, but the resolution of the transactions is unfortunatelly not that straight forward (at least I know by lookimg at actual source code that you also have to resolve edge cases, like transactions added manually, ending balance that does not match, etc). Since this is a bigger issue I'll focus first on getting the pip release ready (https://github.com/bvanelli/actualpy/issues/14) and then try to implement this functionality.

For reference, here is the flow for Simplefin (since they have a beta token easily available):

{
   "status":"ok",
   "data":{
      "accounts":[
         {
            "org":{
               "domain":"example.com",
               "sfin-url":"https://beta-bridge.simplefin.org/simplefin"
            },
            "id":"Demo Savings",
            "name":"SimpleFIN Savings",
            "currency":"USD",
            "balance":"115524.49",
            "available-balance":"115524.49",
            "balance-date":1719792000,
            "transactions":[
               {
                  "id":"1717315200",
                  "posted":1717315200,
                  "amount":"-10.00",
                  "description":"Fishing bait",
                  "payee":"John's Fishin Shack",
                  "memo":"JOHNS FISHIN SHACK BAIT"
               }
            ],
            "holdings":[
               {
                  "id":"25bc4910-4cb4-437b-9924-ee98003651c5",
                  "created":345427200,
                  "cost_basis":"55.00",
                  "currency":"USD",
                  "description":"Shares of Apple",
                  "market_value":"105884.8",
                  "purchase_price":"0.10",
                  "shares":"550.0",
                  "symbol":"AAPL"
               }
            ]
         },
         {
            "org":{
               "domain":"example.com",
               "sfin-url":"https://beta-bridge.simplefin.org/simplefin"
            },
            "id":"Demo Checking",
            "name":"SimpleFIN Checking",
            "currency":"USD",
            "balance":"26134.41",
            "available-balance":"26134.41",
            "balance-date":1719792000,
            "transactions":[
               {
                  "id":"1717315200",
                  "posted":1717315200,
                  "amount":"-13.31",
                  "description":"Fishing bait",
                  "payee":"John's Fishin Shack",
                  "memo":"JOHNS FISHIN SHACK BAIT"
               }
            ],
            "holdings":[

            ]
         }
      ]
   }
}
{
   "status":"ok",
   "data":{
      "balances":[
         {
            "balanceAmount":{
               "amount":"26134.41",
               "currency":"USD"
            },
            "balanceType":"expected",
            "referenceDate":"2024-07-01"
         },
         {
            "balanceAmount":{
               "amount":"26134.41",
               "currency":"USD"
            },
            "balanceType":"interimAvailable",
            "referenceDate":"2024-07-01"
         }
      ],
      "startingBalance":2613441,
      "transactions":{
         "all":[
            {
               "booked":true,
               "bookingDate":"2024-04-03",
               "date":"2024-04-03",
               "debtorName":"John's Fishin Shack",
               "remittanceInformationUnstructured":"Fishing bait",
               "transactionAmount":{
                  "amount":"-19.96",
                  "currency":"USD"
               },
               "transactionId":"1712131200",
               "valueDate":"2024-04-03"
            },
            {
               "booked":true,
               "bookingDate":"2024-04-03",
               "date":"2024-04-03",
               "debtorName":"Grocery store",
               "remittanceInformationUnstructured":"Grocery store",
               "transactionAmount":{
                  "amount":"-163.36",
                  "currency":"USD"
               },
               "transactionId":"1712160000",
               "valueDate":"2024-04-03"
            },
         ],
         "booked":[
            {
               "booked":true,
               "bookingDate":"2024-04-03",
               "date":"2024-04-03",
               "debtorName":"John's Fishin Shack",
               "remittanceInformationUnstructured":"Fishing bait",
               "transactionAmount":{
                  "amount":"-19.96",
                  "currency":"USD"
               },
               "transactionId":"1712131200",
               "valueDate":"2024-04-03"
            },
            {
               "booked":true,
               "bookingDate":"2024-04-03",
               "date":"2024-04-03",
               "debtorName":"Grocery store",
               "remittanceInformationUnstructured":"Grocery store",
               "transactionAmount":{
                  "amount":"-163.36",
                  "currency":"USD"
               },
               "transactionId":"1712160000",
               "valueDate":"2024-04-03"
            }
         ],
         "pending":[

         ]
      }
   }
}
JaxOfDiamonds commented 3 months ago

I literally came here to ask the same! But thinking about it - I wonder if integrating with SimpleFin directly and then adding the transactions with the API would give extra control. Though that is likely beyond the scope of this project.t