This is the Personal Stock Monitor scripting developers forum.
Subscribe to RSS Feed
Developing Custom Stock Market Software using PSM -> How to Modify an Existing Transaction?
Not logged in.
2010-11-23 05:43:50
1 of 6
#2542
Howdy All,

I'm writing an extension that needs to locate and modify an existing transaction in a ticker. The transaction to be located should be ...
 1) The very last transaction (most recent date) that was entered
 2) For only ONE share

My existing code ...

Set TransactionRecs = ticker.Transactions
If TransactionRecs.Item(TransactionRecs.Count).GetProperty("Shares") = 1 Then
  Set OneTransaction = TransactionRecs.Item(TransactionRecs.Count)
  OneTransaction.SetProperty "Date", G_EntryDate
  OneTransaction.SetProperty "Price", HistoryPrice
  ticker.ApplyTransactionToCurrentHoldings(OneTransaction)
End If

... does NOT update the existing entry in the "Current Position" listing, as displayed in the Transactions tab of the Properties dialog box. Rather, the code ADDS an entry into the "Current Position" listing (see Image1.jpg). However, the correct entry in the "Transaction History" listing IS updated correctly.

What is the code necessary to MODIFY the existing entry in the "Current Position" listing, instead of having a new entry ADDED?

Thank you,

-Don

Image1.jpg
Posted by: dgoyette
2010-11-24 08:09:44
2 of 6
#2544
in reply to #2542
Editing transactions was not something that we anticipated would be done from a script, so ApplyTransactionToCurrentHoldings() doesn't do the right thing in that case. I looked at the code that implements these functions, and it looks like using ticker.InsertTransaction will do the right thing, and will not add a duplicate transaction if the transaction is already a child of the ticker object.
Posted by: Anatoly
2010-11-24 14:45:39
3 of 6
#2546
in reply to #2544
Thank you Anatoly, I'll give that a try.
Posted by: dgoyette
2010-11-24 17:42:02
4 of 6
#2547
in reply to #2544
Since ApplyTransactionToCurrentHoldings() does not update a transaction, what is the actual purpose of this method? What objects will it actually update correctly?

Thanks,

-Don
Posted by: dgoyette
2010-11-25 01:06:48
5 of 6
#2559
in reply to #2547
It will work correctly if the transaction is first removed from the ticker object before you call the function, then you can add the transaction back. There is a reason why it works that way, but we should probably fix it to work the way you would expect.
Posted by: Anatoly
2010-11-25 01:14:31
6 of 6
#2561
in reply to #2559
Thank you Anatoly.

InsertTransaction() does work in this case, as you suggested, but the result is NOT what I would expect. I would expect an Insert method to ADD (Insert) a new transaction, not Apply an update to the transaction being worked on. Very confusing.
Posted by: dgoyette