I just finished a similar piece of code for PM. Here's the GL version - a GL Transaction with Analytical Accouting code. It took me quite a while to get the bugs out so this will be valuable in the future.
This article contains a complete working version of an eConnect GL transaction that has Binary Stream and Analytical Accounting code.