Python SDK for interacting with the XRPL decentralized exchange
Project description
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
- Add the SDK as a dependency to your project:
$ pip install xrpl_dex_sdk
- Import the SDK into your script:
import xrpl_dex_sdk
From Source
- 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 withblack
, linting withflake8
, type-checking withmypy
, and vscode testing configs.
- 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
Copyright © 2022 Ripple Labs, Inc.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file xrpl_dex_sdk-1.0.0.tar.gz
.
File metadata
- Download URL: xrpl_dex_sdk-1.0.0.tar.gz
- Upload date:
- Size: 52.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.1 CPython/3.8.13 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5714d08657b64ba7521dea2f63187ab0ef00660251f5013a1e58be330f910ae |
|
MD5 | b837beab01ae96a242d29596090b1030 |
|
BLAKE2b-256 | d8cde2622176e5252ce6eefb0a4ee4231906255d4909f2c47beb5fc8390e4f5f |
File details
Details for the file xrpl_dex_sdk-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: xrpl_dex_sdk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 94.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.1 CPython/3.8.13 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64121aa2735edb620a80aa428d52f2541c50b326f7462cd1fbe0be3854abe7cf |
|
MD5 | 9d8e3a5b9906765f6db355c7aa7041cb |
|
BLAKE2b-256 | b947b62eb60e7902f437fd62b0e89e0cf9efc1870a0d84ac572d0ab48fc8992b |