Created
September 25, 2019 18:01
-
-
Save sedaghatfar/1b97d16e6d42d10fb30a47f851e454e6 to your computer and use it in GitHub Desktop.
eth roll function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def etherroll(fromBlock,toBlock): | |
address = '0xa52e014b3f5cc48287c2d483a3e026c32cc76e6d' | |
topic0 = '0x8dd0b145385d04711e29558ceab40b456976a2b9a7d648cc1bcd416161bf97b9' | |
apikey = 'yourapikey' | |
url = f'https://api.etherscan.io/api?module=logs&action=getLogs&fromBlock={fromBlock}&toBlock={toBlock}&address={address}&topic0={topic0}&apikey={apikey}' | |
request = requests.get(url) | |
results = request.json() | |
new = [] | |
i = 0 | |
while i < len(results['result']): | |
mdata = results['result'][i]['data'] | |
address = results['result'][i]['topics'][3] | |
block = int(results['result'][i]['blockNumber'],16) | |
timest = datetime.datetime.fromtimestamp(int(results['result'][i]['timeStamp'],16)).strftime('%Y-%m-%d %H:%M:%S') | |
new.append([ | |
address | |
,block | |
,timest | |
,int(mdata[2:66], 16) | |
,int(mdata[66:130], 16) | |
,int(mdata[130:194], 16)/1000000000000000000 | |
]) | |
i += 1 | |
edf = pd.DataFrame(new, columns = ['address','block','timestamp','roll under', 'roll', 'amount']) | |
edf.dropna | |
edf['result'] = np.where(edf['roll']<edf['roll under'], 1, 0) | |
edf['wager'] = round(edf.amount*((edf['roll under']-1)/100)*(1.01010101010101),3) | |
edf['profit'] = np.where(edf['result']==1,edf['amount'] - edf['wager'],edf['wager']*(-1)) | |
return edf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment