Nitroglycerin Pickle Machine

    @exodus/project-serum-serum
    TypeScript icon, indicating that this package has built-in type declarations

    0.13.64-exodus.0 • Public • Published

    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,
        );
      }
    }

    Keywords

    none

    Install

    npm i @exodus/project-serum-serum

    DownloadsWeekly Downloads

    1,280

    Version

    0.13.64-exodus.0

    License

    MIT

    Unpacked Size

    194 kB

    Total Files

    24

    Last publish

    Collaborators

    • jamiemaw
    • exodus-justin.za
    • brahim.ma
    • cmosetick
    • javiexodus
    • skanislav
    • wcastr
    • brandon-exodus
    • daniel.je
    • rg911
    • alex.alexandrius
    • filipexodus
    • jeremyex0j
    • ryansquared-npm
    • andrescarreon
    • florianmathieu
    • dwolfgram
    • eox42
    • iamsaikranthi
    • janwe
    • fosterdill
    • eduardoexodus
    • luvette
    • fboucquez
    • skapala
    • umito
    • lanahizzle
    • iaacek
    • nafisholeh
    • ariene-exodus
    • ps.mcnally
    • akinncar
    • matias.la
    • gaganatexodus
    • voltagebots
    • siva-ramnathan
    • kwwood
    • sergii_bo
    • dimitrios.pa
    • mongkuen
    • philipcr
    • jacobbr22
    • kashifchoudhry
    • lekzd
    • cdotta
    • alexandrbbm
    • danm.exodus
    • danh.t.vo
    • ezenwankwogabriel
    • meniem
    • mzndako
    • ianertson
    • kevva
    • aaronloexodus
    • vikgmdev
    • iamcrazycoder
    • cassapula
    • feri42
    • jprichardson
    • farisissa
    • dooglio
    • ryanzim
    • headfire
    • gutenye
    • mosesbot
    • roccomuso
    • dcastagnoli
    • sonaye
    • nareg_exodus
    • ves
    • tenaciousmv
    • asyakost
    • bulgakovk
    • sekhmet
    • chalker
    • andrejb
    • gordonel
    • jaydp17
    • olistic
    • joepie91
    • merlz
    • jadechip
    • vbonini
    • cooncesean
    • devopsrobot
    • jenish-sojitra
    • unidwell
    • nachoalvarez
    • giovannirco
    • rec
    • dncabal
    • diegomura
    • danilsergeev
    • lanre-mark
    • sunilagrawal
    • guillecura
    • mariosvlad
    • federico-po
    • pagan404