Skip to main content

Python SDK for interacting with Nibiru.

Project description

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.

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

nibiru-0.21.11.tar.gz (394.9 kB view hashes)

Uploaded Source

Built Distribution

nibiru-0.21.11-py3-none-any.whl (683.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page