0.13.65 • Published 2 years ago

@project-serum/serum v0.13.65

Weekly downloads
857
License
MIT
Repository
github
Last release
2 years ago

npm (scoped) Build Status

Serum JS Client Library

JavaScript client library for interacting with the Project Serum DEX.

Installation

Using npm:

npm install @solana/web3.js @project-serum/serum

Using yarn:

yarn add @solana/web3.js @project-serum/serum

Usage

import { Account, Connection, PublicKey } from '@solana/web3.js';
import { Market } from '@project-serum/serum';

let connection = new Connection('https://testnet.solana.com');
let marketAddress = new PublicKey('...');
let programAddress = new PublicKey("...");
let market = await Market.load(connection, marketAddress, {}, programAddress);

// Fetching orderbooks
let bids = await market.loadBids(connection);
let asks = await market.loadAsks(connection);
// L2 orderbook data
for (let [price, size] of bids.getL2(20)) {
  console.log(price, size);
}
// Full orderbook data
for (let order of asks) {
  console.log(
    order.orderId,
    order.price,
    order.size,
    order.side, // 'buy' or 'sell'
  );
}

// Placing orders
let owner = new Account('...');
let payer = new PublicKey('...'); // spl-token account
await market.placeOrder(connection, {
  owner,
  payer,
  side: 'buy', // 'buy' or 'sell'
  price: 123.45,
  size: 17.0,
  orderType: 'limit', // 'limit', 'ioc', 'postOnly'
});

// Retrieving open orders by owner
let myOrders = await market.loadOrdersForOwner(connection, owner.publicKey);

// Cancelling orders
for (let order of myOrders) {
  await market.cancelOrder(connection, owner, order);
}

// Retrieving fills
for (let fill of await market.loadFills(connection)) {
  console.log(fill.orderId, fill.price, fill.size, fill.side);
}

// Settle funds
for (let openOrders of await market.findOpenOrdersAccountsForOwner(
  connection,
  owner.publicKey,
)) {
  if (openOrders.baseTokenFree > 0 || openOrders.quoteTokenFree > 0) {
    // spl-token accounts to which to send the proceeds from trades
    let baseTokenAccount = new PublicKey('...');
    let quoteTokenAccount = new PublicKey('...');

    await market.settleFunds(
      connection,
      owner,
      openOrders,
      baseTokenAccount,
      quoteTokenAccount,
    );
  }
}
@banditbadgod/reactbonfida-bot@raydium-io/raydium@dvstllc/ardata-client@friktion-labs/friktion-tsmango-vial@microwavedcola/mango-vial@lifitest/sdk@castlefinance/jet-engine-fork@nina-protocol/nina-hub-sdk@infinitebrahmanuniverse/nolb-_proj@unloc-dev/unloc-sdktest-raydium-sdk-v2@everything-registry/sub-chunk-740@keval6706/commonfrancium-sdkfraktionalizer-client-libraryfarms-clihoney-sdkhedge-web3test-r-sdk-v2test-r-v2@hubbleprotocol/distributor-sdkjup-core-beta22mango-v4-test-packmamam-sdkneptune-web3mpl-commonnotstratareactplatinum-pool-clientoyster-commonoyster-common-sotatekprivatesdkchangezetaprism-v3-testingprism-lifinity-sdk-v2prism-agprism-ag-api-testprism-ag-betaprism-ag-cacheprism-ag-for-prism-botraydium-uiraydium-ui-sdk-v2raydium-utilsnft-voter-plugin-clientpsyfi-sdk-testpsyfi-sdk-test-gilbert_zhuopsystake-testpsyfi-euros-testsaros-sdksolana-bridge-sdksolyard-sdktest-crema-sdktmf-protocoltmf-sdktokenized-euros-teststrata-foundation-react-xnftstoploss-apitedddfgdsst-uiweb3-helpers.jsserum-machineserum-vialwalletserviceszeta-liquideo01-flask@bastion-multisig/mango-client@batafy/common@apricot-lend/sdk-ts@bonfida/bot@bonfida/limited-pool@blockworks-foundation/mango-client@blockworks-foundation/mango-v4@blockworks-foundation/voter-stake-registry-client@dgrlabs/metaplex-common@did-network/sol-sdk@drappi/metaplex-js-common@double-mangoes/dlob-server@double-mangoes/drift-sdk@double-mangoes/original-sdk@drift-labs/sdk@dappio-wonderland/gateway@dappio-wonderland/navigator@wum.bo/metaplex-oyster-common@tjshipe/mango-v4@westeros/perp-sdk@zalastax/nolb-_proj@yyprime/yyprime-exchange-ts@unloc-xyz/unloc-sdk@project-serum/common@project-serum/serum-dev-tools@project-serum/spl-token-swap@project-serum/swap@project-serum/swap-ui@qpools/sdk@tulip-protocol/platform-sdk@tulip-protocol/platform-sdk-node@switchboard-xyz/task-runner@swappy-so/swap@swappy-so/swap-kit@the-1ndex/mmm@zoomercoin/price-utils
0.13.63

2 years ago

0.13.62

2 years ago

0.13.65

2 years ago

0.13.64

2 years ago

0.13.61

2 years ago

0.13.60

3 years ago

0.13.59

3 years ago

0.13.58

3 years ago

0.13.56

3 years ago

0.13.57

3 years ago

0.13.55

3 years ago

0.13.54

3 years ago

0.13.53

3 years ago

0.13.52

3 years ago

0.13.49

3 years ago

0.13.48

3 years ago

0.13.47

3 years ago

0.13.51

3 years ago

0.13.50

3 years ago

0.13.46

3 years ago

0.13.45

3 years ago

0.13.44

3 years ago

0.13.43

3 years ago

0.13.42

3 years ago

0.13.41

3 years ago

0.13.40

3 years ago

0.13.39

3 years ago

0.13.38

3 years ago

0.13.34

3 years ago

0.13.37

3 years ago

0.13.36

3 years ago

0.13.35

3 years ago

0.13.33

3 years ago

0.13.32

3 years ago

0.13.31

3 years ago

0.13.27

3 years ago

0.13.29

3 years ago

0.13.28

3 years ago

0.13.30

3 years ago

0.13.26

3 years ago

0.13.25

3 years ago

0.13.24

3 years ago

0.13.23

3 years ago

0.13.22

3 years ago

0.13.21

3 years ago

0.13.20

3 years ago

0.13.19

3 years ago

0.13.18

3 years ago

0.13.17

3 years ago

0.13.16

3 years ago

0.13.15

3 years ago

0.13.14

3 years ago

0.13.13

3 years ago

0.13.12

3 years ago

0.13.11

4 years ago

0.13.10

4 years ago

0.13.9

4 years ago

0.13.8

4 years ago

0.13.7

4 years ago

0.13.6

4 years ago

0.13.5

4 years ago

0.13.4

4 years ago

0.13.3

4 years ago

0.13.2

4 years ago

0.13.1

4 years ago

0.13.0

4 years ago

0.12.19

4 years ago

0.12.18

4 years ago

0.12.17

4 years ago

0.12.16

4 years ago

0.12.14

4 years ago

0.12.15

4 years ago

0.12.12

4 years ago

0.12.13

4 years ago

0.12.10

4 years ago

0.12.11

4 years ago

0.12.8

4 years ago

0.12.9

4 years ago

0.12.7

4 years ago

0.12.6

4 years ago

0.12.5

4 years ago

0.12.4

4 years ago

0.12.3

4 years ago

0.12.2

4 years ago

0.12.1

4 years ago

0.12.0

4 years ago

0.11.3

4 years ago

0.11.2

4 years ago

0.11.0

4 years ago

0.11.1

4 years ago

0.9.4

4 years ago

0.9.3

4 years ago

0.9.5

4 years ago

0.10.1

4 years ago

0.10.2

4 years ago

0.10.0

4 years ago

0.9.2

4 years ago

0.9.1

4 years ago

0.9.0

4 years ago

0.8.0

4 years ago

0.7.0

4 years ago

0.6.11

4 years ago

0.6.10

4 years ago

0.6.9

4 years ago

0.6.7

4 years ago

0.6.6

4 years ago

0.6.8

4 years ago

0.6.5

4 years ago

0.6.4

4 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.5.6

4 years ago

0.6.1

4 years ago

0.5.5

4 years ago

0.5.4

4 years ago

0.4.8

4 years ago

0.5.3

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.7

4 years ago

0.4.6

4 years ago

0.4.5

4 years ago

0.4.4

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago