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.
Metadata
Release files for nibiru 0.21.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nibiru-0.21.12.tar.gz | 394.7 kB | Without provenance | Details for nibiru-0.21.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nibiru-0.21.12-py3-none-any.whl | Python 3 | none | any | Details for nibiru-0.21.12-py3-none-any.whl |
Total release size: 1.1 MB
Release files / nibiru-0.21.12.tar.gz
| Download URL | nibiru-0.21.12.tar.gz |
|---|---|
| Size | 394.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6e221e1c2f4e793f8c80320a8817e44519855a5f26e2efe13f19ea667ee45fa2
|
|
BLAKE2b-256 checksum How to use checksums |
76c5d9cc38986965fecd142a815d200ee86e72ebaa83e8a42d1dba7beda977f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.8.16 Linux/6.2.0-1011-azure
|
Release files / nibiru-0.21.12-py3-none-any.whl
| Download URL | nibiru-0.21.12-py3-none-any.whl |
|---|---|
| Size | 683.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
23876691b80bdd6463a0abd709dc1a7eb054b7028cbc1ba12a657194ab630ef6
|
|
BLAKE2b-256 checksum How to use checksums |
2f99e32757cb6d9e3d120c28ee5b4f5b25aa9d01eda4e2944c4b80c11ae836cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.8.16 Linux/6.2.0-1011-azure
|
Security for nibiru 0.21.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.