Skip to main content
The Trading API places real orders, so a key alone isn’t enough. A trading key comes with a private key: TakeProfit keeps only the matching public key, and your code signs every request with the private one.

Create a trading key

1

Open token settings

Open takeprofit.com/settings/account, go to Login & Security and scroll to Personal API Tokens. Click Generate New Token.
2

Pick the trading scope

Name the token, for example grid-bot, and tick TRADING:ACCESS:WRITE. Trading scopes can’t be combined with other scopes, so keep a separate key for market data.
3

Set how long it lasts

Under Expires in, pick 7, 30 or 60 days. A trading key always expires, and the default is 30 days. The list shows the date next to the key.
4

Copy the token and the private key

Click Generate Token. Your browser creates the key pair, and the dialog shows the token, the public key and the private key only once. Copy the token and the private key, and save the private key as a file, for example trading-key.pem. TakeProfit never receives the private key, so a lost one can’t be recovered: create a new key.
Keep the private key out of your code and your repository, and use one key per script, so you can revoke one without stopping the others. To revoke a key, click Revoke next to it in Personal API Tokens. Open streams that use it end within 5 minutes.

Sign every request

Send four headers with every REST request and every WebSocket handshake: The signed message joins the three header values exactly as sent, then the payload. An omitted X-API-RECV-WINDOW adds nothing. The payload is:
  • POST: the raw request body, exactly as sent.
  • GET and WebSocket handshake: the raw query string as sent, without ?, or nothing when there is none.
Only the handshake is signed on a stream. Nothing is signed after it.
Sign the exact bytes you send. If your HTTP library re-serialises the body or re-encodes the query string after you signed it, the signature no longer matches: build the body or query yourself, sign it, and send that string.

Keep the clock in sync

A request is accepted while its timestamp is at most the receive window behind our server time and at most 1 second ahead of it. Sync your clock with NTP. There is no nonce: within the window, a captured request can be sent again. Keep the window short, and use Idempotency-Key when placing orders so a repeat never places a second one.

When a request is refused