ftx-api-rest-extended
Version:
An extended wrapper of the FTX API package
132 lines (111 loc) • 3.66 kB
Markdown
An extended version of the [ftx-api-rest](https://github.com/askmike/ftx-api-rest) package made by [askmike](https://github.com/askmike/ftx-api-rest), I decided to write specific functions focused on spot / future trading ✨.
1. [Example](
1. [Overview](
1. [getBalance](
1. [createOTCOrder](
1. [fundingRate](
1. [calculateOrderSize](
1. [createOrder](
1. [getOpenPositions](
1. [getLimitOrders](
1. [closeOrders](
1. [closeLimitOrders](
```bash
npm install ftx-api-rest-extended
```
You can use the code snippet below as a reference, go to [Overview](
```js
const FTX = require('ftx-api-rest-extended');
// request the API credentials on your FTX account
const CREDS = {
'key': '',
'secret': '',
'subaccount': ''
}
const FTX_INSTANCE = new FTX(CREDS);
async function test() {
// get the price of the ETH-PERP future contract
const { price } = await FTX_INSTANCE.getPrice('eth-perp');
console.log(`[i] Exchange rate: ${price}`);
// sample of a limit buy order on the ETH-PERP future contract
await FTX_INSTANCE.marketOrder('0.005', 'eth-perp', 'buy', 'limit', 3000);
// close all limit orders
const closeLimitOrders = await FTX_INSTANCE.closeLimitOrders();
console.log(closeLimitOrders);
}
test();
```
A breakdown of all the functions within the module
Get balance of the subaccount
```
getBalance()
```
Get the price of an future or spot asset
```js
// _pair: Any asset on the ftx exchange such as BTC-PERP or BTC/USD
getPrice(_pair)
```
OTC (Over the counter) Convert X to Y
```js
// _from: Asset you want to convert
// _to: Asset you want to convert to
// _size: How much you want to convert
createOTCOrder(_from, _to, _size)
```
Get the funding rate of a future contract
```js
// _pair: Any asset on the ftx exchange such as BTC-PERP or BTC/USD
fundingRate(_pair)
```
This will calculate the order size based on the portfolio balance
```js
// _sizeInPercentage: how big the order has to be in percentage
// _pair: ETH-PERP or BTC-PERP
calculateOrderSize(_sizeInPercentage, _pair)
```
Place your market or limit order, you can use the `calculateOrderSize(_sizeInPercentage, _pair)` function to calculate the unit amount
```js
// _size: size of the order
// _pair: the future contract name
// _side: buy or sell
// _type: market (default) or limit order
// _price: specify if it's a limit order
createOrder(_size, _pair, _side, _type = 'market', _price = null)
```
Get all open positions
```js
getOpenPositions()
```
### getLimitOrders
Get all open limit orders
```js
getLimitOrders()
```
### closeOrders
Close all orders or of a specific pair
```js
// _pair: close the orders of the specified asset
closeOrders(_pair = '')
```
### closeLimitOrders
Close all limit orders or of a specific pair
```js
// _pair: close the orders of the specified asset
closeLimitOrders(_pair = '')
```
## Reference
- [FTX API Docs](https://docs.ftx.com/?javascript#rest-api)
## Wanna buy me a coffee? ☕
ETH: mitchel.eth or 0x5584A353528dfeB2Fc751Ab48b72D32726C79507
BTC: bc1qqfnfkrnhv903v9v38n98vvk35hgrp77ay7kwqr or 1DhGZ1kvEF1wamq3oRb4f7pPz3cMBaxKz