{"id":30694300,"url":"https://github.com/goosefx1/gfx-perp-ts-sdk","last_synced_at":"2026-07-30T00:31:49.771Z","repository":{"id":158111932,"uuid":"633379855","full_name":"GooseFX1/gfx-perp-ts-sdk","owner":"GooseFX1","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-03T18:54:21.000Z","size":891,"stargazers_count":0,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-02T06:08:03.606Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GooseFX1.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-27T11:25:53.000Z","updated_at":"2024-06-03T22:13:03.000Z","dependencies_parsed_at":"2023-12-28T15:27:49.116Z","dependency_job_id":"153647cd-8efe-49c4-93ea-840d133c4356","html_url":"https://github.com/GooseFX1/gfx-perp-ts-sdk","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/GooseFX1/gfx-perp-ts-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GooseFX1%2Fgfx-perp-ts-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GooseFX1%2Fgfx-perp-ts-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GooseFX1%2Fgfx-perp-ts-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GooseFX1%2Fgfx-perp-ts-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GooseFX1","download_url":"https://codeload.github.com/GooseFX1/gfx-perp-ts-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GooseFX1%2Fgfx-perp-ts-sdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279010340,"owners_count":26084739,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-02T06:05:52.214Z","updated_at":"2025-10-12T06:02:49.886Z","avatar_url":"https://github.com/GooseFX1.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"  \u003cdiv align=\"center\"\u003e\n  \u003ch1\u003eGooseFX Perpetual Futures SDK\u003c/h1\u003e\n  \u003cimg height=\"142\" src=\"https://github.com/GooseFX1/gfx-web-app/blob/dev/public/img/assets/gfx_logo_gradient_lite.svg\" /\u003e\n\n\n  \u003ch4\u003e\n    \u003ca href=\"https://goosefx.io\"\u003eWebsite\u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://docs.goosefx.io\"\u003eDocs\u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://discord.com/channels/833693973687173121/833742620371058688\"\u003eDiscord\u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://www.t.me/goosefx\"\u003eTelegram\u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://medium.com/goosefx\"\u003eMedium\u003c/a\u003e\n  \u003c/h4\u003e\n  \u003cbr /\u003e\n  \u003cbr /\u003e\n\u003c/div\u003e\n\n\n  This SDK contains 3 classes to interact with the GooseFX on-chain perpetual futures. \n  * ``Perp``\n  * ``Product``\n  * ``Trader``\n\n  The `Perp` class is required to initialise the connection and wallet that is going to be used for subsequent interaction. \n  Initialising the `Perp` class should be the first step irrespective of the type of operation in the following manner: \n\n  ```javascript\n  const perp = new Perp(connection, 'mainnet', wallet);\n  await perp.init();\n  ```\n\n\n### Product\n\n  An instance of the `product` class signfies one of the perp product we offer to trade. Initialization of the `product` class can be done in one of two ways: \n\n  1. By index: \n\n  ```javascript\n  const perp = new Perp(connection, 'mainnet', wallet);\n  await perp.init();\n  const product = new Product(perp);\n  product.initByIndex(0);\n  ```\n\n  2. By name:\n\n  ```javascript\n  const perp = new Perp(connection, 'mainnet', wallet);\n  await perp.init();\n  const product = new Product(perp);\n  product.initByName('SOL-PERP');\n  ```\n\n  This `product` instance will be useful for the following functions: \n\n  * `GET L2 Orderbook`: Get the latest layer 2 orderbook\n  ```javascript\n  const orderbook = await product.getOrderbookL2();\n  ```\n\n  * `GET L3 Orderbook`: Get the latest layer 3 orderbook. (Orders mapped to users)\n  ```javascript\n  const orderbook = await product.getOrderbookL3();\n  ```\n  * `Subscribe to Orderbook`: Subscribe to the orderbook account and listen to changes. In the example below, `handleAccountChange` is the callback function which will be called on each state change of the orderbook. Pass your function as the parameter to the ```subscribeToOrderbook ```function to handle orderbook changes and do not forget to unsubscribe when not needed anymore!\n\n  ```javascript\n    async function handleAccountChange(){\n      const res = await product.getOrderbookL2();\n      console.log(\"Updated orderbook: \", res);\n    }\n    const subscribeId = product.subscribeToOrderbook(handleAccountChange);\n    connection.removeAccountChangeListener(subscribeId); //To close the subscription\n  ```\n### Trader\n\n  The `Trader` class is required to get instructions to send transactions to the program. Each wallet must have a unique trader account initialized to be able to place orders and deposit funds. This account needs to be created once using the ```createTraderAccountIxs``` instruction. After it has been created once, for all subsequent interactions by the wallet, the `Trader` class needs to be initialized using the ```init``` function. \n  * To create a new `Trader` account on-chain: \n  ```javascript\n    const perp = new Perp(connection, 'mainnet', wallet);\n    await perp.init();\n    const trader = new Trader(perp);\n    const [ixs, signers] = await trader.createTraderAccountIxs();\n  ```\n  where ```ixs``` is an array of required instructions and ```signers``` is an array of required keypairs for signature. The wallet must also sign the transaction along with the keypairs in the ```signers``` array\n\n  * Once the account is created successfully, the `Trader` instance must be initialised in the following way: \n  ```javascript\n    const perp = new Perp(connection, 'mainnet', wallet);\n    await perp.init();\n    const trader = new Trader(perp);\n    await trader.init();\n  ```\n\n## Fractional Datatype\nThe Fractional data type uses a simple formula to represent a fractional number based on its mantissa (m) and exponent (exp):\n`number = mantissa / (10 ^ exponent)`\n\n## Trader Instructions\n\n### Deposit Funds\n\nTo start placing new orders, traders need to deposit some collateral. This instruction will transfer the required USDC from the wallet to the trader account which will be used as collateral to place new orders.\n\nThe only parameter to this function is the amount of USDC to be depositted.\n\n```javascript\n  const perp = new Perp(connection, 'mainnet', wallet);\n  await perp.init();\n  const trader = new Trader(perp);\n  await trader.init();\n  const ix = await trader.depositFundsIx(new Fractional({\n    m: new BN(1),\n    exp: new BN(0)\n  }));\n```\n\n### Withdraw Funds\n\nSimilar to deposit funds, this function takes the amount of USDC to be withdrawn as the only parameter. This instruction will transfer funds from the trader account to the wallet address.\n\n```javascript\n  const perp = new Perp(connection, 'mainnet', wallet);\n  await perp.init();\n  const trader = new Trader(perp);\n  await trader.init();\n  const ix = await trader.withdrawFundsIx(new Fractional({\n    m: new BN(1),\n    exp: new BN(0)\n  }));\n```\n\nNOTE: The above two instructions do not need a `product` instance as a parameter since the market is cross collateralized and the amount of USDC deposited can be used across products. The following two instructions to place a new order and cancel an order are specific to products and hence need a `product` instance as one of the parameters.\n\n### Trader's open orders for a prouct\n\n  To get all open orders for a `Trader` for a `product`:\n  ```javascript\n    const perp = new Perp(connection, 'mainnet', wallet);\n    await perp.init();\n    const product = new Product(perp);\n    product.initByIndex(0);\n    const trader = new Trader(perp);\n    await trader.init();\n    const orderbookData = await trader.getOpenOrders(product);\n    console.log(\"orderbook: \", orderbookData);\n  ```\n\n### New Order\n\nThe New order instruction needs the following as parameters\n  * Quantity (Fractional) \n  **Please note: 1 unit of the product is denoted by 1 * 100000 units. So to buy 1 unit, the parameter to pass as quantity should be** \n  ```javascript\n    new Fractional({\n      m: new BN(100000),\n      exp: new BN(0)\n    })\n  ``` \n  * Price (Fractional)\n  * Order side ('buy' or 'sell')\n  * Order Type ('limit', 'market', 'immediateOrCancel', 'postOnly')\n  * Product instance\n  * Call back ID: A number between 0 and 4294967295 to uniquely identiy the order in trade events\n\n```javascript\n  const perp = new Perp(connection, \"mainnet\", wallet);\n  await perp.init();\n  const product = new Product(perp);\n  product.initByIndex(0);\n  const trader = new Trader(perp);\n  await trader.init();\n  const ix = await trader.newOrderIx(\n    new Fractional({\n      m: new BN(10000), //Implies 0.1 units\n      exp: new BN(0),\n    }),\n    new Fractional({\n      m: new BN(2245), //Price 22.45$\n      exp: new BN(2),\n    }),\n    \"buy\",\n    \"limit\",\n    product,\n    1435\n  );\n```\n\n### Cancel Order\n\n  The cancel order instruction needs the orderId in string format to cancel the order. Use `getOpenOrders()` to get open orders and its id's to pass as a parameter to cancel the order \n\n  ```javascript\n    const perp = new Perp(connection, \"mainnet\", wallet);\n    await perp.init();\n    const product = new Product(perp);\n    product.initByIndex(0);\n    const trader = new Trader(perp);\n    await trader.init();\n    const ix = await trader.cancelOrderIx(\"7922816251444880503428103912726\", product);\n  ```\n\n  ### Get all Trader addresses\n\n  To get the list of all the trader addresses use `getAllTraderAddresses()` function.\n  \n  ```javascript\n    const perp = new Perp(connection, \"mainnet\", wallet);\n    await perp.init();\n    const trader = new Trader(perp);\n    await trader.init();\n    const traderAddresses = await trader.getAllTraderAddresses()\n    console.log(traderAddresses)\n  ```\n\n### Close Trader Risk Group\n\n  To close the trader risk group and claim the initial deposited SOL, Use `closetrgIx()` function.  \n\n  ```javascript\n    const perp = new Perp(connection, \"mainnet\", wallet);\n    await perp.init();\n    const product = new Product(perp);\n    product.initByIndex(0);\n    const trader = new Trader(perp);\n    await trader.init();\n    const ix = await trader.closetrgIx();\n  ```\n\n\n\nCheckout https://github.com/GooseFX1/gfx-perp-ts-sdk/blob/main/test/index.test.js for examples on the above functionalities! Happy trading!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoosefx1%2Fgfx-perp-ts-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoosefx1%2Fgfx-perp-ts-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoosefx1%2Fgfx-perp-ts-sdk/lists"}