Skip to main content

Python SDK - Nibiru Chain

Python-based client for interacting with the Nibiru blockchain.

Nibiru Test workflow Examples tests PyPI Version MIT license

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.

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)

Source distribution for nibiru 0.21.12
File Size Uploaded
nibiru-0.21.12.tar.gz 394.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nibiru 0.21.12
File Interpreter ABI Platform
nibiru-0.21.12-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

0.21.12 This release

2 release files

0.21.9

2 release files

0.19.8

2 release files

0.19.7

2 release files

0.19.5

2 release files

0.19.4

2 release files

0.19.0

2 release files

0.17.0

2 release files

0.16.8

2 release files

0.16.7

2 release files

0.16.6

2 release files

0.16.5

2 release files

0.16.3

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.19

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page