Skip to content

Instantly share code, notes, and snippets.

@thejollyrogers
Last active October 13, 2018 20:31
Show Gist options
  • Save thejollyrogers/56fabd8eaa5ebb06af36 to your computer and use it in GitHub Desktop.
Save thejollyrogers/56fabd8eaa5ebb06af36 to your computer and use it in GitHub Desktop.
Trading on the Stellar distributed exchange

Trading on the Stellar Distributed Exchange

Here we'll show how a simple trade works on the Stellar distributed exchange.

1: You submit an offer (using TransactionType "OfferCreate"), offering the currency you want to sell for another currency you want to buy. In this example, we'll put in an order that says "I'm selling 500 Stellar for 10 USD!" Now, you must specify the issuer (gateway) of USD you'd like to buy (a gateway you've already trusted).

$ curl -X POST https://test.stellar.org:9002  -d '
{
    "method": "submit",
    "params": [
        {
            "secret": "<YOUR_SECRET>",
            "tx_json": {
                "Account": "<YOUR_ACCOUNT>",
                "TakerGets": "600000000",
                "TakerPays": {
                    "currency": "USD",
                    "issuer": "<ISSUER_ACCOUNT>",
                    "value": 30
                },
                "TransactionType": "OfferCreate"
            }
        }
    ]
}'

2: Now, there are two ways that your order will get filled.

  1. when another user puts in an offer that matches your order, or
  2. when a user trys to send a transaction to someone that needs to be exchanged. In this case, the user wants to use his USD credits to send another user Stellar Credits. Since your offer is providing a path for that exchange to work, the user sending the USD will see your exchange rate.

Here's the RPC representations of the two senarios above:

User2 creates an offer that matches yours:

$ curl -X POST https://test.stellar.org:9002  -d '
    "method": "submit",
    "params": [
        {
            "secret": "<USER2_SECRET>",
            "tx_json": {
                "Account": "<USER2_ACCOUNT>",
                "TakerGets": {
                    "currency": "USD",
                    "issuer": "<GATEWAY_ACCOUNT>",
                    "value": 30
                },
                "TakerPays": "600000000",
                "TransactionType": "OfferCreate"
            }
        }
    ]
}'

OR User2 holds USD from your issuer and wants to send Stellars to another user.

$ curl -X POST https://test.stellar.org:9002  -d '
 {
    "method" : "submit",
    "params" : [ {
        "secret" : <USER2_SECRET>,
        "tx_json" : {
            "TransactionType":"Payment",
            "Account": <USER2_ACCOUNT>,
            "Destination": <USER2_DESTINATION_ADDRESS>,
            "Amount": "600"
        }
    }]
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment