The phrase is known from the early 20th century and originated as horse racing parlance. The earliest record that I can find is from Arthur Binstead's novel Mop Fair, 1905, or, to give it its glorious technicolour name, Mop Fair. Some Elegant Extracts from the Private Correspondence of Lady Viola Drumcree, the Fatherless Daughter of Feodorovna, Countess of Chertsey: