Python SDK for interacting with Nibiru.
Project description
Python SDK - Nibiru Chain
Python-based client for interacting with the Nibiru blockchain.
The nibiru
package allows you to index, query, and send transactions on Nibiru Chain using Python. It provides access to market data for analysis, visualization, indicator development, algorithmic trading, strategy backtesting, bot programming, and related software engineering.
The package is intended to be used by coders, developers, technically-skilled traders and data-scientists for building trading algorithms.
Try running nibiru sdk online
Open the google collab link below to try running Niburu code online:
Or go to the examples folder to see the codes and run Jupyter notebooks locally.
Installation
pip install nibiru # requires Python 3.8+
Usage
Querying the chain
import json
from nibiru import Network, ChainClient
client = ChainClient(Network.testnet(2))
# Query perp markets
print(json.dumps(client.query.perp.markets(), indent=4))
# Query trader's positions
print(
json.dumps(
client.query.perp.all_positions(
trader="nibi1jle8khj3aennq24zx6g93aam9rt0fqhgyp4h52"
),
indent=4)
)
Submitting transactions to the chain
To send a tx you need to authenticate using your wallet mnemonic or private key.
To create a new wallet, generate a mnemonic key using any service or using SDK call.
import json
import nibiru
from nibiru import Network, ChainClient, Msg, PrivateKey
mnemonic, private_key = PrivateKey.generate()
print(mnemonic)
# Example OUTPUT:
# enlist satisfy inspire hobby romance caught great neither kitchen unfair cage awesome update fade object eagle sun ordinary again journey spell gown tiger spin
# Your wallet address
print(private_key.to_public_key().to_address().to_acc_bech32())
# Example OUTPUT:
# nibi1efsh4dq3ve58dgu68rxp8cfe4mgf89el0qfucm
Store your mnemonic key in a safe place and use it going forward.
Use faucet to get some test tokens into your wallet: https://app.nibiru.fi/faucet
Сreate your chain client and authenticate with the mnemoniс generated
mnemonic = "put your mnemonic here..."
client = ChainClient(network=Network.testnet(2))
client.authenticate(mnemonic=mnemonic)
print(client.address)
Check your bank balances. If the faucet succeded - your wallet should not be empty.
print(client.query.get_bank_balances(client.address))
Send tx
output = client.tx.execute_msgs(
Msg.perp.open_position(
pair=pair,
is_long=True,
margin=10,
leverage=2,
)
)
print(output)
You can broadcast any available transaction by passing its corresponding Msg
to the client.tx.execute_msgs
function.
Documentation Website
Documentation can be found here: Nibiru-py documentation
- Learn more about opening and managing your spot and perp positions here
- Learn about querying the chain using the Sdk here
Contributing
Please read HACKING.MD for developer environment setup.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file nibiru-0.21.12.tar.gz
.
File metadata
- Download URL: nibiru-0.21.12.tar.gz
- Upload date:
- Size: 394.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.8.16 Linux/6.2.0-1011-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e221e1c2f4e793f8c80320a8817e44519855a5f26e2efe13f19ea667ee45fa2 |
|
MD5 | 3e0e0040e271a4d6f9efccf6007ef236 |
|
BLAKE2b-256 | 76c5d9cc38986965fecd142a815d200ee86e72ebaa83e8a42d1dba7beda977f8 |
File details
Details for the file nibiru-0.21.12-py3-none-any.whl
.
File metadata
- Download URL: nibiru-0.21.12-py3-none-any.whl
- Upload date:
- Size: 683.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.8.16 Linux/6.2.0-1011-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23876691b80bdd6463a0abd709dc1a7eb054b7028cbc1ba12a657194ab630ef6 |
|
MD5 | f450fb489286cd2dbc41bd1f9bfd111c |
|
BLAKE2b-256 | 2f99e32757cb6d9e3d120c28ee5b4f5b25aa9d01eda4e2944c4b80c11ae836cf |