npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ftx-api-rest-extended

v1.1.3

Published

An extended wrapper of the FTX API package

Downloads

10

Readme

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