# FTX Functions

{% hint style="danger" %}
Due to recent events related to FTX.com - We have decided to stop the development and documentation of FTX capabilities. They will remain in the PENDAX SDK for documentation purposes only. **Please use all FTX functions and integrations with caution.  Current events may result in failure of FTX servers to respond.**
{% endhint %}

## Create an Exchange Object

Before you can interact with PENDAX functions, you must first create an Exchange object with which to use when using PENDAX. You can create one or multiple, and reference them together or individually throughout your code.

#### Example Exchange Object Creation:

<pre class="language-javascript"><code class="lang-javascript"><strong>import { createExchange } from "./exchanges/exchange.js";
</strong>
let myFtxAccount = createExchange({
  exchange: "ftx",
  authenticate: true,
  key: "myKeys",
  secret: "mySecret",
  subaccount: "mySubaccountName",
  label: "ftx",
});
</code></pre>

Once an Exchange object has been created you may use any of the available functions allowed by that exchange by referencing the name of the Exchange object you created.

#### Example using multiple Exchange Objects for executing PENDAX functions:

<pre class="language-javascript"><code class="lang-javascript">import { createExchange } from "./exchanges/exchange.js";

<strong>let myFtxAccount = createExchange({
</strong>  exchange: "ftx",
  authenticate: true,
  key: "myKeys",
  secret: "mySecret",
  subaccount: "mySubaccountName",
  label: "ftx",
});

let myOtherFtxAccount = createExchange({
  exchange: "ftx",
  authenticate: true,
  key: "myOtherKeys",
  secret: "myOtherSecret",
  subaccount: "myOtherSubaccountName",
  label: "ftx",
});

async function getAllSubaccounts() {
  try {
    const subaccounts = await myFtxAccount.getAllSubaccounts();
    const subaccounts2 = await myOtherFtxAccount.getAllSubaccounts();
    console.log(subaccounts);
    console.log(subaccounts2);
  } catch (error) {
    console.log(error.message);
  }
}
</code></pre>

{% hint style="info" %}
This code would create two separate FTX exchange objects, then query each account for a list of subaccounts attached to that FTX account.&#x20;
{% endhint %}

## Subaccounts

### Get All Subaccounts

```javascript
getAllSubaccounts()
```

{% hint style="info" %}

#### You must use api keys from a main account, you cannot use this passing a subaccount api keys

{% endhint %}

#### Example usage:

```javascript
async function getAllSubaccounts() {
  try {
    const accts = await myFtxAccount.getAllSubaccounts();
    console.log(accts);
  } catch (error) {
    console.log(error.message);
  }
}
```

### Create Subaccount

```javascript
createSubaccount(options)
```

{% hint style="info" %}
This function takes in an options object. Optional and required parameters are listed below.
{% endhint %}

#### Required Parameters:

```javascript
nickname: "mySubaccount"
```

#### Available Parameters:

```javascript
nickname: "mySubaccount"
```

#### Example Usage:

```javascript
async function createSubaccount() {
  myFtxAccount.createSubaccount({
    nickname: "myNewSubaccount",
  });
}
```

### Change Subaccount Name

```javascript
changeSubaccountName(options)
```

{% hint style="info" %}
This function takes in an options object. Optional and required parameters are listed below.
{% endhint %}

#### Required Parameters:

```javascript
 nickname: "mySubaccount"
 newNickname: "new name"
```

#### Available Parameters:

```javascript
 nickname: "mySubaccount"
 newNickname: "new name"
```

{% hint style="info" %}
`nickname` is the current subaccount name
{% endhint %}

#### Example Usage:

```javascript
async function changeSubaccountName() {
  myFtxAccount.changeSubaccountName({
    nickname: "currentName",
    newNickname: "newName",
  });
}
```

### Delete Subaccount

```javascript
deleteSubaccount(options)
```

{% hint style="info" %}
This function takes in an options object. Optional and required parameters are listed below.
{% endhint %}

#### Required Parameters:

```
nickname: "mySubaccount"
```

#### Available Parameters:

```
nickname: "mySubaccount"
```

#### Example Usage:

```javascript
async function deleteSubaccount() {
  myFtxAccount.deleteSubaccount({
    nickname: "myUnwantedSubaccount",
  });
}
```

### Get Subaccount Balances

```javascript
getSubaccountBalances(options)
```

{% hint style="info" %}
This function takes in an options object. Optional and required parameters are listed below.
{% endhint %}

#### Required Parameters:

```
nickname: "my subaccount"
```

#### Available Parameters:

```
nickname: "my subaccount"
```

#### Example Usage:

```javascript
async function getSubaccountBalances(options) {
  try {
    let result = await myFtxAccount.getSubaccountBalances(options);
    console.log(result.data.result);
  } catch (error) {
    console.log(error.message);
  }
}

getSubaccountBalances({
nickname: "my subaccount"
});
```

### Transfer Between Subaccounts

```javascript
transferBetweenSubaccounts(options)
```

{% hint style="info" %}
This function takes in an options object. Optional and required parameters are listed below.
{% endhint %}

#### Required Parameters:

```javascript
     "coin": "BTC",
     "size": 10,
     "source": null, 
     //null or "main" denotes the use of main account for source of funds. else supply the subaccount you want to transfer from
     "destination": "sub1"
```

#### Available Parameters:

```javascript
     "coin": "BTC",
     "size": 10,
     "source": null, 
     //null or "main" denotes the use of main account for source of funds. else supply the subaccount you want to transfer from
     "destination": "sub1"
```

#### Example Usage:

```javascript
async function transferBetweenSubaccounts(options) {
  try {
    let result = await myFtxAccount.transferBetweenSubaccounts(options);
    console.log(result.data.result);
  } catch (error) {
    console.log(error.message);
    console.log(error.response.data.error);
  }
}

transferBetweenSubaccounts({
     "coin": "BTC",
     "size": 10,
     "source": null, 
     "destination": "sub1"
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.compendium.finance/pendax/using-pendax-sdk/ftx-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
