-
Notifications
You must be signed in to change notification settings - Fork 13
/
nokyc.py
executable file
·137 lines (114 loc) · 4.24 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python3
# 2022 @j4imefoo
import argparse
import configparser
import itertools
import requests
import sys
import signal
import threading
import time
import json
from bisq import Bisq
from robosats import Robosats
from hodlhodl import HodlHodl
# 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")
supported_exchanges = ["bisq", "robosats", "hodlhodl", "all"]
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,
)
parser.add_argument(
"-e",
"--exchange",
help="Exchange: " + " ".join(supported_exchanges),
type=str,
default="all",
)
args = parser.parse_args()
fiat = args.fiat
direction = args.type
limit = args.deviation
exchange = args.exchange.lower()
if "," in exchange:
exchanges = exchange.replace(" ", "").split(",")
else:
exchanges = [exchange]
# check that exchanges are supported
for ex in exchanges:
if ex not in supported_exchanges:
raise Exception(f'Sorry, only the following exchanges are supported: '
+ " ".join(supported_exchanges))
return fiat, direction, limit, exchanges
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, exchanges = get_user_arguments()
session = get_tor_session()
price_exch = Bisq.getFiatPrice(fiat, session)
allOffers = []
if "all" in exchanges or "bisq" in exchanges:
allOffers = allOffers + Bisq.getOffers(fiat, direction, price_exch, session)
if "all" in exchanges or "robosats" in exchanges:
allOffers = allOffers + Robosats.getOffers(fiat, direction, session)
if "all" in exchanges or "hodlhodl" in exchanges:
allOffers = allOffers + HodlHodl.getOffers(fiat, direction, price_exch,
session)
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']}")