API for developers Broker sign-in window

Broker sign-in window API

Broker login API: let your users sign in to their binary broker on your own site or app, in TPcopier's cloud browser, on a PC or a phone, by one link.

A binary account is signed in to its broker by its owner, in TPcopier's cloud browser. Ask for the account's link: it works in any browser or phone, with no TPcopier login, for 30 minutes - and TPcopier keeps only the login session it produces, encrypted, never the password.

curl -X POST -H "Authorization: Bearer $TPC_KEY" -H "Content-Type: application/json" https://tpcopier.com/api/v1/broker/accounts/A/connect-link
#   {"ok": true, "url": "https://tpcopier.com/connect/...", "expires_at": "...", "status": "/api/v1/broker/accounts/A/connect/status"}

curl -H "Authorization: Bearer $TPC_KEY" https://tpcopier.com/api/v1/broker/accounts/A/connect/status
#   until "done": "ok" true is connected, otherwise "message" says why (a new link tries again)

In your website - on a PC and on a phone

Your visitor logs in to their broker in TPcopier's cloud browser, on your own page, exactly as on tpcopier.com: a window over your page on a PC, the whole screen on a phone (touch and the phone's keyboard work). Add one script and call it with the link's url - the window closes by itself once the account is connected.

<script src="https://tpcopier.com/static/js/tpc-connect.js?v=a00fb5e101"></script>
<script>
// url: what POST /api/v1/broker/accounts/A/connect-link answered (make it on your server - never put your key in a page)
TPcopier.connect(url, {
  onDone: r => r.ok ? alert('Quotex connected') : alert(r.message),   // r: {account, stage, done, ok, message}
  onEvent: r => console.log(r.stage),                                // starting, waiting_for_login, connected ...
});
// or inside your page instead of over it - as tall as it needs:
// TPcopier.connect(url, { into: '#broker-login', onDone: r => ... });
</script>

Or place the link's page yourself (add ?embed=1 to leave out TPcopier's header) - it tells your page how tall it is and when the account is connected:

<iframe id="tpc" src="URL_FROM_CONNECT_LINK?embed=1" style="width:100%;height:760px;border:0"></iframe>
<script>
addEventListener('message', e => {
  if (e.origin !== 'https://tpcopier.com' || !e.data) return;
  if (e.data.type === 'tpcopier.size') document.getElementById('tpc').style.height = e.data.height + 'px';
  // {type:'tpcopier.connect', account, stage, done, ok, message} - stage: starting, waiting_for_login, connected ...
  if (e.data.type === 'tpcopier.connect' && e.data.done) alert(e.data.ok ? 'Connected' : e.data.message);
});
</script>

In your mobile or PC app

Open the link's url in your app's own web view - it is the same live window, with touch and the phone's keyboard. The page tells your app what happened through the app's bridge named TPcopierBridge (the message is {"type":"tpcopier.connect","account":A,"stage":"...","done":true,"ok":true,"message":"..."}):

// Android (Kotlin)
web.settings.javaScriptEnabled = true
web.settings.domStorageEnabled = true
web.addJavascriptInterface(object {
    @JavascriptInterface fun postMessage(json: String) { /* done? ok? - JSONObject(json) */ }
}, "TPcopierBridge")
web.loadUrl(url)

// iOS (Swift) - your class adopts WKScriptMessageHandler
let config = WKWebViewConfiguration()
config.userContentController.add(self, name: "TPcopierBridge")      // userContentController(_:didReceive:) gets it
let web = WKWebView(frame: view.bounds, configuration: config)
web.load(URLRequest(url: URL(string: url)!))

// React Native (react-native-webview)
<WebView source={{ uri: url }} onMessage={e => { const m = JSON.parse(e.nativeEvent.data); if (m.done) ... }} />

// Flutter (webview_flutter)
controller..setJavaScriptMode(JavaScriptMode.unrestricted)
  ..addJavaScriptChannel('TPcopierBridge', onMessageReceived: (m) { /* jsonDecode(m.message) */ })
  ..loadRequest(Uri.parse(url));

// Windows (WebView2): web.CoreWebView2.WebMessageReceived += (s, e) => { /* e.WebMessageAsJson */ };
// Electron: a preload with contextBridge.exposeInMainWorld('TPcopierBridge', { postMessage: json => ipcRenderer.send('tpcopier', json) })

Or open it in the phone's or the PC's own browser and get the user back to your app when it is done - give return_url: your app's own link (myapp://...), an https:// page, or for a PC app http://127.0.0.1:PORT/.... It is signed into the link, so it cannot be changed.

curl -X POST -H "Authorization: Bearer $TPC_KEY" -H "Content-Type: application/json" \
     -d '{"return_url":"myapp://tpcopier-done"}' https://tpcopier.com/api/v1/broker/accounts/A/connect-link
# when it is done the browser goes to  myapp://tpcopier-done?status=connected&account=A   (or status=failed)

Or draw the window yourself

With your key: start it with POST /api/v1/broker/accounts/A/connect ({"w": width, "h": height} of your screen), then pictures and input until /connect/status says done. These two never count against your key's requests a minute - a window is several pictures a second.

# the newest picture after the one you have: image/jpeg with X-Seq (its number) and X-Host (the site it shows);
# it waits up to 8 s for a new one, then 204 - ask again at once
curl -H "Authorization: Bearer $TPC_KEY" "https://tpcopier.com/api/v1/broker/accounts/A/connect/frame?after=SEQ" -o frame.jpg

# clicks, typing, scrolling - x and y are parts of the picture (0 to 1), up to 60 events a request
curl -X POST -H "Authorization: Bearer $TPC_KEY" -H "Content-Type: application/json" \
     -d '{"events":[{"t":"click","x":0.42,"y":0.31},{"t":"text","s":"me@example.com"},{"t":"key","k":"Tab"}]}' \
     https://tpcopier.com/api/v1/broker/accounts/A/connect/input
# events: click {x,y,n:2 for a double click} - text {s} - key {k: Enter, Tab, Backspace, Escape, ArrowLeft...}
#         wheel {x,y,fx,fy} - down / move / up {x,y} (a drag) - all {} (select all)

Further reading: the OpenAPI Specification our API description follows.

Endpoints in this guide

Base address https://tpcopier.com. Send your key with every request - Authorization: Bearer tpc_... - up to 120 requests a minute. Open an endpoint for its fields, its answers and an example.

liveTelegram sign-in and channels
POST/api/v1/broker/accounts/{aid}/connectConnect Account

Opens Chrome on the account's saved profile: a real window on a customer's own copy, and on TPcopier.com one shown inside their page (engine/remote.py). The user signs in themselves; we only capture the session. A second press while one is open joins it.

Parameters

aid *pathinteger

Request body

{
  "w": 0,
  "h": 0
}

Responses

200 Successful Response · 422 Validation Error · 401 402 403 429 - see Errors

Example

curl -X POST -H "Authorization: Bearer $TPC_KEY" -H "Content-Type: application/json" \
     -d '{"w": 0, "h": 0}' \
     "https://tpcopier.com/api/v1/broker/accounts/{aid}/connect"
GET/api/v1/broker/accounts/{aid}/connect/frameConnect Frame

The sign-in window's newest picture once it is newer than `after` (waits up to 8 s; 204 = none).

Parameters

aid *pathinteger
afterqueryinteger

Responses

200 Successful Response · 422 Validation Error · 401 402 403 429 - see Errors

Example

curl -H "Authorization: Bearer $TPC_KEY" \
     "https://tpcopier.com/api/v1/broker/accounts/{aid}/connect/frame"
POST/api/v1/broker/accounts/{aid}/connect/inputConnect Input

The customer's clicks and keys for their own sign-in window - passed on, never logged.

Parameters

aid *pathinteger

Request body

{
  "events": [
    {}
  ]
}

Responses

200 Successful Response · 422 Validation Error · 401 402 403 429 - see Errors

Example

curl -X POST -H "Authorization: Bearer $TPC_KEY" -H "Content-Type: application/json" \
     -d '{"events": [{}]}' \
     "https://tpcopier.com/api/v1/broker/accounts/{aid}/connect/input"
GET/api/v1/broker/accounts/{aid}/connect/statusConnect Status

Parameters

aid *pathinteger

Responses

200 Successful Response · 422 Validation Error · 401 402 403 429 - see Errors

Example

curl -H "Authorization: Bearer $TPC_KEY" \
     "https://tpcopier.com/api/v1/broker/accounts/{aid}/connect/status"
POST/api/v1/broker/accounts/{aid}/connect/cancelConnect Cancel

Parameters

aid *pathinteger

Responses

200 Successful Response · 422 Validation Error · 401 402 403 429 - see Errors

Example

curl -X POST -H "Authorization: Bearer $TPC_KEY" \
     "https://tpcopier.com/api/v1/broker/accounts/{aid}/connect/cancel"
POST/api/v1/broker/accounts/{aid}/connect-linkConnect Link

A link where this account is signed in to its broker in TPcopier's cloud browser - in your website (an iframe), your mobile or PC app (a WebView), or any browser, with no TPcopier login: the API's way to connect a binary account. It works for 30 minutes; GET /api/v1/broker/accounts/{aid}/connect/status says when it is connected, or why not. With return_url (your app's own link, https://..., or http://localhost for a PC app) the browser goes back there when it is done, with ?status=connected or ?status=failed and &account=ID.

Parameters

aid *pathinteger

Request body

{
  "return_url": ""
}

Responses

200 Successful Response · 422 Validation Error · 401 402 403 429 - see Errors

Example

curl -X POST -H "Authorization: Bearer $TPC_KEY" -H "Content-Type: application/json" \
     -d '{"return_url": ""}' \
     "https://tpcopier.com/api/v1/broker/accounts/{aid}/connect-link"