Commodity industry lobbyists worked late on the night of July 9, drafting a bill to save themselves $400 million a year in taxes.

They went to be confident they had cut a deal with the House Ways and Means Committee, and the next morning, before the committee had even voted, the Chicago commodity traders began to cash in.

The usually quiet corners of the Chicago Board of Trade where mortgages and government bond futures contracts are traded exploded in a surge of business that stunned market watchers.

Both the Commodity Futures Trading Commission and the trading desk of the Federal Reserve Board took note of the unexpected spurt in trading that occurred simultaneously with the committee's action.

On July 9, only 11 contracts for March 1984 mortgages had been traded, but the next day trading volume mushroomed to 6,700 contracts.

The same thing happened in the pits where Treasury bond futures are bought and sold. Trading in one bond future jumped from 169 contracts on July 9 to 5,060 on July 10; another bond jumped overnight from 204 contracts to 8,725.

Futures contracts in Treasury bonds and Government National Mortgage Association mortgages are the principal vehicles now used in a tax-avoidance loophole known as the commodity straddle that the IRS and tax reformers are trying to outlaw.

On the day that trading in the two contracts exploded, the Ways and Means Committee voted 25 to 8 to keep the commodity straddle loophole open. The Senate earlier had voted to close the loophole. Late Friday a conference committee was named to decide the fate of the straddle.

The bill the Ways and Means Committee approved on July 10 had been drafted the night before with the direct participation of Leslie Rosenthal, chairman of the Chicago Board of Trade, and Leo Melamed, special counsel to the Chicago Mercantile Exchange.

Two Illinois Democrats who had received campaign contributions from the wealthy Chicago commodity exchanges provided the chief support for the industry's bill -- Reps. Martin Russo and Dan Rostenkowski, the committee chairman.

Russo collected $84,000 in campaign contributions in the first six months of 1981, much of it from commodity industry sources, reports filed Friday with the Federal Election Commission show, Russohs recent contributors include Carl Arnold, a Washington lobbyist representing the commodity industry and the Auction Markets Political Action Committee of the Chicago Board of Trade.

Campaign contribution reports for the first half of 1981 were due at the FEC Friday afternoon, but not all of them were available at the end of the day. Commodity contributions show up on the reports of half a dozen Ways and Means Committee members who voted for the straddle bill.

The total contributions by the commodity industry to save its straddles will not be disclosed until late next week, after the straddle issue has been settled in Congress.

The Ways and Means vote was a major victory for the commodity industry, which marshaled a bipartism panel of politically influential supporters to argue its case. The industry's hired guns range across the political spectrum from former Democractic National Committee chairman Robert Strauss to John T. (Terry) Dolan of the National Conservative Political Action Committee.

NCPAC's help backfired when it was disclosed Dolan had not registered to lobby on the straddle issue. The Justice Department is investigating possible lobbyist registration violations by Dolan and also had been asked to determine whether Dolan violated federal bribery laws by offering to advertise for representatives who would vote in favor of straddles.

Commodity industry lobbyists have invested thousands of hours of lobbying time trying to get a special dispensation so complicated that only a handful of people outside the industry understand all its ramifications.

The Ways and Means Committee members did not even have a copy of the industry bill when they voted for it on July 10, committee sources said. Details of the legislation were still being polished when the full House accepted the committee bill last week as part of President Reagan's three-year tax package.

The House version of the straddle tax bill would legalize loopholes that the Senate voted earlier to close.The industry-backed bill would also stop efforts by the IRS to halt the use of straddles through court action.

The differences between the two bills add up to $400 million a year and the question of whether a small group of taxpayers -- those who speculate in the commodity market -- should be allowed to squeeze through a loophole that has been closed to everyone else.

The tough Senate bill sponsored by Daniel Patrick Moynihan (D-N.Y.), would outlaw any tax deductions produced by using commodity straddles. The same thing would have been accomplished by a House bill introduced by Reps. William Brodhead (D-Mich.), and Benjamin Rosenthal (D-N.Y.)

The Reagan administration endorsed the bills, which would raise $1.3 billion in taxes.

But the Ways and Means Committee rejected the Brodhead-Rosenthal bill in favor of the industry version sponsored by Russo that allows straddle losses to be deducted from commodity profits.

The chief beneficiaries would be the 3,500 professional commodity traders in Chicago, said an aide to Brodhead.

Even the Senate bill would give commodity traders a special tax break. The Reagan administration's tax package cuts the maximum income tax on most investments from the present 70 percent to 50 percent. Commodity profits, however, would be taxed at no more than 30 percent under the Senate bill.

Most industry lobbyists would go home bragging if they could take credit for cutting their clients' tax rate to 60 percent of what everybody else pays. But not the lawyers and lobbyists working on the straddle bill.

They've tried in the past two weeks to slip several exemptions into the Senate version. In an unusual action, Securities and Exchange Commission Chairman John Shad wrote a letter endorsing one of the exemptions, which would have applies only to aboiut 500 stock market specialists.

That exemption, tacked on to the Senate bill by Sen. Alfonse D'Amato, (R-N.Y.), would allow the specialists to adjust their records retroactively to shift investments from one account to another, potentially reducing their tax bill.

Shad argued that the provision was needed for orderly operation of the stock market, the same claim made by commodity lobbyists in their effort to protect the commodity straddle.

A commodity straddle is an arcane investment that's been described as equivalent to betting on both sides in a football game. An IRS consultant calculated that the odds against making a profit on the most popular kind of tax straddle are less than the chances of winning at roulette.

But regardless of the profit potential, a straddle can reduce taxes and in some cases defer than forever.

To set up a straddle, an investor simultaneously buys and sells contracts for future delivery of some commodity. Regardless of whether the price of the commodity goes up or down, the straddler will make money on one of the contracts and lose about the same amount on the other.

The trick is to cash in the losing contract and deduct the loss from other income this year. The profitable contract is held until next year.

If the profitable contract is held more than six months, the income from it is taxed as long-term capital gains at rates as low as 28 percent. The deduction on the losing contract could offset income on which the rate is as high as 70 percent.

Thus the straddle cuts the tax bill from 70 percent to 28 percent. Even that tax can be avoided if another straddle is set up the following year, so the earings are "rolled forward" year after year.

Big commodity traders have been doing that for years, continually delaying their date with the tax collector. The practice has become so common in the commodity industry that the straddle bills offer special arrangements for paying the taxes that will be due if straddles are outlawed. The bill gives straddle users five years to pay their previously deferred earnings.

Moynihan's Senate bill taxes straddles using what is called a "mark to market" approach. At the end of each year, commodity traders would have to add up the accumulated profits and losses on all their contracts, even those that have not been cashed in. That would make it impossible to defer straddle income until the following year.

The industry bill uses what is called "a market basket" to limit the write-offs for straddle losses. They could be deducted only from income from other commodities. The industry claims that would stop doctors, dentists and rock stars from using the commodity markets to shelter their incomes.

Industry insiders deserve to be permitted to continue to use straddles because of the importance of the commodity markets, the industry contends. Without special tax advantages, the lobbyists argue, no one would speculate in commodities; the result would be unstable commodity prices.

That argument is dismissed by Treasury Secretary Donald T. Regan, who has emerged as a forceful advocate of taxing straddles. Regan formerly was chairman of Merrill Lynch, Pierce, Fenner & Smith, which like many brokerage firms helps arrange straddles for its customers.

Tax trading does nothing to benefit the markets, Regan retorted last week when the issue was raised.

Nor has the threat to the commodity market swayed Sen. Robert Dole (R-Kan.), whose political future depends on stable prices for Kansas wheat farmers. Dole has denounced the commodity industry's bill, and as chairman of the Senate Finance Committee, may be able to assure that it is defeated.