forked from j4imefoo/nokyc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnokyc.py
executable file
·113 lines (92 loc) · 3.43 KB
/
nokyc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python3
# 2022 @j4imefoo
import argparse
import configparser
import itertools
import signal
import sys
import threading
import time
import json
import requests
from bisq import Bisq
from hodlhodl import HodlHodl
from robosats import Robosats
# Import user configuration from nokycconfig.ini file
config = configparser.ConfigParser()
config.read('nokycconfig.ini')
def get_tor_session():
session = requests.session()
session.proxies = {'http': 'socks5h://127.0.0.1:' + config['DEFAULT']['TOR_PORT'],
'https': 'socks5h://127.0.0.1:' + config['DEFAULT']['TOR_PORT']}
return session
def sigint_handler(signal, frame):
print ('Cancelled.')
sys.exit(0)
# Define a simple "loading" animation while we gather offers
def animate():
for c in itertools.cycle(['|', '/', '-', '\\']):
if done:
break
sys.stdout.write('\rGathering offers... ' + c)
sys.stdout.flush()
time.sleep(0.1)
def get_user_arguments():
parser = argparse.ArgumentParser(description="A script that lists all current Bisq, HodlHodl and Robosats offers in the terminal")
parser.add_argument(
"-t",
"--type",
help="Type of orders (buy or sell)",
type=str,
choices=['buy', 'sell'],
default='sell',
)
parser.add_argument(
"-f",
"--fiat",
help="Fiat currency",
type=str,
choices = ['eur', 'usd', 'gbp', 'cad', 'aud', 'chf', 'brl', 'czk', 'sek', 'nzd', 'dkk', 'pln'],
default='eur',
)
parser.add_argument(
"-d",
"--deviation",
help="Max deviation from market price",
type=int,
default=8,
)
args = parser.parse_args()
fiat = args.fiat
direction = args.type
limit = args.deviation
return fiat, direction, limit
if __name__ == "__main__":
# Display a simple loading animation
# Put the animation in a thread so the rest of the function can proceed
done = False
t = threading.Thread(target=animate)
# Allow a user to exit out of the script and animation cleanly
t.daemon=True
t.start()
signal.signal(signal.SIGINT, sigint_handler)
fiat, direction, limit = get_user_arguments()
session = get_tor_session()
price_exch = Bisq.getFiatPrice(fiat, session)
bisqOffers = Bisq.getOffers(fiat, direction, price_exch, session)
robosatsOffers = Robosats.getOffers(fiat, direction, session)
hodlhodlOffers = HodlHodl.getOffers(fiat, direction, price_exch, session)
allOffers = bisqOffers + robosatsOffers + hodlhodlOffers
if (direction=='sell'):
allOffers.sort(key=lambda item: item.get('price'))
else:
allOffers.sort(key=lambda item: item.get('price'), reverse=True)
# Stop the loading animation
done = True
print('\r ', end = '')
print(f"\rPrice: {price_exch} {fiat.upper()}\n")
print(f"BTC {direction} offers:\n")
print(f"{'Exchange':8} {'Price':12} {'Dif':6} {'BTC min':8} {'BTC max':9} {'Min':6} {'Max':5} {'Method'}")
for offer in allOffers:
if ((direction=="sell" and offer['dif']<limit) or (direction=="buy" and offer['dif']>-limit)) and offer['method'].lower() not in config['DEFAULT']['avoid_methods']:
print(f"{offer['exchange']:8}{offer['price']:8n} {fiat.upper():4} {offer['dif']:4.1f}% {offer['min_btc']:8.4f} {offer['max_btc']:8.4f} {offer['min_amount']:7n} {offer['max_amount']:7n} {offer['method']}")