# omxjs

> omx ts client

Latest version **0.0.14** (published 2023-09-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install omxjs
pnpm add omxjs
yarn add omxjs
bun add omxjs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.14 |
| Published | 2023-09-08 |
| First published | 2023-06-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=16.0.0 |
| Dependencies | 3 |
| Unpacked size | 304.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Omxadmin |
| Maintainers | omxlab |
| Keywords | omx, cosmos, cosmwasm, osmosis, osmo |

## Links

- npm: https://www.npmjs.com/package/omxjs
- npm.io page: https://npm.io/package/omxjs

## Dependencies (3)

- [@types/long](https://npm.io/package/@types/long.md) ^4.0.1
- [@cosmjs/amino](https://npm.io/package/@cosmjs/amino.md) ^0.30.1
- [@cosmjs/cosmwasm-stargate](https://npm.io/package/@cosmjs/cosmwasm-stargate.md) ^0.30.1

## Recent versions

- 0.0.14 (latest) — 2023-09-08
- 0.0.13 — 2023-09-08
- 0.0.12 — 2023-09-07
- 0.0.11 — 2023-08-31
- 0.0.10 — 2023-08-10
- 0.0.7 — 2023-07-25
- 0.0.5 — 2023-07-07
- 0.0.3 — 2023-07-05
- 0.0.2 — 2023-06-23
- 0.0.1 — 2023-06-23

## README

# OMX typescript api

Typescript client for interacting with [OMX](https://www.omxapp.com/) contracts.

[![ReadTheDocs](https://readthedocs.org/projects/switcheo-python/badge/?version=latest)](https://docs.omxapp.com)
[![license](https://img.shields.io/npm/l/omxjs.svg)](https://github.com/omxlabs/omxjs/blob/master/LICENSE.md)
[![npm](https://img.shields.io/node/v/omxjs.svg)](https://www.npmjs.com/package/omxjs)
[![npm](https://img.shields.io/npm/dt/omxjs.svg)](https://www.npmjs.com/package/omxjs)

## Installation

## Requirements

- node >= 16, highly recommend to use [nvm](https://github.com/nvm-sh/nvm) (or [nvm-windows](https://github.com/coreybutler/nvm-windows))
- [Osmosis localnet](https://github.com/osmosis-labs/osmosis/tree/main/tests/localosmosis) for testing

```bash
npm i omxjs
```

## Examples

Simple example of creating a position with the client:

```typescript
import { OmxCwRouterClient, OmxCwVaultClient } from "omxjs";
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";

// replace with the addresses of the contracts on your chain
const vaultAddress = "osmo1...";
const routerAddress = "osmo1...";
const osmoAddress = "osmo1...";

const ownAddress = "osmo1a..."; // replace with your address
const cwClient: SigningCosmWasmClient = ...; // create a client for the chain with signer you prefer

const vaultClient = new OmxCwVaultClient(cwClient, ownAddress, vaultAddress);
const routerClient = new OmxCwRouterClient(cwClient, ownAddress, routerAddress);

// In real world this should be the price from the oracle with 18 decimals precision
const priceInUsd = BigInt(1e18);

const amountIn = BigInt(100e6); // 100 uosmo
const leverage = 3n; // 3x leverage

// Add router to the vault
await vaultClient.addRouter({ router: routerAddress });

// Create position
await routerClient.increasePositionOsmo({
    collateral: {
        token: osmoAddress,
    },
    indexToken: osmoAddress,
    isLong: true,
    price: priceInUsd.toString(),
    minOut: "0",
    sizeDelta: (priceInUsd * leverage).toString(),
}, "auto", "", [{ denom: "uosmo", amount: amountIn.toString()}]);

// Check the position
const position = await vaultClient.position({
    account: ownAddress,
    indexToken: osmoAddress,
    collateralToken: osmoAddress,
    isLong: true,
});

console.log("position", position);
```

## Code generation

### Requirements

- [cargo-make](https://crates.io/crates/cargo-make/0.3.54)

### Generate code

```bash
npm i
# generate code for specific tag
npm run code-gen v0.0.12
```

---
_Source: https://npm.io/package/omxjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
