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

@gmx-io/sdk

v0.1.0

Published

## Install

Downloads

726

Readme

GMX SDK

Install

yarn add @gmx-io/sdk # or
npm install --save @gmx-io/sdk

Usage

import { GmxSdk } from "@gmx/sdk";
import { useWallet } from "wagmi";

const sdk = new GmxSdk({
  chainId: 42161,
  rpcUrl: "https://arb1.arbitrum.io/rpc",
  oracleUrl: "https://arbitrum-api.gmxinfra.io",
  walletClient: useWallet().walletClient,
  subgraph: {
    subsquid: "https://gmx.squids.live/gmx-synthetics-arbitrum/graphql",
  },
});

const { marketsInfoData, tokensData } = await sdk.markets.getMarketsInfo();

sdk.setAccount("0x1234567890abcdef1234567890abcdef12345678");

sdk.positions.getPositions().then((positions) => {
  console.log(positions);
});

Documentation

Read methods

Markets

  • getMarkets(offset?: number, limit?: number): Promise<Market[]> - returns a list of markets
  • getMarketsInfo(): Promise<{ marketsInfoData: MarketInfoData[], tokensData: TokenData[] }> - returns a list of markets info and tokens data
  • getDailyVolumes(): Promise<{market: string; volume: bigint}[]> - returns markets' daily volume data

Positions

  • getPositions(): Promise<Position[]> - returns a list of positions

Tokens

  • getTokensData(): Promise<TokenData[]> - returns a list of tokens data

Orders

  • getOrders(): Promise<Order[]> - returns a list of orders

Trades

  • getTradeHistory(p: Parameters): Promise<TradeAction[]> - returns a list of trades

Write methods

Orders

  • cancelOrders(orderKeys: string[]) - cancels orders by order keys
  • createIncreaseOrder(p: Parameters) - creates an increase order (see examples)
  • createDecreaseOrder(p: Parameters) - creates a decrease order (see examples)
  • createSwapOrder(p: Parameters) - creates a swap order (see examples)

Configuration

interface GmxSdkConfig {
  chainId: number;
  rpcUrl: string;
  oracleUrl: string;
  subgraph: {
    subsquid?: string;
  };
  account?: string;
  publicClient: PublicClient;
  walletClient: WalletClient;
  tokens?: Record<string, Partial<Token>>;
  markets?: Record<
    string,
    {
      isListed: boolean;
    }
  >;
}

Tokens customization

If you need to override some field in tokens, just pass extension object in SDK config:

const sdk = new GmxSdk({
  ...arbitrumSdkConfig,
  tokens: {
    "0x912CE59144191C1204E64559FE8253a0e49E6548": {
      name: "My Custom Name for ARB",
    },
  },
});

Here and further, name field in tokens data object will be taken from the extension object.

Markets customization

To enable/disable market in SDK use config field `markets

const sdk = new GmxSdk({
  ...arbitrumSdkConfig,
  markets: {
    "0x47c031236e19d024b42f8AE6780E44A573170703": {
      isListed: false,
    },
  },
});

Examples

Open long position

import type { IncreasePositionAmounts } from "@gmx-io/sdk/types/orders";

const { marketsInfoData, tokensData } = await sdk.markets.getMarketsInfo();

if (!marketsInfoData || !tokensData) {
  throw new Error("No markets or tokens info data");
}

const marketInfo = marketsInfo["0x47c031236e19d024b42f8AE6780E44A573170703"];
const collateralToken = tokensData["0x912CE59144191C1204E64559FE8253a0e49E6548"];
sdk.orders.createIncreaseOrder({
  marketsInfoData: marketsInfoData!,
  tokensData,
  isLimit: false,
  isLong: true,
  marketAddress: marketInfo.marketTokenAddress,
  allowedSlippage: 50,
  collateralToken,
  collateralTokenAddress: collateralToken.address,
  receiveTokenAddress: collateralToken.address,
  fromToken: tokensData["0x912CE59144191C1204E64559FE8253a0e49E6548"],
  marketInfo,
  indexToken: marketInfo.indexToken,
  increaseAmounts: {
    // amounts for position
  },
});