Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pathlib import Path
- import os
- import json
- import pandas as pd
- from datetime import datetime
- BASEPATH = Path(__file__).parent
- exchange = 'binance'
- tradepair_state_paths = sorted(BASEPATH.glob(f'{exchange}-BTC-*-state.json'), key=os.path.getmtime, reverse=True)
- def state_file_reader(path_):
- with open(path_, 'r') as f:
- return json.loads(f.read())
- def parse_name_from_path(path_):
- return path_.name.split('-')[2]
- def parse_date_time(path_):
- mtime = path_.stat().st_mtime
- return datetime.utcfromtimestamp(mtime)
- state_file_data = []
- for jsonpath in tradepair_state_paths:
- data = state_file_reader(jsonpath)
- time = parse_date_time(jsonpath)
- name = parse_name_from_path(jsonpath)
- data['name'] = name
- data['time'] = time
- # filterout bad names here if then append else skip
- state_file_data.append(data)
- print('.', end='')
- print()
- balances = state_file_data[0]['balancesdata']
- positive_bal = [bal for bal in balances if balances[bal]['available'] > 0]
- state_df = pd.DataFrame(state_file_data)
- columns = ['name', 'Bid', 'Ask', 'quoteBalance', 'baseBalance', 'time']
- current_df = state_df[columns]
- current_df = current_df[current_df['name'].isin(positive_bal)]
- current_df['price'] = (current_df['Bid'] + current_df['Ask']) / 2
- current_df['btc_value'] = current_df['price'] * current_df['quoteBalance']
- current_df.columns = ['name', 'bid', 'ask', 'balance', 'btc', 'time', 'price', 'btc_value']
- estimated_value = current_df['btc_value'].sum() + current_df['btc'][0]
- print(estimated_value)
- print(current_df[current_df['btc_value'] > 0.0001]['name'])
Add Comment
Please, Sign In to add comment