Welcome to the world of Algorithmic Trading

Welcome to the world of Algorithmic Trading

What is Algorithmic Trading? Algorithmic trading. It sounds so complicated, so sophisticated, yet comes in so many flavours. Contrary to what your intuition might tell you, it doesn't have to be rocket science. It can be, but it doesn't have to be. The simplest form of algorithmic trading is taking something you can already do manually and automating it. That might seem obvious to you, the experienced software developer, but it's such a common assumption for those starting in this space. They think there's a superpower that automatically comes with it. 6 monitors towering over you, sunglasses, standing desk, numbers flying off the screen. Make a bot, buy a bot, instant profit. That's not quite how it works. This isn't Hollywood (sorry). Algorithmic trading in the simplest form is automation. Everything you would do manually can be automated. Some things are easier than others, but there are no exceptions here. Some forms can be complex but they don't have to be. Where do I start? Naturally this is the next most common question I see in this space. I know how to code. I'm excited. I'm driven. I don't know what to build. I just know I want to doing what I saw on YouTube. Don't do that. Most of those posting get-rich-quick brags on YouTube don't know what they're doing. Start simple. Your first project does not need to be a fully fledged, fully automated, algorithmic trading machine. Often the best ideas happen while you're experimenting with the capabilities. I often recommend to start with partial automation, something that will already help you, improve you, support you, protect you. Partial automation This is where I would start. The basics. Doesn't sound exciting? Oh it is, and you'd be surprised how powerful this can be. How does it work? Simple: you control entries. See a potential opportunity you want to try? You place the entries, limit orders, or just buy something outright with a market order. Via your favourite exchange's website or app. Doesn't matter. Your automation can monitor your account automatically, 24/7, via API keys. As soon as it sees an entry fill (or position update), this is where it wakes up. Fetch necessary details to track position state, for example: Market type: spot, futures, etc. Position Symbol: BTCUSDT. Position Side: Long vs Short (futures only). Position Size: 0.001 BTC (always start small). Position Cost Average: 60000 USDT (this is the average price your position was built on). All of this is easily tracked via each exchange's REST APIs & WebSockets. What about authentication etc? That doesn't have to be complicated either, we'll talk about that too. With WebSockets, your system will know within milliseconds that something happened on your account. A fill happened on your account and it's time to wake your system up. Time to act. What do we do from here? Automatic Take Profit There are so many ways to automating this, from arbitrary math, to using indicators to react to market behaviour (e.g. volatility), but we'll keep it simple. The goal is to make your life as simple as tapping a button on your phone and letting the system handle the rest. Let's just say when any position is updated, we want to automatically exit any position at 1% profit. We'll also ignore fees to keep it simple. Your system already sees position updates as soon as they happen, powered by WebSockets, it already sees position details such as the current position size. You could also track any active (not yet filled) orders, but let's keep it as simple as possible. This is the workflow: Position update arrives. New position size is 0.001 BTC long on BTCUSDT at cost average of 60000 USDT. Calculate the exit price. Your goal is exit at 1% profit. Your position is long, so you need the price to increase to reach your target. The calculation is simple. Calculating Take Profit Exit Price 1% is 0.01 in decimal: 1% out of 100% = 1/100. Price needs to increase for profit, so: 1 + (1/100). = Multiply that by price: (1+(1/100)) x 60000 = 60600. Ignoring fees, we need to exit at 60600 to reach a 1% profit, given our position cost average of 60000. Hang on, we're devs, so put that calculator away: function getLongTPTarget(entryPrice, percentTarget) { const decimalTarget = 1 + (percentTarget / 100); const priceTarget = entryPrice * decimalTarget; return priceTarget; } const longPositionCostAverageEntryPrice = 60000; const profitTargetPercent = 1;// 1% // 60600 const targetExitPrice = getLongTPTarget( longPositionCostAverageEntryPrice, profitTargetPercent ); Enter fullscreen mode Exit fullscreen mode Now your system can easily find the target exit price, given the two simple parameters it already has: target profit in %, current position cost average entry price (at what price you acquired your BTC). Managing Orders Don't overthink it. Be the lazy dev you were made to be. You don't need to track orders, you don't need complex math, you don't need a complex order management system or state machine. The steps in the workflow so far: WebSocket: position update arrived, we know the (new) position cost average entry price, size and symbol. Your system: calculated the target price we want to exit. What we don't know: Do we have any active orders yet. Are we going to hit that price. We're keeping it simple, so the simplest way to stay in control: Cancel all orders for this symbol (you heard that right). Set the orders you expect to see. This way, when your trigger happens (position updated), you always have a clean slate with only the orders that you expect, and you don't need to worry about tracking order state. This makes your system really simple, and a simple system is a resilient one: Position update arrives. Cancel all orders. Set new orders where you expect them. For your automatic take profit, this is a Limit order. Pseudo code (we'll write real code later): const longPositionSize = 0.001; const sellOrderResult = await client.submitOrder({ category: 'linear', symbol: 'BTCUSDT', side: 'Sell', orderType: 'Limit', qty: `${longPositionSize}`, price: `${targetExitPrice}`, }); Enter fullscreen mode Exit fullscreen mode This example is inspired by the Siebly JavaScript SDK for Bybit, one of the leading cryptocurrency exchanges with a rich & reliable API. While the workflow here is minimal, it really can be that simple. With a capable SDK you don't have to worry about connectivity, managing WebSockets, building requests, handling authentication. Focus on the workflow you're looking to automate, let the SDK handle the connectivity for you. WebSockets can be used to easily trigger workflows in your system when a change happens (position updated), while the REST API can commonly be used to execute changes triggered by your workflow (cancel orders, place new orders, etc). This applies to every centralised cryptocurrency exchange's API offering. Why use a limit order? This type of order will wait in the order-book for a counter party to fill it. In other words, when the price moves up and crosses your order, it will automatically fill. It's passive, it's simple, and you don't have to worry if your system happens to be offline at that crucial moment. The exchange will track and fill your order for you when the time comes. That's it, if you've followed this far, you've seen one of the simplest ways to starting your journey in algorithmic trading. Automate how you exit your positions. Trade as you want, via your exchange's mobile app or website, or even your own automation. Let this workflow manage your exits. How are we? I'm Tiago, lead dev behind Siebly. Nice to e-meet you. My algorithmic systems have executed millions in notional volume across some of the top exchanges. Sounds big, but easier than you think in the algorithmic trading space. They run 24/7, often months on end, all powered by my own SDKs that I've shared with the world. I wanted to build out my own ideas. I wasn't happy with how hard it was to integrate exchange REST APIs & WebSockets. Instead of working on my systems, I lost so much time debugging connectivity issues, dead WebSockets, missed orders. It cost time. It also cost money (liquidations & missed opportunities). That wasn't good enough. The SDKs weren't good enough. So I made my own, how I expect them to be, and I shared them with the world on GitHub & NPM. This was almost a decade ago, time flies, and it quickly became clear I wasn't alone. At Siebly we now have 9 public SDKs for 9 cryptocurrency exchanges (so far), quickly approaching 4 million in lifetime downloads with daily users in the thousands! They're here to make APIs & WebSockets easy. Let them handle the plumbing, so you can focus on what's important to you: your system. But enough about me. Next steps What do you want to learn about next? Automating protective orders? Stop loss? Dollar cost averaging into a better position? Dynamic exit pricing? Share your thoughts, we're here for you.

Original Source

Read the full article at Dev →

KhanList aggregates and links to publicly available news content. We do not host full articles from third-party sources. Always verify important information with original sources.