-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfeed.last.py
74 lines (64 loc) · 2.61 KB
/
feed.last.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
from grapheneapi import GrapheneClient
from grapheneexchange import GrapheneExchange
import json
class Config():
wallet_host = "localhost"
wallet_port = 8090
wallet_user = ""
wallet_password = ""
witness_url = "ws://localhost:11011"
witness_user = ""
witness_password = ""
watch_markets = ["PEG.LAST:TEST"]
market_separator = ":"
if __name__ == '__main__':
config = Config
graphene = GrapheneClient(config)
dex = GrapheneExchange(config)
asset_symbol = "PEG.LAST"
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 = 1.0
else :
price = ticker[config.watch_markets[0]]["last"]
if price == -1:
price = 1.0
asset = graphene.rpc.get_asset(asset_symbol)
base = graphene.rpc.get_asset("1.3.0")
price = price * 10 ** asset["precision"] / 10 ** base["precision"]
denominator = base["precision"]
numerator = round(price*base["precision"])
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))