Harold Wentworth & Stuart Flexner, Dictionary of American Slang, first edition (1960) has this ebtry for "the nuts":
nuts, the [or] nerts, the Any excellent thing or person. 1934: "Eulogizing anything ... as 'the nerts.' ..." Eng. Jour., Nov., 740.
A Google Books search finds a number of slightly earlier occurrences of "the nerts" in the relevant sense. Here are the three earliest. From The Judge, volume 95 (1928)[combined snippets]:
Just a formal card which may be sent to anybody: The Christmas spirit is the nerts/Give and give until it hurts.
One mention of "the nerts" from 1932 attributes it to "the vernacular of 'Ballyhoo'." As for Ballyhoo, Silas Bent, Ballyhoo: The Voice of the Press (1927) [combined snippets] offers this description of it as carnival-barker lingo:
My dear Mr. Bent: The term ballyhoo is a contraction of Ballyhooly, which is a proper name that designates a village east of Mallow in Cork County, Ireland. The village was long famous for its party fights, and to give or to get Ballyhooly was to berate or be berated.
Ballyhoo as a noun has been said to be synonymous with barker in the slang sense of this word — one who stands outside the entrance of the side shows of a circus and attracts an audience by exaggerated claims of the novelties within the side show—for instance, "Walk in, ladies and gentlemen, walk in and see a live lion stuffed with straw; the only living specimen of that marvellous mastodon, the gyascutus. Also, the greatest curiosity of modern times, a horse with his head where his tail ought to be."
From Life magazine (volume 94) (1929) [combined snippets]:
It [talking movies] was a featured topic at the last meeting of the Thursday Club in Gallipolis, O. You hear it broadcast over the radio and tabloid headlines scream: "Squawkies Are The Nerts!"
From The Railwayan, volume 14 (1930) [combined snippets]:
It was decorated much the same as last year, with the exception of a tree we fixed up, and a few more wreaths at the windows, with red and green garlands decorating the lunch room windows and walls. Oh, ki-e-ed, it was the nerts all right! And this year the boys had Christmas among themselves here at the car house, with a present on the tree for everybody—and you should have seen some of the things the boys got!
James Maitland, The Dictionary of American Slang (1891) has this entry for "nuts":
Nuts, "to be nuts" or "dead nuts" on any man, person or thing, is to be pleased with or fond of the same.
This seems to express the same fondness that "the nuts/the nerts" in its positive aspect conveys. J.E. Lighter, Random House Historical Dictionary of American Slang, volume 2 (1997) offers this note about the source of the slang word nuts in the sense of "fond (of); infatuated, fascinated, or obsessed (with); very enthusiastic (about)":
[Eric] Partridge, [A] Dict[ionary of the] Und[erworld, British and American]  reasonably sugg[ests] a semantic basis in "sweet on," infl[uenced] by [the] cliché sweet as a nut.
So "sweet as a nut" yields "nuts" meaning "fond of," which produces "the nuts/the nerts" meaning "any excellent thing," which crystallizes in card playing into the meaning "a great hand (of cards)."