New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

ETHLondonUK: Build a trading bot you can use today – DeversiFi x StarkWare API, with Will Harborne

ETHGlobalFri, Oct 9, 2020, 12:00 AM

Transcript

I'm gonna give a quick 30-minute how to build a Dex trading bot but just to gauge has anyone ever built has anyone ever using the API of a centralized crypto currency exchange and how about trading on a dex using no not a UI ok so just quickly first of all to give an introduction of diversify so currently we're a decentralized exchange on maintenance areum settling every single transaction using 0x protocol so a user can place an order and once it gets matched with someone else it gets settled in an individual transaction and we're just now releasing for the first time at this hackathon sort of next level Dex which uses start is powered by stock where to do batches of transactions so rather than every single one having to go onto the blockchain users can place thousands of trades and have them settled in a single batch onto the blockchain which allows us to have much higher scalability much lower cost and this is the first time it's been tested so we don't think on the Watson test network anymore that we can break it but that doesn't mean that it's not going to get working by some of you if you try very hard at this hackathon so good luck with that so I'm just gonna go quick be through how it works overall what you can build with it during this next few days and then walk through like how you would set up on the exchange and how you can build a simple strategy on the decks and tomorrow for people who are interested there's gonna be diving into a lot more depth on the actual cryptography behind how with how these proofs are done by Michael who's from Stark where and later in the afternoon then more about the actual stark proof system which is basically how these are bashed together to validate on a smart contract on the blockchain that all the transactions that happened with valid so from the perspective of our UI it looks pretty much like any other centralized exchange and the big difference of how it now works is that when you come you deposit to a single smart contract and when you deposit to that pool of funds you also sign essentially a transaction which allows your funds to be swept off chain and all your trading then happens in that off chain environment so each time that you're placing an order you're signing it with a with a key which basically allows us to collect signatures and eventually generate this proof which settles on to the blockchain ever periodically so it means that from your from a trading perspective you have instant trade execution and placement but the settlement happens at a delayed period later and means that it's very sort of fast from from your perspective so so features wise it means that you get the benefit of no trade being able to make without being able to take place without you having signed specific permission for it your funds are fully controlled by you and your own wallet and there's a whole host of wallets that you can use and you don't have any risk from the exchange or from any counterpart if you're trading with unlike on a centralized exchange but you also get performance and high speed and you also get privacy on your transactions so unlike most decks is where you can be front run on the blockchain and your trades here are invisible to anyone else and it's only at the point of depositing and withdrawing that you your funds are associated with your address again on on the theorem so just very basically the way that that happens is that yeah these transactions are batch together and so the the cost essentially of each batch is it doesn't scale with the numbers from transactions so if you can put 10000 trades into one batch the cost is very very low per trade and therefore the fee can also be very low so there's a few prizes over the weekend for building using these api's on the Watson has test Network we're looking for anything innovative and that's using the complete function or as much functionality as possible of the exchange in particular dashboards helping to visualize the funds locked in the contract is particularly given that now the data is presented in a very different way so unlike most Dex aggregators and most dphi monitors increasingly apps like this they're going to be taking place with a lot of off chain data and so they need to be other ways of reading and displaying that data for dphi monitors and the other case we're really interested in is that there's there's some quite a bit of new cryptography involved here particularly because a new curve is being used for signing and hashing data which is more efficient for these stark proofs and so we interested then anyone who can have a look at that and start to help integrate new wallets to support trading on here one of the other really interesting ones is to is using it is combining this with flash loans so because of the way that the funds are held when they were on the exchange and deposited it's relatively simple in theory to write a flash loan wrapper around the deposit contract here to allow those funds to be used while they're also in use on the exchange so yeah just a couple more ideas along those lines all of these are would be interesting projects so integrating trade with leverage by the deposits mechanism into the change adding unsupported wallets the dashboard smart contract funds where because of the way that it works you can have quite quite easily a multi-sig wallet trading on the exchange which isn't isn't as simple and a lot of other defy protocols so now I'm gonna go into a bit more detail about how it works in practice for people who might want to use it so the first thing is around keys and authentication so particularly we've essentially split fund management and trading keys so you have two keys which if you chose two could be the same the first is your etherium key and that can be an externally owned account it can be a hardware wallet it can be a multi-sig contract actually rather than a key and that gives you the benefit of being able to have whatever security you want around your actual funds but your trading can be separate therefore just like any exchange centralized exchange API key you can use it in a automated trading bot on your machine without having to worry so much about the security because even if that was compromised no one can steal your funds they can just trade on your behalf which you can still be damaging but isn't catastrophic so this gives you a lot of flexibility and we already have native legend support which has just been released and so if someone wants to look at working on on that over the weekend come and speak to us because LEDs you have just published their their their library today and it also gives ya like a lot more efficiency around trading so I had planned here to kind of run through some examples if people had their laptops open but I think it's more relevant maybe the people who want you to go and do this but on our github we have this JavaScript client library which essentially implements all of the calls to our API and to the blockchain and wraps them in a really nice easy-to-use interface so for example you can open this examples folder if you if you go here and also look at the documentation and just by running node zero zero setup Jas you can essentially get a new private key set it up and then by running another command registers the exchange get some aetherium we had to do a bit of hacking around this where because of a lot of the faucets weight limit you via API we've implemented like a tour service which switches your IP address to hit the faucet so you can top it up and then instantly you have it have it all ready for trading it's quite neat and it's very easy to use and you can go all the way through doing all these examples deposit and get deposits get balanced and submit order and it all happens very fast although some of these include on chain if they're in cause of course but once you get to the submit order stage all of this is now I mean is happening happening via API but you're signing using your start key rather than your etherion private key to authenticate allow these proofs to be created forgetting market data there's also some examples that we've published but you essentially can also get WebSocket data which is a big advantage compared to a lot of Dex's where you're either reading on chain or you may be reading from a REST API what that means is that you can essentially subscribe to a WebSocket feed of price information which could be changing very quickly and react to that placing your orders and therefore create much more advanced and much more interesting trading strategies than you'd be able to do on most decentralized exchanges so if you're looking to build anything please come and speak to us about the websocket api which we can give any tips on using so in terms of writing a strategy we've published this repository which has like an example a very very simple sort of 300 line market-making strategy which I'm sure anyone here could exploit if they tried and essentially you're using two libraries one is our DVF client j/s library and then also we're using here the bit for next api node library which is a JavaScript library for handling the WebSocket data in a really nice way and then essentially this is this is all setup information but we connect with them with an inferior URL to the web stand blockchain create our what we have our aetherium and start private keys and then start to subscribe to the diversify order book feed and this essentially is just saying that if we get a new if the mid-price of the order book changes at any point we basically record what the new bid and ask is so the best price anyone's willing to buy and the best price that anyone is willing to sell and then update our in order to always be the best bid and so this will constantly try and make sure it's the best bid in the market and if it's if it finds it's not it'll update so that may not I mean that's even that's not particularly obviously is very simple but that's actually something is very hard to do on most or on any decks including a lot of the centralized 0x3 layers because you don't you can't get this fast price feed relay and you also can't cancel and replace your orders particularly the cancellation which usually with 0x requires a none chain and cool to the smart contract to invalidate your previously signed order so yeah encouraged anyone who wants to to go to that URL and and and and run it so I think because we went through those examples rather than everyone wanting them that that was relatively fast but if anyone wants to ask questions about the general way of the exchange works or how the start settlements work then please do we can use the focus so each time that their so basically there's a an update each time there's a new order change which will hit the socket yes so both I mean they're similar in the sense that in all cases including us the order book data and the orders are off chain so you're not limited in having to put every single order onto the blockchain but both of those are similar to the way that our current sort of production system operates in that when trades do occur they have to go into the blockchain individually which means that it's fine at relatively small numbers of transactions but you pay an aetherium transaction cost every time you want to settle one of those the big difference with this version that we've that we're just releasing is that instead of that you could have tens of thousands of transactions all happening in a very sports database of time and batch them together so that the cost is extremely low and you can have a much higher throughput than an either of those two systems or or our current production system yes so so rather than yeah having a record of every single transaction you're we're able to prove that at the end of this period this is the new state of balances and every transaction that was included although we haven't recorded them on to the blockchain was that was valid was about a transition so we've yeah netted them all together and created this proof that the new state is also valid so actually with the original implementation yes that was the case we've now abstracted also the way that deposits and withdrawals happen which also means that it's not clear who's balanced yeah essentially we've hidden that information as well but through a slightly convoluted method yeah so you also can't see the position updates over time which is also another form of leaking traders traders data yeah so essentially you can keep a record of course of all of your state but you have to essentially that are ourselves stock where and a series of other committee members store this data and make it public and make it publicly available in the case where we go offline and from that you can also see essentially you can always get your own position data in your own state but you need to have in the worst case everyone's state if we were off lying in order to withdraw [Music] you know relying on ya so essentially well you have this tree of everyone's balances and for example you could you could provide just and you know your balances but you have to be have to provide the tree of ever the path of everyone else's data but not the full set yeah any any other questions so this this version isn't yet on the main net aetherium but there's four different assets that are traded over this weekend on the on the stone test Network in theory unit because of there's there's not really any limitation imposed here so then our number of assets will be likely very high in the long run yeah the nice thing is that you have the ability to have multiple markets but also you can reduce the trade size for example which is usually quite high on most platforms like dy/dx for example because you're paying for a very you're paying the same amount there no matter how many no matter what the trade size is for settlement whereas here the settlement is just dependent on its time essentially so we want to have as many transaction as possible and it can be as small or as large as possible without really changing the economics of it okay thanks [Applause]

Automatic transcript — names and jargon may be misspelled.