NEW YORK, Oct 5 (Reuters) - Sam Bankman-Fried's college roommate and ex-colleague at the now-bankrupt FTX cryptocurrency exchange, Gary Wang, took the stand at the 31-year-old former billionaire's fraud trial on Friday.

Wang, FTX's former chief technology officer, is the first of three former close associates of Bankman-Fried to testify at the trial, which began on Tuesday. All three have pleaded guilty to fraud charges and agreed to cooperate with prosecutors.

Bankman-Fried's trial kicked off nearly a year after FTX froze customer withdrawals and declared bankruptcy in a dramatic collapse that shocked financial markets and left its founder's reputation in tatters.

Federal prosecutors in Manhattan say Bankman-Fried stole billions of dollars in FTX customer deposits to plug losses at his hedge fund, Alameda Research, buy real estate and donate to U.S. political candidates.

"All that was left in FTX was what amounted to an IOU from Alameda," prosecutor Thane Rehn said in his opening statement on Wednesday.

Bankman-Fried has pleaded not guilty. His lawyer, Mark Cohen, said in his opening statement that cooperating witnesses like Wang may be "spinning things that Sam said and did at the time that were good-faith business decisions that they themselves were fine with" as "sinister" in hindsight.

Wang and Bankman-Fried met at a math camp in high school and later became roommates at the Massachusetts Institute of Technology. They were also among 10 FTX and Alameda employees who lived together in a $35 million penthouse apartment in the Bahamas, where FTX was based.

In pleading guilty last December, Wang said he was directed to make changes to FTX's software code to give Alameda special privileges on the trading platform, while being aware that others were telling investors and customers that Alameda had no such privileges.

Wang did not specify at the time who gave him those directions, but prosecutors say it was Bankman-Fried.

Earlier this week, jurors heard from Adam Yedidia, a former FTX computer programmer who reported to Wang and was also friends with Bankman-Fried at MIT.

Yedidia said that in fixing an error in FTX's code in June 2022, he saw that Alameda owed FTX $8 billion. The debt had arisen because the exchange could not open its own bank accounts and had instructed FTX's users to wire money to Alameda, he said.

But Yedidia grew concerned that the debt was too large, and asked Bankman-Fried about it while playing padel tennis at their Bahamas apartment complex. He said Bankman-Fried appeared worried as well.

"Sam said something like, 'we were bulletproof last year, but we're not bulletproof this year,'" Yedidia testified on Thursday.

At the trial on Thursday, Bankman-Fried took a break from typing on a laptop on the defense table in front of him to look up at Yedidia as he walked by before testifying. Yedidia did not turn to look at him.

The defendant's parents, the Stanford Law School professors Joseph Bankman and Barbara Fried, took notes on a yellow legal pad that they passed back and forth to each other as Yedidia testified.

Other cooperating witnesses set to testify include Nishad Singh, FTX's former engineering chief, and Caroline Ellison, Alameda's former chief executive officer and Bankman-Fried's on-and-off girlfriend.

(Reporting by Luc Cohen in New York Editing by Amy Stevens and Matthew Lewis)