forked from litepresence/Graphene-Metanode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunit_test_private.py
92 lines (82 loc) · 3.42 KB
/
unit_test_private.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
r"""
╔════════════════════════════════════════════════════╗
║ ╔═╗╦═╗╔═╗╔═╗╦ ╦╔═╗╔╗╔╔═╗ ╔╦╗╔═╗╔╦╗╔═╗╔╗╔╔═╗╔╦╗╔═╗ ║
║ ║ ╦╠╦╝╠═╣╠═╝╠═╣║╣ ║║║║╣ ║║║║╣ ║ ╠═╣║║║║ ║ ║║║╣ ║
║ ╚═╝╩╚═╩ ╩╩ ╩ ╩╚═╝╝╚╝╚═╝ ╩ ╩╚═╝ ╩ ╩ ╩╝╚╝╚═╝═╩╝╚═╝ ║
╚════════════════════════════════════════════════════╝
~
UNIT TEST AUTHENTICATED OPS
"""
# STANDARD MODULES
import json
import traceback
from getpass import getpass
# GRAPHENE MODULES
from graphene_auth import GrapheneAuth
from graphene_constants import GrapheneConstants
from graphene_metanode_server import GrapheneTrustlessClient
from graphene_utils import it, jprint
def sample_orders(auth, constants, pair, active):
"""
sample orders of in-script demo
"""
order = json.loads(auth.prototype_order(pair))
order["header"]["wif"] = active
order1, order2, order3, order4 = dict(order), dict(order), dict(order), dict(order)
# login
order1["edicts"] = [{"op": "login"}]
# cancel all
order2["edicts"] = [{"op": "cancel", "ids": ["1.7.X"]}]
# place two limit orders
order3["edicts"] = [
{"op": "buy", "amount": 10, "price": 0.2, "expiration": 0,},
{"op": "sell", "amount": 10, "price": 0.7, "expiration": 0,},
]
# query open orders from the metanode and cancel 2 of them
metanode = GrapheneTrustlessClient(constants)
metanode_pairs = metanode.pairs
orders = [order["order_number"] for order in metanode_pairs[pair]["opens"]][:2:]
order4["edicts"] = [{"op": "cancel", "ids": orders}]
return order1, order2, order3, order4
def unit_test():
constants = GrapheneConstants()
dispatch = {str(idx): chain for idx, chain in enumerate(constants.core.CHAINS)}
for key, value in dispatch.items():
if "testnet" not in value:
print(key + ": " + it("blue", value))
else:
print(key + ": " + it("purple", value))
chain = dispatch[input("Enter choice: ")]
constants = GrapheneConstants(chain)
print("\033c")
dispatch = {str(idx): pair for idx, pair in enumerate(constants.chain.PAIRS)}
for key, value in dispatch.items():
print(key + ": " + value)
pair = dispatch[input("Enter choice: ")]
print("\033c")
print("WARNING: this script will buy/sell whatever amount is hard coded inline")
input("press Enter to continue, Ctrl+c to cancel")
active = getpass("Enter WIF: ")
print("\033c")
auth = GrapheneAuth(constants, active)
order1, order2, order3, order4 = sample_orders(auth, constants, pair, active)
dispatch = {
"1": order1,
"2": order2,
"3": order3,
"4": order4,
}
choices = {
"1": "authenticate",
"2": "cancel all",
"3": "buy and sell",
"4": "cancel some",
}
print(it("yellow", " UNIT TEST\n"))
for key, val in choices.items():
print(it("green", key), ":", it("cyan", val))
choice = input("\n\n")
auth.broker(dispatch[choice])
if __name__ == "__main__":
print("\033c")
unit_test()