Skip to content

Commit

Permalink
get_payments() for earnings
Browse files Browse the repository at this point in the history
  • Loading branch information
barlaensdoonn committed Jul 30, 2017
1 parent fd07afd commit 965a011
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion dcrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import bttrx
import minor
import requests
from datetime import datetime, timedelta


# NOTE: getusertransactions only returns last 100 transactions
Expand All @@ -23,6 +24,16 @@ def _request(action):
return r.json()[action]['data']


def _convert_to_datetime(pymnt_lst):
'''timestamps from suprnova seem to be 9 hours ahead'''

for pymnt in pymnt_lst:
pymnt['timestamp'] = datetime.strptime(pymnt['timestamp'], '%Y-%m-%d %H:%M:%S')
pymnt['date'] = pymnt['timestamp'] - timedelta(hours=9)

return pymnt_lst


def get_prices():
btc_dcrd = bttrx.get_price('btc', 'dcr')
usd_btc = bttrx.get_price('usdt', 'btc')
Expand Down Expand Up @@ -57,6 +68,7 @@ def get_paid():
def get_payments():
# NOTE: all possible tx types: ['Bonus', 'Credit', 'Credit_PPS', 'Debit_AP', 'Debit_MP', 'Fee', 'TXFee']
# NOTE: all keys in tx instance: ['amount', 'blockhash', 'coin_address', 'confirmations', 'height', 'id', 'timestamp', 'txid', 'type', 'username']
# NOTE: string format for tx['date']: '%Y-%m-%d %H:%M:%S' (currently seems to be 9 hours ahead)

pymnt_types = ['Bonus', 'Credit', 'Credit_PPS', 'Debit_AP', 'Debit_MP']
pymnts = []
Expand All @@ -66,4 +78,7 @@ def get_payments():

for i in range(len(txs)):
if txs[i]['type'] in pymnt_types:
pymnts.append(txs[i])
tx = {key: txs[i][key] for key in ['amount', 'timestamp', 'id']}
pymnts.append(tx)

return _convert_to_datetime(pymnts)

0 comments on commit 965a011

Please sign in to comment.