0.13.65 • Published 3 years ago

@project-serum/serum v0.13.65

Weekly downloads
857
License
MIT
Repository
github
Last release
3 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/commontest-dev-sdktest-crema-sdkwalletservicessaros-sdktedddfgdsst-uistoploss-apiserum-machineserum-vialtest-r-sdk-v2test-r-v2@hubbleprotocol/distributor-sdk@foresight-tmp/foresight-sdkjito-kitmpl-commonjup-core-beta22hedge-web3honey-sdklaunchpad-sdkmango-v4-test-packmamam-sdkopt-raydium-sdk-v2oyster-commonoyster-common-sotatekpsyfi-euros-testpsyfi-sdk-testpsyfi-sdk-test-gilbert_zhuopsystake-testprivatesdkchangezetaprism-lifinity-sdk-v2prism-v3-testingprism-agprism-ag-api-testprism-ag-betaprism-ag-cacheprism-ag-for-prism-botnft-voter-plugin-clientplatinum-pool-clientneptune-web3notstratareactraydium-uiraydium-ui-sdk-v2raydium-utilsspl-price-in-solstrata-foundation-react-2strata-foundation-react-xnftsolana-bridge-sdksolana-bundlingsolyard-sdktmf-protocoltmf-sdktokengobblertokenized-euros-test@apricot-lend/sdk-ts@batafy/common@bastion-multisig/mango-client@blockworks-foundation/mango-client@blockworks-foundation/mango-v4@blockworks-foundation/voter-stake-registry-client@burnt/common@chugach-foundation/cypher-client9mm-sdk01-flask@deriverse/sdk@dgrlabs/metaplex-common@did-network/sol-sdk@dappio-wonderland/gateway@dappio-wonderland/navigator@david-lab/sol-libweb3-helpers.jsweb3-bundle-helper.jsweb3-bundle-helpers.jszeta-liquideo@hashfund/program@frakters/fraktionalizer-client-library@hubbleprotocol/kamino-sdk@hubbleprotocol/rarefish-sdk@hubbleprotocol/distributor@hubbleprotocol/farms-sdk@heymike/raydium-sdk-v2@hydraprotocol/migrations@hydraprotocol/sdk@icesolution/sdk@gamify/onchain-program-sdk@friktion-labs/entropy-client@friktion-labs/friktion-sdk
0.13.63

3 years ago

0.13.62

3 years ago

0.13.65

3 years ago

0.13.64

3 years ago

0.13.61

3 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

4 years ago

0.13.34

4 years ago

0.13.37

4 years ago

0.13.36

4 years ago

0.13.35

4 years ago

0.13.33

4 years ago

0.13.32

4 years ago

0.13.31

4 years ago

0.13.27

4 years ago

0.13.29

4 years ago

0.13.28

4 years ago

0.13.30

4 years ago

0.13.26

4 years ago

0.13.25

4 years ago

0.13.24

4 years ago

0.13.23

4 years ago

0.13.22

4 years ago

0.13.21

4 years ago

0.13.20

4 years ago

0.13.19

4 years ago

0.13.18

4 years ago

0.13.17

4 years ago

0.13.16

4 years ago

0.13.15

4 years ago

0.13.14

4 years ago

0.13.13

4 years ago

0.13.12

4 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