What we’re building: Simple market maker strategy
We will be creating a simple market making strategy that attempts to profit off of the bid-ask spread:
Submits one limit buy order at or near the current ask rate.
Submits one limit sell order at or near the current bid rate.
When either order is filled a new order will be submitted at or near the new ask/bid rate.
If the ask/bid rate moves too far away from the existing open buy/sell order, the order(s) will be cancelled and re-submitted at or near the new ask/bid rate.
This exact strategy is available within Coygo Bots here: Simple market maker crypto trading bot strategy.
First we’ll create a new Strategy
We’ll name it “Simple market maker” since that’s what we’re building today.
Once the Strategy is created we can click the “Forge — Edit this Strategy” button to launch Coygo Forge.
Coygo Forge overview
We’ve landed in Coygo Forge, the tool that we’ll be using to code our custom crypto trading bot today.
On the right we’ll also see Example Strategies which has complete working code examples for reference and inspiration
Coding intro: Access a real-time order book
When we create a new Strategy we’re given a basic starter template code that creates two inputs on the “Configure” screen to select an exchange and a trade pair to use, then accesses a real-time order book for that trade pair.
See the two times that coygo.input(options) was called? Those are used to automatically generate a user interface to configure your bot on the “Configure” screen. Here is what that looks like:
Notice that the last line of code uses coygo.log(messages,…). This lets us log any information to the Activity Log so that we can see it when the Bot is running.
Coding intro: Run your new Bot
With that basic starter template code we can try to run our new Bot on the “Run” screen.
Once the Bot has started and is running we will see the “Activity Log” on the left side of the screen. See this line in our code?
coygo.log(‘This is the order book!’, orderBook);
Now we can see that message in the Activity Log!
This allows us to see what our Bot is doing and debug when issues might occur.
Coding Part 1: Inputs & persisted data
Now we can begin coding our market maker strategy that we described above. First we’ll set up all of the configuration inputs and persisted data that we’ll need. (Remember you can see all of this in the video above as well!)
Coding Part 2: Determining when to buy, sell, or cancel
With all of our inputs and data now set up we’re ready to determine what the Strategy should do. The Strategy may need to do one of a few things:
Submit a new buy or sell order if there is not currently one open
Cancel a buy or sell order if the current ask/bid rate has moved too far away from our open order’s rate
Wait for a cancelled order to finish being canceled
Coding Part 3: Submitting and canceling orders
Our Strategy has determined what to do next, now it’s time to actually submit or cancel orders when appropriate. We will calculate the order’s rate depending on the current ask/bid rate and we’ll make sure our order rate and amounts adhere to the exchanges rules for how many decimal places are allowed.
Run your new market maker Bot!
It’s time to try out our new Strategy! We can run the Bot using this Strategy on the “Run” screen. We’ll see it submit a buy and sell order as soon as the bot starts, and on the left side Activity Log we’ll see detailed information about what the Bot is doing.
Try Coygo for free today
Follow us on social media and subscribe to our blog to keep up to date with Coygo’s progress as we continue to develop the best tools for cryptocurrency and digital asset traders.