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

@nftperp/trader

v1.0.0

Published

Utilities to make market making on nftperp easier

Downloads

5

Readme

NFTPerp Trader

NFTPerp trader is a pure javascript library that streamlines the process of trading on the NFTPerp Platform. The NFTPerp Maker repo uses this script to market make on NFTPerp.

Example

The NFTPerp Maker repo that uses this library is production ready and was used to market make on the paper trading platform.

Install

npm i @nftperp/trader

Tests

Copy .env-example and create .env. Once the environment variables are set, you can perform integration tests with:

npm test

Getting Started

The liveTrader can be instantiated as below:

const liveTrader = require('@nftperp/trader');
let lt = new liveTrader(signer, amm, leverage=1, testnet = true);

Parameters:

signer: An Ethereum signer.
amm: Denotes the chosen market.
leverage: The leverage trader is willing to use, with a default of 1.
testnet: A boolean flag indicating if the system operates in testnet mode (default is true).

It contains the following method:

1. initialize()

Sets up contract addresses and initializes the ClearingHouse contract.

Parameters: None.
Return: void.

2. getPrice()

Fetches the current mark price for the chosen market.

Parameters: None.
Return: float - representing the markPrice.

3. getIndexPrice()

Fetches the current index price for the selected market.

Parameters: None.
Return: float - representing the indexPrice.

4. getPosition()

Retrieves the trader's position in the given market

Parameters: None.
Return: Object representing the trader's position

5. getPositionSize()

Retrieves the size of the trader's position at the market price.

Parameters: None.
Return: float - representing the position size.

6. getBalance()

Obtains the WETH balance associated with the trader's address

Parameters: None.
Return: float  - balance in ETH format.

7. getETHBalance()

Queries the Ethereum balance of the trader's address

Parameters: None.
Return: float - balance in ETH format.

8. cancelAllLimitOrders()

Cancels all of the trader's limit orders in the chosen market

Parameters: None.
Return: void

9. createLimitOrder(side, price, amount)

Sets up a limit order based on the provided criteria.

Parameters: 
    side: String ("LONG" or "SHORT") to indicate order direction.
    price: Numeric value for the desired order price.
    amount: Numeric value for the order amount.

Return: Transaction object.

10. updateLimitOrder(id, side, price, amount)

Modifies an existing limit order based on its ID and provided parameters.

Parameters: 
    id: Order ID to be updated.
    side: String ("LONG" or "SHORT") to indicate order direction.
    price: Numeric value for the desired order price.
    amount: Numeric value for the order amount.

Return: Transaction object.

11. cancelLimitOrder(side, price)

Cancels a specified limit order based on its side and price.

Parameters: 
    side: String indicating order side.
    price: Numeric value indicating order price.

Return: Transaction object

12. cancelOrder(orderId)

Cancels a specified limit order based on its id

Parameters: 
    orderId: ID of the order to be canceled.

Return: Transaction object

13. sumBuyAndSellOrders()

Aggregates the value of all of the trader's buy and sell orders.

Parameters: None.
Return: Object with properties buySum and sellSum indicating the totals.

14. getMyOrders()

Fetches the trader's orderbook, segmented into buy and sell orders.

Parameters: None.
Return: Object containing arrays buyOrders and sellOrders, sorted by price.

15. getOrders()

Retrieves the entire orderbook, segmented into buy and sell orders.

Parameters: None.
Return: Object containing arrays buyOrders and sellOrders, sorted by price.