A federal judge yesterday ordered Allegheny Beverage Corp. to stop buying stock in the Macke Co., after Macke lawyers argued that Allegheny was making an illegal attempt to take over the Washington vending, food and furniture business.

U.S. District Court Judge John Garrett Penn issued a temporary restraining order halting Allegheny's stock-buying for 10 days after a hearing yesterday afternoon at which Macke accused Allegheny of violating federal securities law.

Judge Penn did not rule on the legality of Allegheny's actions, but accepted Macke's contention that the company might be irreparably damaged if Allegheny's buying continued.

For the past few days, Allegheny has been buying tens of thousands of shares of Macke daily on the New York Stock Exchange. In yesterday's trading, Macke stock closed at 13 5/8, down from 14 1/4, on unusually heavy volume of 265,000 shares.

On Monday Allegheny bought 41,000 shares, almost half of the 88,900 Macke shares traded, boosting its holdings to 603,700 shares or 19.9 percent of Macke. Allegheny's purchases were disclosed in reports to the Securities and Exchange Commission by the Baltimore firm, which holds the Pepsi-Cola and Dr. Pepper franchises for much of the Middle Atlantic region.

The day before, Allegheny reported to the SEC that it owned 562,700 shares or 18.5 percent. A month ago the reported holdings totaled 450,000 shares, 14.8 percent.

At yesterday's court hearing, Macke lawyers told Judge Penn they believed Allegheny was negotiating to purchase 300,000 Macke shares from E.F. Hutton, the big New York broker. The 300,000-share block is nearly 10 percent of Macke.

The Macke investments reported by Allegheny as of Monday show the Baltimore firm's holdings are approaching those of the company's two biggest shareholders, chairman Meyer Gelfand and former chairman Aaron Goldman and their families, who control 23 percent.

Before the injunction was issued yesterday, Allegheny Vice President Harry Conn said the company intended to continue its announced plan to keep buying Macke stock until it acquired at least 25 percent of the Washington company. Allegheny officials could not be reached for comment after the court action.

Macke is twice as big a business as Allegheny, with sales of $261 million last year, compared to Allegheny's $129 million. Macke's principal business is vending machines, coin operated laundry equipment and business food service. It also owns the Family Fish House chain and the D & F office furniture stores.