1.1.3 • Published 3 years ago

ftx-api-rest-extended v1.1.3

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

ftx-api-rest-extended

An extended version of the ftx-api-rest package made by askmike, I decided to write specific functions focused on spot / future trading ✨.

Table of contents

  1. Example
  2. Overview
    1. getBalance
    2. createOTCOrder
    3. fundingRate
    4. calculateOrderSize
    5. createOrder
    6. getOpenPositions
    7. getLimitOrders
    8. closeOrders
    9. closeLimitOrders

Install

npm install ftx-api-rest-extended

Usage

You can use the code snippet below as a reference, go to Overview for a breakdown of all the features

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();

Overview

A breakdown of all the functions within the module

getBalance

Get balance of the subaccount

getBalance()

Get the price of an future or spot asset

// _pair: Any asset on the ftx exchange such as BTC-PERP or BTC/USD
getPrice(_pair)

createOTCOrder

OTC (Over the counter) Convert X to Y

// _from: Asset you want to convert
// _to: Asset you want to convert to
// _size: How much you want to convert
createOTCOrder(_from, _to, _size)

fundingRate

Get the funding rate of a future contract

// _pair: Any asset on the ftx exchange such as BTC-PERP or BTC/USD
fundingRate(_pair)

calculateOrderSize

This will calculate the order size based on the portfolio balance

// _sizeInPercentage: how big the order has to be in percentage
// _pair: ETH-PERP or BTC-PERP
calculateOrderSize(_sizeInPercentage, _pair)

createOrder

Place your market or limit order, you can use the calculateOrderSize(_sizeInPercentage, _pair) function to calculate the unit amount

// _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)

getOpenPositions

Get all open positions

getOpenPositions()

getLimitOrders

Get all open limit orders

getLimitOrders()

closeOrders

Close all orders or of a specific pair

// _pair: close the orders of the specified asset
closeOrders(_pair = '')

closeLimitOrders

Close all limit orders or of a specific pair

// _pair: close the orders of the specified asset
closeLimitOrders(_pair = '')

Reference

Wanna buy me a coffee? ☕

ETH: mitchel.eth or 0x5584A353528dfeB2Fc751Ab48b72D32726C79507
BTC: bc1qqfnfkrnhv903v9v38n98vvk35hgrp77ay7kwqr or 1DhGZ1kvEF1wamq3oRb4f7pPz3cMBaxKz

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago