What is Nostr?
Ape Mithrandir
npub16ds…h6vy
2025-03-19 08:26:31
in reply to nevent1q…dfkm

Ape Mithrandir on Nostr: ```python import pandas as pd import numpy as np import datetime as dt import ...

```python
import pandas as pd
import numpy as np
import datetime as dt
import calendar as cal
from dateutil import relativedelta
import argparse
import warnings
warnings.filterwarnings('ignore')

def process_market(market):
if market.endswith('BTC'):
return market.split('/')[0]
elif market.startswith('BTC'):
return market.split('/')[1]
return market

def bisqstats(csv_str, f, t=0, pivot='Market', mkttype=None):
try:
df = pd.read_csv(csv_str)
start = dt.datetime.now() - relativedelta.relativedelta(months=f)
start_date = start.date().strftime("%Y-%m-%d")
start = cal.timegm(start.timetuple())*1000
end = dt.datetime.now() - relativedelta.relativedelta(months=t)
end_date = end.date().strftime("%Y-%m-%d")
end = cal.timegm(end.timetuple())*1000

df_filtered = df[(df["Epoch time in ms"] >= start) & (df["Epoch time in ms"] <= end)]
df_filtered['Type'] = df_filtered['Market'].apply(lambda x: 'fiat' if x.startswith('BTC') else ('altcoin' if x.endswith('BTC') else None))
df_filtered['Market'] = df_filtered['Market'].apply(process_market)

if mkttype is not None:
df_filtered = df_filtered[df_filtered['Type']==mkttype]

pv = df_filtered.pivot_table(index=[pivot], values=["Amount in BTC"], aggfunc=('sum', 'count'))
if pv.empty:
raise RuntimeError(f'Your dataframe has been filtered to empty. pivot={pivot}, mkttype={mkttype}')
else:
pv = pv.sort_values(by=[('Amount in BTC', 'sum')], ascending=False)
return pv, start_date, end_date
except Exception as e:
print('There was an error in your input, please try again :{0}'.format(e))
return None, None, None

def main():
#Create the parser
parser = argparse.ArgumentParser(description='Process some Inputs.')

# Add arguments
parser.add_argument('--f', type=int, required=True, help='Number of months to look back')
parser.add_argument('--t', type=int, help='Use this to look at historical periods')
parser.add_argument('--pivot', type=str, help='Set this to Payment method/Market/Type print out stats by Different Pivots')
parser.add_argument('--mkttype', type=str, help='Set this to fiat/altcoin to print out stats by market type')

# Parse the arguments
try:
args = parser.parse_args()
except SystemExit as e:
print("Error: Missing required arguments.")
parser.print_help()
return

t = 0
pivot = 'Market'
mkttype = None
if args.t is not None:
t = args.t
if args.pivot is not None:
pivot = args.pivot
if args.mkttype is not None:
mkttype = args.mkttype

pv, start_date, end_date = bisqstats("trade-statistics-all-markets.csv", args.f, t, pivot, mkttype)

print('\n==========================================================')
print(f"Bisq Trading Stats from {start_date} to {end_date}:")
print('==========================================================')
print(pv)
print('\n')

if __name__ == '__main__':
main()
```
Author Public Key
npub16dsu2ghu9yd363utyw7dejqc8rgx5ps7r4hxddrvx2x64dh73p7qqkh6vy