How about using Etherscan's Event Log API?
https://api.etherscan.io/api?module=logs&action=getLogs
&fromBlock=0
&toBlock=latest
&address=[Token Contract Address]
&topic0=0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
&topic1=[From Address, padded to 32 bytes - optional]
&topic2=[To Address, padded to 32 bytes - optional]
In the above topic0
is the signature of an ERC20 Transfer
event.
For example, the following link shows you all the send transactions of LLL tokens from my account (two transactions).
Here, your X
(the token) is represented by the token's contract address, which is easy enough to find out for the various tokens.
As always, the API will return you a maximum of 10000 results, so you may need to manage fromBlock
and toBlock
accordingly.
Since you tagged your post with python, you might be especially interested in web3.py
docs and github.
Then you could run your own local geth
node, and use python to send ether, using:
from web3 import Web3, IPCProvider
web3 = Web3(IPCProvider())
web3.eth.sendTransaction({
'to': '0x5B2063246F2191f18F2675ceDB8b28102e957458',
'from': web3.eth.coinbase,
'value': 12345,
})
Best Answer
(The Ethplorer API is specific to ERC-20 tokens, so won't give you what you want.)
Price is subjective, and different exchanges will trade at different rates depending on the markets that use them.
If you want an average price you'll need to either use several APIs - from those exchanges you care about - and take an average, or use a service that automatically averages across all exchanges. (Also, if you use the first method, you might want to think about weighting the average by the trade volume on the exchanges.)
I think the CoinMarketCap API does the averaging and weighting across the exchanges it knows about:
Output:
If you want a different quote currency, rather than USD or BTC, then you can do that, too.