Coygo Adds OTO and OCO Orders for Crypto Trading Bots!

OTO & OCO advanced order types

In our latest release we've added support for OTO and OCO orders to Coygo Forge! You can now use these advanced order types in your own crypto trading bots.

When it comes to trading most people are familiar with the basic order types such as market orders, which have no guanarteed rate but will always execute, or limit orders, which have a guaranteed rate but may or may not execute. These simple tools give you a choice when developing your trading strategy.

As you expand your knowledge you will eventually encounter more advanced order types such as stop-limit orders, which trigger a limit order after a particular “stop” price is reached.

There are two advanced order types in particular that allow extremely powerful trading automation: OTO (One-Triggers-Other) and OCO (One-Cancels-Other). These two tools can be combined to do things that simply are not possible otherwise and are extremely helpful for mitigating risk in your strategy. For example, with a single order you could configure an entry price, stop-loss condition, and take-profit condition simultaneously.

What is an OTO (One-Triggers-Other) order?

An OTO order allows you to submit a “parent” order. When that “parent” order executes (fills completely) it can then automatically trigger submitting one or more other “child” orders. As a basic example, you could submit a “parent” limit order to buy an asset at a rate of 100 that will then submit an accompanying “child” limit order to sell that same asset at a rate of 110. This allows you to configure your entry and exit prices in a single order submission.

What is an OCO (One-Cancels-Other) order?

An OCO order allows you to submit a limit order and another “sibling” order at the same time. When one order executes (fills any amount) or is canceled the other “sibling” will be automatically canceled. For example, an OCO stop-market order can be used to mitigate risk by configuring simultaneous stop-loss and take-profit conditions.

Example: Configure entry, stop-loss and take-profit simultaneously

Let's walk through a real example of how we can use these powerful advanced order types to our advantage. We will use an OTO parent order and an OCO stop-market child order.

For this example:

We can achieve this by:

  1. Submitting an OTO buy order
    • This is a limit order that will buy BTC at 1% below the ask arte.
  2. Configuring a “child” order that is an OCO (One-Cancels-The-Other) stop market order at +1% with a stop at -1%.
    • The OCO order will generate a limit sell order at the buy rate + 1%.
    • The OCO order will also generate a stop-market sell order at the buy rate -1%, which triggers a market sell order as soon as the price drops <= the stop.
    • If either of these sell orders fills or is canceled the other is canceled.

Coygo ForgeCoygo Forge

Code example: Use OTO & OCO orders in a crypto trading bot w/Coygo!

Coygo Forge is our powerful crypto trading bot creation framework that allows you to use simple JavaScript code to create automated crypto trading bot strategies. Forge is the underlying engine powering Coygo Bots, our crypto trading bot platform built with a focus on security, speed, and ease of use. Coygo Bots can execute on intervals as short as minutes, seconds, or even milliseconds! All strategies available within Coygo Bots were built with Coygo Forge.

With Forge you can use OTO & OCO orders in your crypto trading bots!

If you wanted to replicate the example given above within Coygo Forge to configure an entry, stop-loss and take-profit simultaneously we could do so with the following JavaScript code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// we will set the buy rate to the 1% below the "ask" rate
const buyRate = orderBook.ask * 0.99;
// set the take-profit rate to 1% above the buy rate
const takeProfitRate = buyRate * 1.01;
// set teh stop-loss ratea to 1% below the buy rate
const stopLossRate = buyRate * 0.99;

const parentLimitBuyOrder = coygo.submitOrder({
	market: marketToUse,
	// The type of order to be submitted. Use coygo.orderTypes to specify the type.
	type: coygo.orderTypes.oneTriggersOtherLimitSimulated,
	// The side of the order to be submitted. Use coygo.orderSides to specify the side.
	side: coygo.orderSides.buy,
	// The order amount to be submitted.
	amount: 0.5,
	// The buy limit order's rate
	rate: buyRate,
	// configure orders(s) to be submitted when the parent order fills completely
	sendsOtherOrders: [
		{
			order: {
				market: marketToUse,
				// The type of order to be submitted. Use coygo.orderTypes to specify the type.
				type: coygo.orderTypes.oneCancelsOtherStopMarketSimulated,
				// The side of the order to be submitted. Use coygo.orderSides to specify the side.
				side: coygo.orderSides.sell,
				// The order amount to be submitted.
				amount: 0.5,
				// The sell limit order's rate
				rate: takeProfitRate,
				// The stop condition to trigger a market sell
				stop: stopLossRate
			},
			// this order may not be able to be submitted for a number of reasons,
			// for example if you don't have enough balance when it attempts to
			// submit. you can use this to determine how to handle that behavior
			ifCantSubmit: {
				stopBot: true, // defaults to true if not specified
				alert: true // defaults to true if not specified
			}
		}
	]
});
// the child orders are accessible on the parent order via the .oneTriggersOtherOrders array property
const childOcoOrder = parentLimitBuyOrder.oneTriggersOtherOrders[0];

Try Coygo Forge for free!

If you'd like to try coding your own crypto trading bot that uses OTO or OCO orders you can sign up for Coygo today! All subscription plans include a free trial. We'd love to hear your feedback!

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.

YouTube: https://www.youtube.com/@coygo

Facebook: https://www.facebook.com/CoygoHQ/

LinkedIn: https://www.linkedin.com/company/coygo

Twitter: https://twitter.com/CoygoHQ