Take profit orders?

Is there anything in the works for take profit orders? Everything I’ve tried so far to keep track of my orders programmatically leads down the rate limit road.

1 Like

What are you doing to hit the rate limit? Most rate limit issues can be resolved with the use of the websocket feed. Have you done anything with that yet?

Trying to keep the system load down by checking orders hourly thru the rest architecture, which really bogs down when the amount of open orders gets past double digits. But watching the websocket feed for every order eats up my processor time on my ec2 instance which costs me money after a certain limit. Also tried mapping my order prices and selling that way but balance checks and order status checks also get cumbersome as the number of orders increase.

Are you storing the orders in a database? I was doing the same kind of thing when I started out and yeah, took forever once I had more than a few dozen orders if I wanted to stay below the rate limit.

I resolved it by calling the API to get all my open orders at once, then got all my open orders from the database. Compare the two arrays by order ID. If any are missing from the Coinbase array, then I know they have probably settled, and I can check them individually. Gives a much smaller list of orders to check individually, meaning you’re much less likely to hit the rate limit.

I’m surprised the websocket feed is eating up your processor time like that. If it’s not getting any messages, it really shouldn’t be doing much. Are you subscribing to a more busy channel like the ticker channel, or just the user channel? User channel should be pretty quiet unless trades are going through or being placed, in which case you would probably want to be doing something anyway.

I watch serveral tickers for specific indicator patterns to pop up together and use that as a buy signal. Which takes a fair amount of calculation each tick, i think the trade off is worth it as I’m generally impressed at the success rate and hold times so far. I’m wondering if this new stop limit system is capable of acting as a take profit order?

Ah, I think I misunderstood your second post. So you’re processing stuff constantly, not just once an hour because they don’t have the kind of order you actually want.

Any reason you’re not using a local machine? Or do you need the low latency of being in the same cloud as the Coinbase servers?

Originally it was the latency issue like you said. Now its more of a network reliability issue. I think I may have solved this however. I created a reciprocated set of indicators that trigger on the beginning of bearish markers to use as a sell point along with a db of order buy prices yet to be sold and their corresponding amounts to be sold as a single order instead of attemping to monitor individual orders. I’ve just updated the project and will let you know how that works in a few days. Thanks :blush:

1 Like

@jmicko thanks for your patience.

I’m stuck creating what the last api called a stop loss order and this new advanced trade calls a stop limit order, either way what I am trying to accomplish is to set a limit order that triggers when the current market price drops below a certain value.

Bug tracing the uncaught exemption the stack unravels like this:

public CoinbaseAPIResponse stopLossLimitOrder(String productID, String trigger, String value, String balance) { // STOP ENTRY LIMIT SELL ORDER
	
	return this.ACCOUNT.postRequest("/orders", String.join("", 
			"{\"client_order_id\":\"", UUID.randomUUID().toString(),
			"\",\"product_id\":\"", productID,
			"\",\"side\":\"SELL\",\"order_configuration\":{\"stop_limit_stop_limit_gtc\":{\"base_size\":\"", balance,
			"\",\"limit_price\":\"", value,
			"\",\"stop_price\":\"", trigger,
			"\",\"stop_direction\":\"STOP_DIRECTION_STOP_DOWN\",\"post_only\":\"false\"}}}"));
}



public CoinbaseAPIResponse postRequest(String endpoint, String requestBody) { // PERFORM REST POST REQUEST

	CoinbaseAPIResponse returnData = null;

	try {
		String[] response = this.commonREST("POST", coinbaseAdvExtendedURL + endpoint, "", requestBody);



private String[] commonREST(String method, String endpoint, String pathParams, String requestBody) throws InterruptedException {

	String[] response = new String[3];
	
	try {
		HttpsURLConnection connection = (HttpsURLConnection) new URL(
				String.join("", coinbaseProBaseURL, endpoint + pathParams)).openConnection();
		connection.setRequestMethod(method);
		connection.setRequestProperty("Content-Type", "application/json");
		connection.setRequestProperty("Accept", "application/json");

		if (this.coinbaseAPIKey != null) { // SECURITY CREDENTIALS PRESENT
			String timeStamp = Long.toString(Instant.now().getEpochSecond());
			connection.setRequestProperty("CB-ACCESS-KEY", coinbaseAPIKey);
			connection.setRequestProperty("CB-ACCESS-SIGN",
					signMessage(timeStamp, method, endpoint, requestBody));
			connection.setRequestProperty("CB-ACCESS-TIMESTAMP", timeStamp);
		}

		if (method.compareTo("PUT") == 0 || method.compareTo("POST") == 0) { // HANDLE BODY MESSAGE
			connection.setDoOutput(true);
			connection.getOutputStream().write(requestBody.getBytes());
		}
		response[0] = "";
		InputStreamReader responseReader = new InputStreamReader(connection.getInputStream(), "UTF-8");

At which point only a response code of 400 is evidence of any error with no further messages.

Any help here would be amazing!

From what I’ve seen, 400 is most often a problem with the order config. I’d be interested to see what the output of this section looks like:

String.join("", 
			"{\"client_order_id\":\"", UUID.randomUUID().toString(),
			"\",\"product_id\":\"", productID,
			"\",\"side\":\"SELL\",\"order_configuration\":{\"stop_limit_stop_limit_gtc\":{\"base_size\":\"", balance,
			"\",\"limit_price\":\"", value,
			"\",\"stop_price\":\"", trigger,
			"\",\"stop_direction\":\"STOP_DIRECTION_STOP_DOWN\",\"post_only\":\"false\"}}}"));

"post_only" isn’t listed as an option in the docs for a stop_limit_stop_limit_gtc order. Normally I think they would just ignore it, but it might be an option and is just missing from the docs. That might be your problem. It should be a JSON string, and JSON doesn’t put booleans in quotes, but you appear to have them here \"post_only\":\"false\". I believe Coinbase is using Go structs and it gets mad when you put in the wrong data type, even if it would be super easy to just convert it to the appropriate data type. That string should look something like this (but different order type) when you’re done joining everything together:

Beyond that, I mostly code in javascript, so I might not be much help here. That looks like Java, yeah?

1 Like

The output of the join function looks just like any json serializer just with less overhead. Turns out the issue was the post only variable, changing data types didnt help but removing the tag altogether worked like a charm. Funny because my limit down buy method doesn’t care either way. Oh well. Thanks a ton @jmicko top g status for you :clap:

1 Like

Ayyyyy no problem, glad to see you got it working!

1 Like