Skip to main content

XRPL Decentralized Exchange SDK

This Python SDK provides a CCXT-compatible API for interacting with the XRPL decentralized exchange.

A TypeScript version of this SDK is available here.

Installation

This package requires Python v3.8 (or newer) and the Pip package installer.

From PyPI

  1. Add the SDK as a dependency to your project:
$ pip install xrpl_dex_sdk
  1. Import the SDK into your script:
import xrpl_dex_sdk

From Source

  1. Make sure you have Poetry installed on your system.

NOTE: If you use VSCode, it should automatically show a prompt to select the virtual environment created by Poetry (./.venv). You will now have auto-formatting with black, linting with flake8, type-checking with mypy, and vscode testing configs.

  1. Clone the repo and install dependencies:
$ git clone https://github.com/AktaryTech/xrpl-dex-sdk-python.git
$ cd xrpl-dex-sdk-python
$ poetry install

Usage

To use the SDK, import it into your script and initialize it:

from xrpl_dex_sdk import SDK, SDKParams, constants

sdk = SDK(SDKParams.from_dict({
  "network": constants.TESTNET,
  "generate_wallet": True,
}))

Currencies, MarketSymbols, and ID Formatting

Currency codes, market symbols (aka pairs), and Order/Trade IDs are strings that follow the following formats:

Type Format Example
CurrencyCode [Currency]+[IssuerAddress] USD+rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq
MarketSymbol [BaseCurrency]/[QuoteCurrency] XRP/USD+rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq
OrderId, TradeId [AccountAddress]/[Sequence] rpkeJcxB2y5BeAFyycuWwdTTcR3og2a3SR:30419065

Examples

Placing an Order

The following example places an Order to buy 20 TST tokens, issued by the account at rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd, at a price of 1.5 XRP each:

from xrpl_dex_sdk import SDK, SDKParams, constants, models

sdk = SDK(SDKParams(
  network=constants.TESTNET,
  generate_wallet=True,
))

create_order_result = await sdk.create_order(
    symbol="TST+rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd/XRP",
    side=models.OrderSide.Buy,
    type=models.OrderType.Limit,
    amount=20,
    price=1.5,
)

order = await sdk.fetch_order(create_order_result.id)

print(order)

Outputs the newly created Order object:

{
  ...,
  "status": "open",
  "symbol": "TST+rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd/XRP",
  "type": "limit",
  "timeInForce": "GTC",
  "side": "buy",
  "amount": "20",
  "price": "1.5",
  "average": "0",
  "filled": "0",
  "remaining": "20",
  "cost": "0",
  "trades": [],
  "info": {
    // ... raw response from XRPL server
  }
}

Fetching an Order Book

The following example retrieves the latest order book for the market pair TST+rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd/XRP:

from xrpl_dex_sdk import SDK, SDKParams, constants, models

sdk = SDK(SDKParams(
  network=constants.TESTNET,
  generate_wallet=True,
))

order_book = await sdk.fetch_order_book(
    symbol="TST+rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd/XRP",
    limit=5
)

print(order_book)

Outputs an object like the following:

{
  "symbol": "TST+rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd/XRP",
  "bids": [
    ["0.0030627837459923", "93.030522464522"],
    ["0.00302447007930511", "1"]
  ],
  "asks": [["331.133829801611", "0.3"]],
  "info": {
    // ... raw response from XRPL server
  }
}

Methods

For full SDK documentation, load docs/_build/html/index.html in your browser. Run docs/build.sh to re-generate documentation.

Further Reading

CCXT (CryptoCurrency eXchange Trading Library)

XRPL Ledger

Contributing

Pull requests, issues and comments are welcome! Make sure to add tests for new features and bug fixes.

Contact

For questions, suggestions, etc, you can reach the maintainer at info@aktarytech.com.

License

The software is distributed under the MIT license. See LICENSE for details.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this library by you, as defined in the MIT license, shall be licensed as above, without any additional terms or conditions.

Disclaimer

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright © 2022 Ripple Labs, Inc.

Metadata

Release files for xrpl-dex-sdk 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xrpl-dex-sdk 1.0.0
File Size Uploaded
xrpl_dex_sdk-1.0.0.tar.gz 52.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xrpl-dex-sdk 1.0.0
File Interpreter ABI Platform
xrpl_dex_sdk-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 147.6 kB

Release files / xrpl_dex_sdk-1.0.0.tar.gz

Download URL xrpl_dex_sdk-1.0.0.tar.gz
Size 52.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d5714d08657b64ba7521dea2f63187ab0ef00660251f5013a1e58be330f910ae
BLAKE2b-256 checksum
How to use checksums
d8cde2622176e5252ce6eefb0a4ee4231906255d4909f2c47beb5fc8390e4f5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.1 CPython/3.8.13 Darwin/21.6.0

Release files / xrpl_dex_sdk-1.0.0-py3-none-any.whl

Download URL xrpl_dex_sdk-1.0.0-py3-none-any.whl
Size 94.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
64121aa2735edb620a80aa428d52f2541c50b326f7462cd1fbe0be3854abe7cf
BLAKE2b-256 checksum
How to use checksums
b947b62eb60e7902f437fd62b0e89e0cf9efc1870a0d84ac572d0ab48fc8992b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.1 CPython/3.8.13 Darwin/21.6.0

Release history Release notifications | RSS feed

This release

1.0.0 This release

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