A bitcoin transaction is composed of inputs (coins) and output (coins). As example, if a transaction has 10 inputs worth 1 BTC each, and 10 outputs worth 1 BTC each, there is no meaningful way to discern "which input become which output?", it is a nonsensical question at a technical level. Think of it as if all of the inputs are melded together, and then the outputs are forged anew from this blob.
So in relation to your question, the best you could do is to write some code to report back with a full index of bitcoin outputs that share a history with the output in question. This would mean finding the history of every input to the transaction that paid you, and every input to those transactions... and so on, until you reach coinbase outputs for every possible path.
For a lot of outputs, I think this history would likely be absolutely massive, tracing back to a large number of coinbase transactions across time. Very very few outputs would be traceable back to a single coinbase output!