You'd think a nation rescuing Iraq from a blockade of its oil exports could not possibly be on speaking terms with Iran. Yet Turkey, the NATO state bordering on each of the Gulf war combatants, is proving adept at a potentially perilous balancing act between the two.
Trade is the key element in the equation. Both the Iranians and the Iraqis have found good practical reason to stay friendly with the Turks, who provide each with a land bridge to the Mediterranean.
Yet Ankara seems increasingly aware of the potential dangers in trying to steer a middle course between two neighbors that are battling each other to the death.
Late last year a series of bomb explosions in Ankara and Istanbul, plus a foiled car-bomb attack near American and French facilities in the port city of Izmir, was claimed by a pro-Iranian group. The blasts were avowedly in ''retaliation against the crimes committed by the regime of Iraq.'' The Turks arrested a number of suspects, described as Iranian and Syrian nationals.
The Turks, even before the bombings, had been concerned about potential spillover of the Iran-Iraq conflict. Weeks earlier the Ankara authorities had, according to a report from the Iranian News Agency, banned distribution of some 40 periodicals printed in Iran.
More recently, an antiregime radio station in Iran broadcast a scathing attack on Iran's improving ties with Turkey. Saying that Ayatollah Khomeini once termed Turkey's rulers ''US agents and lackeys,'' the station accused Tehran of having done a ''180-degree turn'' to seek ''the friendship of international imperialism.''
In fact, the Turks seem determined to steer clear of too close a political identification with either of the foes, while providing an important trade outlet for both.
For Iraq, Turkey is a crucial oil-export link following the closure of a pipeline that used to ferry Iraqi crude across Syria to the sea. The Syrians, long at odds with Iraq, have backed Iran in the Gulf war.
In recent months, the Iraqis have won agreement from the Turks to expand the capacity of their substitute outlet for Iraqi oil. And in talks last month, the two states agreed to study the possibility of a second Iraqi-Turkish pipeline. A third pipeline - to supply Turkey with Iraqi natural gas - is also under joint study.
None of this, presumably, leaves Iran's ayatollahs smiling. But their own flourishing trade ties with the Turks seem ample compensation. Direct commerce and transshipment have increased to such an extent that Iran is now Turkey's major trade partner.
''There are no problems in Turkish-Iranian relations,'' remarked Iran's deputy transportation minister on a February visit to the Turkish port of Mersin. He was the second senior Iranian official in three months to visit Mersin, where facilities have recently been upgraded to speed transshipment of goods destined for Iran.
Tehran radio, for its part, noted last month that the value of Turkish exports to Iran had jumped from about $55 million in 1975-76 to $1.35 billion in 1982-83. Iran's non-oil exports to Turkey, which gets some oil from both Iran and Iraq, had vaulted from $300,000 to $2 million.
Turkey has, with one major exception, focused largely on the economic side of its relations with Iran and Iraq.
There was also one minor exception: an offer to mediate in the war. The pitfalls in any such endeavor cannot have been lost on Turkish Foreign Minister Vahit Halefoglu, who visited Tehran earlier this month. Only a day after meeting the Turkish visitor, Iranian parliament speaker Hashemi Rafsanjani was quoted by Tehran radio as having said that ''95 percent of the mediators lie.'' There would not seem much to recommend the Turks' investigating whether they are among the lucky 5 percent.
Of greater magnitude has been Turkey's shared interest with Iraq and Iran in keeping the countries' respective Kurdish populations under control. Most of these tough and restive hill people live near the area where Turkey, Iraq, and Iran meet.
Since the Turkish military coup in 1980, a new crackdown on Kurdish separatists has been under way there.
Last year, the Turks reportedly launched what was called a ''limited'' military operation against Kurdish rebels over the border in Iraq. Turkish officials denied the reports. In January, in a move some analysts saw as related partly to the Kurdish question, Turkey and Iraq agreed to ''cooperate more closely in the field of security, and to take effective measures to prevent (cross-border) smuggling.'' Earlier this month, there were again Western news reports of Turkish air strikes against Kurdish positions, this time in Iraqi and Iranian frontier areas.