Python sdk to interact with Rysk v12
Project description
Rysk V12 Python SDK
Python wrapper for ryskv12-cli
Setup
- Ensure Python 3.12+ is installed.
- Install the required dependencies:
poetry install - Download the
ryskV12CLI:./client/scripts/fetch_latest_release.sh
This automatically pulls the latest release ofryskV12 cli. If that is not the case please navigate to https://github.com/rysk-finance/ryskV12-cli/releases/latest and download the latest release in this directory asryskV12.
Run
Instantiation
from v12.rysk import Rysk, Env
private_key = "YOUR_PRIVATE_KEY"
env = Env.TESTNET
rysk_sdk = Rysk(env=env, private_key=private_key, v12_cli_path="./ryskV12") # Optional CLI path
Create a Connection
async def stream_reader(stream, callback):
if stream and callback:
while True:
line = await stream.readline()
if not line:
break
callback(line)
def response_handler(response: string):
print(f"Received response: {response.strip()}")
channel_id = "rfqs_listener"
uri = "/rfqs/0x..." # Example websocket endpoint (replace with actual asset address)
proc = rysk_sdk.execute_async(rysk_sdk.connect_args(channel_id, uri), response_handler)
asyncio.run(stream_reader(proc.stdout, response_handler))
Approve USDC Spending
chain_id = 84532
amount = "1000000"
rpc_url= "https://rpc..."
proc = rysk_sdk.execute(rysk_sdk.approve_args(chain_id, amount, rpc_url))
List USDC Balances
maker_channel = "maker-channel"
account = "0xabc"
proc = rysk_sdk.execute(rysk_sdk.balances_args(maker_channel, account))
Deposit / Withdraw
from models import Transfer
maker_channel = "maker-channel"
transfer_details = Transfer(
amout="500000",
asset="0x...", # The asset address
chain_id=84532,
is_deposit=True,
nonce="some-unique-nonce",
)
proc = rysk_sdk.execute(rysk_sdk.transfer_args(maker_channel, transfer_details))
List Positions
maker_channel = "maker-channel"
account = "0xabc"
proc = rysk_sdk.execute(rysk_sdk.positions_args(maker_channel, account))
Send a Quote
from models import Quote
maker_channel = "maker-channel"
request_id = "some-uuid-from-server"
quote_details = Quote(
assetAddress="0x...",
chainId=84532,
expiry=1678886400,
isPut=False,
isTakerBuy=True,
maker="0x...",
nonce="another-unique-nonce",
price="0.01",
quantity="1",
strike="1000000",
validUntil=1678886460,
)
proc = rysk_sdk.execute(rysk_sdk.quote_args(maker_channel, request_id, quote_details))
Example
import asyncio
import json
import time
from ryskV12.models import Quote, is_json_rpc_response, is_request
from ryskV12.client import Rysk, Env
private_key = ""
public_address = ""
asset = "0xb67bfa7b488df4f2efa874f4e59242e9130ae61f
async def process_rfqs():
rysk_sdk = Rysk(env=Env.TESTNET, private_key=private_key)
maker_chan = "maker__py"
rfq_chan = f'{asset}__py'
try:
asyncio.create_task(rysk_sdk.execute_async(rysk_sdk.connect_args(maker_chan, "maker")))
def process_rfq(payload: bytes):
# payload = str(payload)
print(payload)
if payload == b'\n':
return
try:
data = json.loads(payload)
if is_json_rpc_response(data):
request_id = data["id"]
result = data["result"]
if is_request(result):
quote = Quote(
result["asset"],
result["chainId"],
result["expiry"],
result["isPut"],
False,
public_address,
str(int(time.time() * 1000)),
"1000000000",
result["quantity"],
result["strike"],
int(time.time()) + 30,
)
proc = rysk_sdk.execute(rysk_sdk.quote_args(maker_chan, request_id, quote))
print(proc.stdout.readlines())
print(proc.stderr.readlines())
except Exception as e:
print("error")
print(e)
await rysk_sdk.execute_async(rysk_sdk.connect_args(rfq_chan, "rfqs/0xb67bfa7b488df4f2efa874f4e59242e9130ae61f"), process_rfq)
except Exception as e:
print(e)
if __name__ == "__main__":
asyncio.run(process_rfqs())
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ryskv12-1.0.1.tar.gz
(5.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ryskv12-1.0.1.tar.gz.
File metadata
- Download URL: ryskv12-1.0.1.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.9.6 Darwin/23.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f2256f5d56d00b409cae340d920ee0dcd2ab747799cff04fc5bc678884f57db
|
|
| MD5 |
fd5fbaa0c19a3cb03f4f05ad4889d238
|
|
| BLAKE2b-256 |
52085dce21b08d7af393c7a13f06ad8048b1234d5cf9ed32d13d31f64dec37e9
|
File details
Details for the file ryskv12-1.0.1-py3-none-any.whl.
File metadata
- Download URL: ryskv12-1.0.1-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.9.6 Darwin/23.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9301200b010add9e245507631f5f3802784121d3aba20f24a3b295e0112bb7ce
|
|
| MD5 |
a44a6e45a09bebde28aa4d435184ee6e
|
|
| BLAKE2b-256 |
a8d4ea6f5e9ab9212054dcb324bcb3aa41f34e32bae5fced06709d63f682dec6
|