-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathliquidity-commitment-submit.py
More file actions
122 lines (103 loc) · 3.58 KB
/
liquidity-commitment-submit.py
File metadata and controls
122 lines (103 loc) · 3.58 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/python3
import json
import time
import requests
import helpers
# Vega wallet interaction helper, see login.py for detail
from login import token, pubkey
# Load Vega node API v2 URL, this is set using 'source vega-config'
# located in the root folder of the sample-api-scripts repository
data_node_url_rest = helpers.get_from_env("DATA_NODE_URL_REST")
# Load Vega wallet server URL, set in same way as above
wallet_server_url = helpers.get_from_env("WALLET_SERVER_URL")
# Load Vega market id
market_id = helpers.env_market_id()
assert market_id != ""
# Set to False to ONLY submit/amend a liquidity commitment (no cancellation)
CANCEL_LP_AFTER_SUBMISSION = True
# Set market id in ENV or uncomment the line below to override market id directly
market_id = "e503cadb437861037cddfd7263d25b69102098a97573db23f8e5fc320cea1ce9"
#####################################################################################
# S U B M I T L I Q U I D I T Y C O M M I T M E N T #
#####################################################################################
# Hint: commitmentAmount is an integer. For example 123456 is a price of 1.23456,
# for a market which is configured to have a precision of 5 decimal places.
# __create_liquidity_commitment:
# Compose your submit liquidity provision command
# Set your own user specific reference to find the commitment by reference and
# as a foreign key to your local client/trading application
liquidity_ref = f"{pubkey}-{helpers.generate_id(30)}"
submission = {
"liquidityProvisionSubmission": {
"marketId": market_id,
"commitmentAmount": "100",
"fee": "0.01",
"buys": [
{
"offset": "1",
"proportion": "1",
"reference": "PEGGED_REFERENCE_MID"
},
{
"offset": "2",
"proportion": "2",
"reference": "PEGGED_REFERENCE_MID"
}
],
"sells": [
{
"offset": "1",
"proportion": "1",
"reference": "PEGGED_REFERENCE_MID"
},
{
"offset": "2",
"proportion": "2",
"reference": "PEGGED_REFERENCE_MID"
},
{
"offset": "3",
"proportion": "5",
"reference": "PEGGED_REFERENCE_MID"
}
],
"reference": liquidity_ref
},
"pubKey": pubkey,
"propagate": True
}
# :create_liquidity_commitment__
print("Liquidity commitment submission:\n{}".format(
json.dumps(submission, indent=2, sort_keys=True)
))
# __sign_tx_liquidity_submit:
# Sign the transaction with an liquidity commitment command
# Hint: Setting propagate to true will also submit to a Vega node
url = "http://localhost:1789/api/v2/requests"
payload1 = {
"id": "1",
"jsonrpc": "2.0",
"method": "client.send_transaction",
"params": {
"publicKey": pubkey,
"sendingMode": "TYPE_SYNC",
"transaction": submission
}
}
payload = json.dumps(payload1)
headers = {
'Content-Type': 'application/json-rpc',
'Accept': 'application/json-rpc',
'Origin': 'application/json-rpc',
'Authorization': f'{token}'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
# :sign_tx_liquidity_submit__
print(json.dumps(response.json(), indent=4, sort_keys=True))
print()
print("Signed liquidity commitment and sent to Vega")
print()
# Wait for cancellation to be included in a block
print("Waiting for blockchain...")
time.sleep(3)