poloniex.Poloniex.nonce = time.time() * 1000099990 polo = poloniex.Poloniex() polo.Key = poloKey polo.Secret = poloSecret #ticker = polo.returnTicker() walletBal = polo.returnCompleteBalances() currBTCPrice = requests.get( 'http://api.coindesk.com/v1/bpi/currentprice.json') ts = datetime.datetime.fromtimestamp( time.time()).strftime('%Y-%m-%d %H:%M:%S') price_json = currBTCPrice.json() btc_price = price_json['bpi']['USD']['rate_float'] balance = float(walletBal['BTC']['btcValue']) * btc_price coinBalance = ['poloniex' + accNum, 'income', balance, ts] coinBalance = [str(ele) for ele in coinBalance] return ','.join(coinBalance) poloKey1 = '<Key_Here>' poloSecret1 = '<Key_Here>' balWriter.balanceWriter('poloniex1', poloniexBalance(poloKey1, poloSecret1, '1')) poloKey2 = '<Key_Here>' poloSecret2 = '<Key_Here>' balWriter.balanceWriter('poloniex2', poloniexBalance(poloKey2, poloSecret2, '2'))
from coinbase.wallet.client import Client import datetime import time import balWriter def coinbaseBalance(cbKey, cbSecret): '''usage from coinbase.wallet.client import Client coinbaseBalance(KEY, SECRET) it returns balance in wallet currency as float''' api_key = cbKey api_secret = cbSecret client = Client(api_key, api_secret) accInfo = client.get_accounts() balance = accInfo['data'][0]['native_balance']['amount'] ts = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S') coinBalance = ['coinbase', 'income', float(balance), ts] coinBalance = [str(ele) for ele in coinBalance] return ','.join(coinBalance) cbKey = '<Key_Here>' cbSecret = '<Key_Here>' balWriter.balanceWriter('coinbase', coinbaseBalance(cbKey,cbSecret))
from lbcapi import api import datetime import time import balWriter def lbtcBalance(lbtcKey, lbtcSecret): '''usage: from lbcapi import api lbcBalance(key, secret) returns balance as float''' hmac_key = lbtcKey hmac_secret = lbtcSecret conn = api.hmac(hmac_key, hmac_secret) lbcBal = conn.call('GET', '/api/wallet-balance/').json() ts = datetime.datetime.fromtimestamp( time.time()).strftime('%Y-%m-%d %H:%M:%S') balance = lbcBal["data"]['total']['balance'] coinBalance = ['localbtc', 'income', float(balance), ts] coinBalance = [str(ele) for ele in coinBalance] return ','.join(coinBalance) hmac_key = '<Key_Here>' hmac_secret = '<Key_Here>' balWriter.balanceWriter('localbitcoin', lbtcBalance(hmac_key, hmac_secret))
def payPalBalance(user, pwd, signature): payload = { "USER": user, "PWD": pwd, "SIGNATURE": signature, "VERSION": "190", "METHOD": "GetBalance", "RETURNALLCURRENCIES": 1 } url = "https://api-3t.paypal.com/nvp" r = requests.post(url, data=payload) ts = datetime.datetime.fromtimestamp( time.time()).strftime('%Y-%m-%d %H:%M:%S') balance_str = r.text balance = balance_str[balance_str.index('AMT0=') + 5:balance_str.index('&')].replace('%2e', '.') #balance = balance_str balance = float(balance) accBalance = ['paypal', 'income', balance, ts] accBalance = [str(ele) for ele in accBalance] return ','.join(accBalance) payPalUser = '******' payPalPwd = '<Key_Here>' payPalSignature = '<Key_Here>' balWriter.balanceWriter('paypal', payPalBalance(payPalUser, payPalPwd, payPalSignature))
ticker_url = 'https://api.bitfinex.com/v1/pubticker/' wallet_balance = {} ts = datetime.datetime.fromtimestamp( time.time()).strftime('%Y-%m-%d %H:%M:%S') for coin in coin_list: if coin != 'USD': #last_price = float(requests.get(ticker_url+coin.lower()+'usd', data={}, headers=headers).json()['last_price']) last_price = float( requests.get(ticker_url + coin.lower() + 'usd', data={}, headers=headers).json()['bid']) wallet_balance[coin] = coin_list[coin] * last_price #print(coin, ':', last_price) else: wallet_balance[coin] = coin_list[coin] #print(coin, ':', 1) balance = sum(wallet_balance.values()) #print (sum(wallet_balance.values())) coinBalance = ['bitfinex', 'income', balance, ts] coinBalance = [str(ele) for ele in coinBalance] return ','.join(coinBalance) bitfinexKey = '<Key_Here>' bitfinexSecret = b'<Key_Here>' #the b is deliberate, encodes to bytes balWriter.balanceWriter('bitfinex', bitfinexBal(bitfinexKey, bitfinexSecret))