Skip to content

Python-based client for interacting with the Nibiru blockchain

License

Notifications You must be signed in to change notification settings

NibiruChain/py-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

13e6238 · May 23, 2023
Mar 15, 2023
Feb 13, 2023
Feb 13, 2023
May 23, 2023
May 23, 2023
May 23, 2023
Dec 29, 2022
Jan 31, 2023
Jan 31, 2023
Aug 4, 2022
Feb 14, 2023
Jan 18, 2023
Aug 12, 2022
Apr 17, 2023
Dec 17, 2022
May 23, 2023
May 23, 2023
Aug 19, 2022

Repository files navigation

Python SDK - Nibiru Chain

Python-based client for interacting with the Nibiru blockchain.

Nibiru Test workflow Nibiru 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.

README Contents

Python SDK Tutorial

Installation from PyPI

pip install nibiru  # requires Python 3.7+

You may need to update pip to get this to run:

python -m pip install --upgrade pip

Usage

Ex: Creating a wallet and SDK client

from nibiru import wallet

# Save the mnemonic for later
mnemonic, private_key = wallet.PrivateKey.generate()

After, creating an account, you can create an Sdk instance.

import nibiru

network = nibiru.network.Network.testnet(2)
sdk = nibiru.Sdk.authorize(mnemonic)
  .with_network(network)

The Sdk class creates an interface to sign and send transactions or execute queries. It is associated with:

  • A transaction signer (wallet), which is configured from existing mnemonic to recover a PrivateKey.
  • A Network, which specifies the RPC, LCD, and gRPC endpoints for connecting to Nibiru Chain.
  • An optional TxConfig for changing gas parameters.

Ex: Using the faucet

import requests

requests.post(
    "https://faucet.testnet-2.nibiru.fi/",
    json={
        "address": sdk.address,
        "coins": ["10000000unibi", "100000000000unusd"],
    },
)

Ex: Querying chain state

# Querying the token balances of the account
sdk.query.get_bank_balances(sdk.address)

# Querying from the vpool module
query_resp = sdk.query.vpool.all_pools()
print(query_resp)
# Queries from other modules can be accessed from "sdk.query.module"

Ex: Submitting transactions

# version 0.16.3
from nibiru import Msg

tx_resp = sdk.tx.execute_msgs(
    Msg.perp.open_position(
        sender=sdk.address,
        pair="ubtc:unusd",
        is_long=True,
        quote_asset_amount=10,
        leverage=10,
        base_asset_amount_limit=0,
    )
)

You can broadcast any available transaction by passing its corresponding Msg to the sdk.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.