-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfeed.random.py
More file actions
78 lines (66 loc) · 2.66 KB
/
feed.random.py
File metadata and controls
78 lines (66 loc) · 2.66 KB
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
from grapheneapi import GrapheneClient
from grapheneexchange import GrapheneExchange
import json
import random
import math
class Config():
wallet_host = "localhost"
wallet_port = 8090
wallet_user = ""
wallet_password = ""
witness_url = "ws://localhost:11011"
witness_user = ""
witness_password = ""
watch_markets = ["PEG.RANDOM:TEST"]
market_separator = ":"
if __name__ == '__main__':
config = Config
graphene = GrapheneClient(config)
dex = GrapheneExchange(config)
asset_symbol = "PEG.RANDOM"
producers = ["init0", "init1", "init2", "init3", "init4", "init5", "init6", "init7", "init8", "init9", "init10"]
ticker = None
try:
ticker = dex.returnTicker()
except :
pass
if not ticker or config.watch_markets[0] not in ticker:
price = 100 * asset["precision"]
else :
price = ticker[config.watch_markets[0]]["settlement_price"]
price += random.normalvariate(1, 0.1)
price = math.fabs(price)
asset = graphene.rpc.get_asset(asset_symbol)
base = graphene.rpc.get_asset("1.3.0")
price = price * 10 ** asset["precision"] / 10 ** base["precision"]
denominator = 1e5
numerator = round(price*1e5)
for producer in producers:
account = graphene.rpc.get_account(producer)
price_feed = {"settlement_price": {
"quote": {"asset_id": "1.3.0",
"amount": denominator
},
"base": {"asset_id": asset["id"],
"amount": numerator
}
},
"maintenance_collateral_ratio" : 1200,
"maximum_short_squeeze_ratio" : 1100,
"core_exchange_rate": {
"quote": {"asset_id": "1.3.0",
"amount": int(denominator * 1.05)
},
"base": {"asset_id": asset["id"],
"amount": numerator
}}}
handle = graphene.rpc.begin_builder_transaction()
op = [19, # id 19 corresponds to price feed update operation
{"asset_id" : asset["id"],
"feed" : price_feed,
"publisher" : account["id"]
}]
graphene.rpc.add_operation_to_builder_transaction(handle, op)
graphene.rpc.set_fees_on_builder_transaction(handle, "1.3.0")
tx = graphene.rpc.sign_builder_transaction(handle, True)
print(json.dumps(tx, indent=4))