This repository has been archived by the owner on Mar 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
burn_fee.py
84 lines (70 loc) · 3.1 KB
/
burn_fee.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
import time
import threading
import functions.orders as dydx
import config as conf
from dydx3 import Client
from dydx3.constants import ORDER_SIDE_SELL
from dydx3.constants import ORDER_SIDE_BUY
def burn_fee(wallet_name: str, host: str, wallet_credentials: dict, parameters: dict):
# Create a wallet object
client = Client(
host=host,
api_key_credentials=wallet_credentials['API_CREDENTIALS'],
stark_private_key=wallet_credentials['STARK_PRIVATE_KEY'],
stark_public_key=wallet_credentials['STARK_PUBLIC_KEY'],
stark_public_key_y_coordinate=wallet_credentials['STARK_PUBLIC_KEY_Y_COORDINATE'],
default_ethereum_address=wallet_credentials['DEFAULT_ETHEREUM_ADDRESS'],
)
# Set up default parameters
current_number_of_placed_orders = 0
placed_order = ""
# Run the main loop
while current_number_of_placed_orders < parameters['ORDERS_LIMIT']:
if placed_order:
if placed_order.data['order']['side'] == ORDER_SIDE_SELL:
placed_order = dydx.create_market_order(client=client,
side=ORDER_SIDE_BUY,
size=parameters['POSITION_SIZE'])
elif placed_order.data['order']['side'] == ORDER_SIDE_BUY:
placed_order = dydx.create_market_order(client=client,
side=ORDER_SIDE_SELL,
size=parameters['POSITION_SIZE'])
else:
raise NameError('Invalid order. Program has been stopped.')
else:
placed_order = dydx.create_market_order(client=client,
side=ORDER_SIDE_SELL,
size=parameters['POSITION_SIZE'])
# Update counter
current_number_of_placed_orders += 1
# Print the details of placed order
t = time.localtime()
print('{}: order {} out of {} placed {} at {}'.format(
wallet_name,
current_number_of_placed_orders,
parameters['ORDERS_LIMIT'],
placed_order.data['order']['side'],
time.strftime("%H:%M:%S", t)),
)
# Just an additional pause for resilience
time.sleep(2)
# Wait until all orders filled and go to the next order
while dydx.get_number_of_opened_orders(client) != 0:
time.sleep(3)
print("{}: done!".format(
wallet_name,
))
def burn_fee_all():
# Threads array
threads = []
for wallet in conf.WALLETS:
if wallet['wallet_name'] in conf.SKIP_WALLETS:
continue
thread = threading.Thread(target=burn_fee, args=(wallet['wallet_name'],
conf.HOST,
wallet['data'],
conf.PARAMETERS))
thread.start()
threads.append(thread)
for thread in threads:
thread.join()