Offline Backup

Could someone with api access try adding some cash transactions to a cash account and see if they have any issues with the transaction date?

The code below should add 80 transactions - 20 transactions on June 1st, 20 on June 8th, 20 on June 15th and 20 on June 22nd. I’ve used various methods of defining the date format for each batch.

From my tests I often end up with some transactions appearing a day early or late, regardless of the method I use for the date format. You can also see that the response from the PUT call gives variable date format responses (the time and timezone fluctuate).

Interested to see if anyone else has encountered this issue.

from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session
import requests
from datetime import datetime
import pytz

client_id = ""  # From https://portfolio.sharesight.com/oauth_consumers
client_secret = ""  # From https://portfolio.sharesight.com/oauth_consumers
access_token_url = r"https://api.sharesight.com/oauth2/token"

client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(
	token_url=access_token_url, client_id=client_id, client_secret=client_secret
)
access_token = token["access_token"]
cash_account_id = ""    # cash account id is available at the end of a cash transaction account
						# easiest to make a new cash account (you'll need to be on Investor level or higher)
						# https://portfolio.sharesight.com/cash_accounts/#####

i = 0
aest = pytz.timezone("Australia/Melbourne")
dt = datetime.strptime("2021-6-1", "%Y-%m-%d")
dt = aest.localize(dt)

date_str_1 = datetime.isoformat(dt, sep="T", timespec="milliseconds")
date_str_2 = "2021-06-08T00:00:00.000+10:00"
date_str_3 = "2021-06-15T00:00:00.000Z"
date_str_4 = "2021-06-22"
print(
	f"date format 1 - {date_str_1}\ndate format 2 - {date_str_2}\n"
	f"date format 2 - {date_str_3}\ndate format 3 - {date_str_4}"
)

for i in range(0, 80):
	trans_json = {
		"access_token": access_token,
		"cash_account_transaction": {
			"description": "Random Deposit",
			"amount": 20,
			"date_time": date_str_1
			if i < 20
			else date_str_2
			if i < 40
			else date_str_3
			if i < 60
			else date_str_4,
			"type_name": "DEPOSIT",
		},
	}
	r = requests.post(
		f"https://api.sharesight.com/api/v2/cash_accounts/{cash_account_id}/cash_account_transactions.json",
		json=trans_json,
	)
	print(i, " - ", r.status_code, " - ", r.text)

3 Likes