-
Notifications
You must be signed in to change notification settings - Fork 5
/
feed.cny.py
51 lines (44 loc) · 1.82 KB
/
feed.cny.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
from grapheneapi.grapheneapi import GrapheneAPI
import json
import random
import math
if __name__ == '__main__':
rpc = GrapheneAPI("localhost", 8092)
asset_symbol = "CNY"
producers = ["fakeusd-feed-producer"]
price = random.normalvariate(134, 0.1)
price = math.fabs(price)
asset = rpc.get_asset(asset_symbol)
base = 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 = 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 = rpc.begin_builder_transaction()
op = [19, # id 19 corresponds to price feed update operation
{"asset_id": asset["id"],
"feed": price_feed,
"publisher": account["id"]
}]
rpc.add_operation_to_builder_transaction(handle, op)
rpc.set_fees_on_builder_transaction(handle, "1.3.0")
tx = rpc.sign_builder_transaction(handle, True)
print(json.dumps(tx, indent=4))