> For the complete documentation index, see [llms.txt](https://guide.ssi.com.vn/ssi-products/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guide.ssi.com.vn/ssi-products/fastconnect-trading/connection-guide.md).

# Connection guide

## Service endpoints

<table><thead><tr><th width="244">Service name</th><th>Endpoint</th></tr></thead><tbody><tr><td>FCTrading API</td><td>https://fc-tradeapi.ssi.com.vn</td></tr><tr><td>FCTrading Streaming</td><td>https://fc-tradehub.ssi.com.vn</td></tr></tbody></table>

## Credentials

After registration, you can create the API connection keys (refer [here](/ssi-products/service-registration.md)).&#x20;

* ConsumerID
* ConsumerSecrect
* PrivateKey: used to create Signature. [Refer here for more details.](/ssi-products/general-information.md) &#x20;

## Integration diagram

### Integration diagram

<figure><img src="/files/Nd5HGMFloME0KMkBR4yc" alt=""><figcaption><p>Integration diagram</p></figcaption></figure>

### **Access token request**

To secure your account activities, **authentication code** is required together with ConsumerID and ConsumerSecret when you request access token. Authentication code is dependent on the authentication method you registered:

* PIN: Input your PIN code.&#x20;
* SMS OTP: Use function GetOTP to get OTP code. OTP code will be sent to your registered mobile number.&#x20;
* Email OTP: Use function GetOTP to get OTP code. OTP code will be sent to your registered email address.&#x20;
* Smart OTP: Input OTP code from SSI SmartOTP app or iBoard app depending on which app you have activated the service.&#x20;

{% hint style="info" %}
We recommend you use SMS OTP or SmartOTP for security enhancement. PIN will soon be out of support.&#x20;
{% endhint %}

### **Access token usage**

* Regarding query functions, only access token is required for authentication before executing the request. &#x20;
* Regarding functions impacting to cash/securities (place/amend/cancel orders, internal transfer, right subscription, stock transfer, initial margin deposit/withdraw), you will need to sign the data by the Private Key provided. Refer [here](/ssi-products/general-information.md) for details of Signature.&#x20;

{% hint style="info" %}
Access token is valid within 8h. You cannot access our service with an expired token. Remember to renew access token before it expires to make sure the availability of your system.&#x20;

When requesting access token, you can choose to save the effective period of the authentication code.&#x20;

* If you choose to save, you will not need to enter authentication code when executing transactions related to cash/securities.&#x20;
* If you don't choose to save, you will need to enter authentication
  {% endhint %}

## Streaming connection

To use streaming update, you need to init the connection and bind to subcribe for different type of data.&#x20;

#### Init connection

```json
Initstream:
client.initStream({
    url: config.stream_url,
    consumer_id: config. ConsumerID,
    consumer_secret: config. ConsumerSecret,
    notify_id:   0

});

```

{% hint style="info" %}
**Notes:**&#x20;

notify\_id is the sequential order of the streaming messages. When init connection, you need to set value for notify\_id. &#x20;

* notify\_id = 0: the system will return all messages from the beginning of the day&#x20;
* notify\_id = -1: the system will return update messages after connected.
* &#x20;notify\_id = n: the system will return messages from n, with n equal to the sequence number of the last message received before disconnection + 1.&#x20;

During connected time, you should store this id, which will be used in case of disconnection.&#x20;

FastConnect system will reset notify\_id to 0 at 00:00 daily.&#x20;
{% endhint %}

#### Subscribe data changes

***Order update***

```json
//Bind a callback function to: event onNewOrder:
client.bind(client.events.onOrderUpdate, function (e,data) {
	    console.log(e + ": ");
	    console.log(JSON.stringify(data));
    
});

//Bind a callback function to event onOrderError::
client.bind(client.events.onOrderError, function (e, data) {
	   console.log(e + ": ");
	   console.log(JSON.stringify(data));

```

***Derivatives portfolio update***

```
client.bind(client.events.onClientPortfolioEvent,function(e,data){
Process data...
console.log(e + ": ");
console.log(JSON.stringify(data));
});
```

## Order placing process

<figure><img src="/files/MnuqZc11srbQ1kBAAOfF" alt=""><figcaption><p>Order placing and streaming update</p></figcaption></figure>
