Package: xrpl-dex-sdk
XRPL Decentralized Exchange SDKThis Python SDK provides aCCXT-compatible APIfor interacting with theXRPL decentralized exchange.A TypeScript version of this SDK is availablehere.InstallationThis package requiresPython v3.8(or newer) and thePippackage installer.From PyPIAdd the SDK as a dependency to your project:$ pip install xrpl_dex_sdkImport the SDK into your script:importxrpl_dex_sdkFrom SourceMake sure you havePoetryinstalled 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 installUsageTo use the SDK, import it into your script and initialize it:fromxrpl_dex_sdkimportSDK,SDKParams,constantssdk=SDK(SDKParams.from_dict({"network":constants.TESTNET,"generate_wallet":True,}))Currencies, MarketSymbols, and ID FormattingCurrency codes, market symbols (aka pairs), and Order/Trade IDs are strings that follow the following formats:TypeFormatExampleCurrencyCode[Currency]+[IssuerAddress]USD+rhub8VRN55s94qWKDv6jmDy1pUykJzF3wqMarketSymbol[BaseCurrency]/[QuoteCurrency]XRP/USD+rhub8VRN55s94qWKDv6jmDy1pUykJzF3wqOrderId, TradeId[AccountAddress]/[Sequence]rpkeJcxB2y5BeAFyycuWwdTTcR3og2a3SR:30419065ExamplesPlacing an OrderThe following example places an Order to buy 20 TST tokens, issued by the account atrP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd, at a price of 1.5 XRP each:fromxrpl_dex_sdkimportSDK,SDKParams,constants,modelssdk=SDK(SDKParams(network=constants.TESTNET,generate_wallet=True,))create_order_result=awaitsdk.create_order(symbol="TST+rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd/XRP",side=models.OrderSide.Buy,type=models.OrderType.Limit,amount=20,price=1.5,)order=awaitsdk.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 BookThe following example retrieves the latest order book for the market pairTST+rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd/XRP:fromxrpl_dex_sdkimportSDK,SDKParams,constants,modelssdk=SDK(SDKParams(network=constants.TESTNET,generate_wallet=True,))order_book=awaitsdk.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}}MethodsFor full SDK documentation, loaddocs/_build/html/index.htmlin your browser. Rundocs/build.shto re-generate documentation.Further ReadingCCXT (CryptoCurrency eXchange Trading Library)General DocumentationUnified APIXRPL LedgerGeneral DocumentationDecentralized ExchangedEX TutorialContributingPull requests, issues and comments are welcome! Make sure to add tests for new features and bug fixes.ContactFor questions, suggestions, etc, you can reach the maintainer atinfo@aktarytech.com.LicenseThe software is distributed under the MIT license. SeeLICENSEfor 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.DisclaimerTHE 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.CopyrightCopyright © 2022 Ripple Labs, Inc.