-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathliquidity-commitment-cancel.py
78 lines (62 loc) · 2.29 KB
/
liquidity-commitment-cancel.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
#!/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 market id in ENV or uncomment the line below to override market id directly
market_id = "e503cadb437861037cddfd7263d25b69102098a97573db23f8e5fc320cea1ce9"
#####################################################################################
# C A N C E L L I Q U I D I T Y C O M M I T M E N T #
#####################################################################################
# __cancel_liquidity_commitment:
# Compose a liquidity commitment cancellation command
# Hint: The transaction may get rejected if removing previously supplied liquidity
# will result in insufficient liquidity for the market to operate
submission = {
"liquidityProvisionCancellation": {
"marketId": market_id,
},
"pubKey": pubkey,
"propagate": True
}
# :cancel_liquidity_commitment__
print("Liquidity commitment cancellation:\n{}".format(
json.dumps(submission, indent=2, sort_keys=True)
))
# __sign_tx_liquidity_cancel:
# Sign the transaction with an order submission command
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_cancel__
print("Signed liquidity commitment cancellation and sent to Vega")
# Wait for cancellation to be included in a block
print("Waiting for blockchain...")
time.sleep(3)