Skip to main content

Open and close a position

A full trade with curl. Run it against a demo account. You'll want a second terminal with the account feed open, so you can see each step confirmed live.

1. Get a token​

With your API key (see Authentication):

curl -X POST "https://api.onlytradeplatform.com/auth/v1/oauth2/token?grant_type=client_credentials&remember_me=true" \
-H "Authorization: Basic $(printf "$OT_CLIENT_ID:$OT_CLIENT_SECRET" | base64)"

Save data.access_token:

TOKEN="3d4d16824096e9c0…"

2. Check the account​

curl https://api.onlytradeplatform.com/api/v1/accounts/me \
-H "Authorization: Bearer $TOKEN"

Check data.free_margin is enough, and data.trade_type is 1 (demo).

3. Look up the symbol​

curl "https://api.onlytradeplatform.com/api/v1/symbols/me/by_name?symbol=EURUSD" \
-H "Authorization: Bearer $TOKEN"

Note id (e.g. 26100001), digits (e.g. 5), stop_level, and the current last_bid / last_ask.

4. Place a market buy with SL/TP​

type: 0 is market, side: 0 is buy. order_price is required: use the current ask. For a buy, the stop goes below the bid and the target above it, each at least stop_level points away.

curl -X POST https://api.onlytradeplatform.com/api/v1/orders/accounts/me \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"symbol_id": 26100001,
"type": 0,
"side": 0,
"volume": 0.10,
"order_price": 1.08234,
"stop_loss": 1.08022,
"take_profit": 1.08622,
"comment": "recipe-1"
}'
{ "success": true, "code": 201, "data": "new market_order BUY 0.1 EURUSD @ 1.08234" }

That only means accepted. The fill arrives on the WebSocket as position_create. A rejection (for example, the SL is too close) arrives as bad_request with reason: "order_create".

5. Find the position​

curl https://api.onlytradeplatform.com/api/v1/positions/accounts/me \
-H "Authorization: Bearer $TOKEN"

Find the one with "comment": "recipe-1" and note its id (e.g. 260610016) and open_price — your actual fill.

6. Move the stop​

Send both SL and TP. Leaving one out removes it.

curl -X PUT https://api.onlytradeplatform.com/api/v1/positions/260610016/accounts/me \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{ "stop_loss": 1.08120, "take_profit": 1.08622, "comment": "recipe-1" }'

7. Close it​

volume is required. Send the full volume to close everything, or less for a partial close.

curl -X POST https://api.onlytradeplatform.com/api/v1/positions/260610016/accounts/me \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{ "volume": 0.10 }'

The feed shows position_close and a deal_create exit carrying the realized profit. It's also in your history:

curl "https://api.onlytradeplatform.com/api/v1/deals/accounts/me?limit=5" \
-H "Authorization: Bearer $TOKEN"
tip

Every step has a Try It panel in the API Reference — paste Bearer <token> into the auth box and send the request from your browser.