Jump to content

Building C# Bot to trade on XRP Ledger, questions about the exchange?


Recommended Posts

Hey folks,

I'm a C# dev and I want to build a trading bot to work on the XRP ledger.  I did some experimenting with the Node JS library (ripple-lib) and I'm able to fetch basic account details and send payments.  I just have a few questions - I'm fairly new to the specifics of how trading works on the ledger so please forgive my ignorance:

  1. Is anyone aware of a nuget for C#/.NET devs that is similar to the ripple-lib library from Node?  
  2. Can someone explain what I'm looking at when I see the ledger? I've attached a photo:  ledger.thumb.png.5ae7c525984170d1d21c3bc4bb616406.png

    Under order book, what is the Market Size?  What are all the different numbers under market size? What is the USD Spread?  What does Aggregation mean?
     
  3. Looking at the browser console I can see that when we look at the ledger, the data on this main page is coming from the public ripple API.  Why do we get a list of exchanges back? I thought the ledger IS the exchange?  api.thumb.png.b0d5738513ce647eadd6451a3333c1d1.png

    Each exchange has a  buyer , provider, seller and taker.  Who are these entities in the context of buying/selling XRP or other related tokens?

    That's all for now.  Looking forward to your feedback and thanks for any help!
Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

8 hours ago, devnej said:

Hey folks,

I'm a C# dev and I want to build a trading bot to work on the XRP ledger.  I did some experimenting with the Node JS library (ripple-lib) and I'm able to fetch basic account details and send payments.  I just have a few questions - I'm fairly new to the specifics of how trading works on the ledger so please forgive my ignorance:

  1. Is anyone aware of a nuget for C#/.NET devs that is similar to the ripple-lib library from Node?  
  2. Can someone explain what I'm looking at when I see the ledger? I've attached a photo:  ledger.thumb.png.5ae7c525984170d1d21c3bc4bb616406.png

    Under order book, what is the Market Size?  What are all the different numbers under market size? What is the USD Spread?  What does Aggregation mean?
     
  3. Looking at the browser console I can see that when we look at the ledger, the data on this main page is coming from the public ripple API.  Why do we get a list of exchanges back? I thought the ledger IS the exchange?  api.thumb.png.b0d5738513ce647eadd6451a3333c1d1.png

    Each exchange has a  buyer , provider, seller and taker.  Who are these entities in the context of buying/selling XRP or other related tokens?

    That's all for now.  Looking forward to your feedback and thanks for any help!

Here is my initial understanding. Hope someone can correct me if I'm too far off - 

To run a bot, you'll almost certainly require your own node to avoid usage limits on public servers

  1. I'm not aware of a c# nuget. You could consider using a standard C# jsonrpc library and connect to your own XRPL node. A WebSocket client would be needed, though, to handle streaming data. You could also consider running a Node/Java/Python client that interacts with the ledger and talk to that process over IPC.
  2. Look into how Order Books work and how orders are matched The USD spread is the bid-ask spread on the currency pair you are looking to trade (in this case is XRP/USD), for the amount you are looking to transact (0 per the screenshot). Subtract the last entry in red (0.6107) from the first entry in green (0.6101) and you get the spread for the Market Size at those prices. Here we have offers of up to 87.4 XRP at 0.6107 as sale offers/asks and up to offers of 232.24 XRP at 0.6101 as buy offers/bids. Looking at the book side by side, with the asks on one side and the bids on the other might serve as a better visualization.
  3. The ledger is just a ledger. A data store with a bunch of entries. Any account (including exchanges) are able to transact over that data store. Here, you are seeing the order book that's an aggregate of current bid/ask orders on the XRP/USD pair from accounts managed by issuing gateways / exchanges.

Hope this helps.

Link to comment
Share on other sites

I have exactly what you need. RippleLibSharp. But do you know how to publish the dll to nugget? I want to be able to import the nugget into another project.  

I committed some documentation so you can see what I'm talking about. 

creating an offer
https://jargoman.github.io/RippleLibSharp/offer.html

word list example
https://jargoman.github.io/RippleLibSharp/bip39.html

order book 
https://jargoman.github.io/RippleLibSharp/book_offers.html

source code
https://github.com/jargoman/RippleLibSharp
 

It's an exe because it can run independently for unit testing.  
https://github.com/jargoman/RippleLibSharp/raw/master/RippleLibSharp/bin/Debug/riplibsharp.exe

 

Link to comment
Share on other sites

@Ripley thanks for the response, very helpful.  I will look into how Order Books work to get a clearer understanding of what's going on here.  Do you really think I'd need to run my own node? What does that entail? And do you know if there are listed rate limits to the ledger? I couldn't seem to find any in the documentation - just that rate limiting is exists and is calculated somehow.

@jargoman this is awesome! I'm going to have a look now.  I do know how to publish to Nuget, yes - it just depends if you want to publish it to the public nuget feed or if you have a private nuget server somewhere.  The documentation is helpful as well.  This could be something that gets popular and in that case I would recommend maybe having a Blazor WASM for the docs?  I'm building Blazor Server/WASM apps at my day job now so I've got some chops if you need help.  Let's chat more, would love to contribute and lean on this for the bot creation.  Thanks man!

 

Link to comment
Share on other sites

1 hour ago, devnej said:

@Ripley thanks for the response, very helpful.  I will look into how Order Books work to get a clearer understanding of what's going on here.  Do you really think I'd need to run my own node? What does that entail? And do you know if there are listed rate limits to the ledger? I couldn't seem to find any in the documentation - just that rate limiting is exists and is calculated somehow.

A bot could be as simple as a script to place an order at a certain time of the day to as complex as generating signals based on historical and real time data, doing complex measurements, feeding into various data pipelines etc.

If it’s something like the latter, then you might need to run your own node. You probably don’t need it until you’re done building the bot though.

Also, running a node is no biggie. You don’t need to participate in the consensus and if you are only interested in real time data, you can keep the ledger count super low. 

Link to comment
Share on other sites

The order book is a list of offers. actually two opposing lists of offers

var bids = new Offer[];
var asks = new Offer[];

each offer is two currencies. taker gets and taker pays. 

class Offer {takerGets, takerPays} 

So if you were selling bitcoin your taker gets would be how much bitcoin you wanted to sell. And taker pays is the currency you want to accept. 



You don't need rippled installed to use the library. It's your choice. You can do ANY
1. install rippled and sign a tx through the rpc interface. 
2. install rippled and connect to websockets interface locally
3. don't install rippled and connect to any public validator. 

When connecting to a public server you wouldn't send the secret with the request you'd sign it locally. So the recommended way is tx.signWithRippleDotNet() which will sign it using a port of ripple's code ripple dot net.

RippleLibSharp is a wrapper around the websocket interface, a wrapper around ripple's signing code, a wrapper around bitcoins bip39 library. And code for making it object oriented. 

You have to unit test everything, because there's lots of leeway. The keys for example can be expressed a number of ways. 

string s = new RippleAddress(byte[]);
RippleAddress address = "rpERSCiR7BbREqhJwEGM5SM3oQZNa7LGSw";
The equals sign has been overridden.

It also supports polymorphism. 

RippleTransaction[] txs = {

new RipplePaymentTransaction(),
new RippleTrustSetTransaction(),
new RippleAccountSetTransaction()

}

foreach (tx in txs) {
tx.signWithRippleDotNet();
tx.submit();
}

Link to comment
Share on other sites

On 7/15/2021 at 8:03 AM, devnej said:

Why do we get a list of exchanges back? I thought the ledger IS the exchange?  

Each exchange has a  buyer , provider, seller and taker.  Who are these entities in the context of buying/selling XRP or other related tokens?

I think in this case the terminology is a bit bad. The exchanges in this case I THINK are historical trades, i.e. trades that happend already in that market. The "provider" is probably who placed the order. The "taker" is who has matched the order. Then the "buyer" and "seller" should be clear, but it's who actually bought and sold the currencies involved in the trade (in your case XRP and USD_bitstamp).

Link to comment
Share on other sites

On 7/15/2021 at 7:03 AM, devnej said:
  1. Is anyone aware of a nuget for C#/.NET devs that is similar to the ripple-lib library from Node?  

If you search nuget for ripple there are two XRP related libraries near the top.

First is https://www.nuget.org/packages/Ripple.NetCore/ which is a dotnet core fork of the C# code from Ripples official repo which never supported much apart from transaction signing.

Second is a library I've been working on and publish to NuGet https://www.nuget.org/packages/Ibasa.Ripple/ which is aiming to fully support the ripple JSON RPC and WebSocket APIs in a very type safe way with support for offline transaction signing. It's not 100% feature complete yet but pretty much all the core stuff is there.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.