0.17.4 • Published 3 years ago
@civic/serum v0.17.4
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 market = await Market.load(connection, marketAddress);
// 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,
);
}
}
0.17.4
3 years ago
0.17.3
3 years ago
0.17.2
3 years ago
0.17.1
3 years ago
0.17.0
4 years ago
0.15.0
4 years ago
0.16.0
4 years ago
0.14.1
4 years ago
0.14.2
4 years ago
0.14.3
4 years ago
0.14.0
4 years ago
0.13.61
4 years ago
0.13.60
4 years ago
0.13.59
4 years ago
0.13.58
4 years ago
0.13.57
4 years ago
0.13.56
4 years ago
0.13.55
4 years ago
0.13.54
4 years ago
0.13.53
4 years ago
0.13.52
4 years ago
0.13.51
4 years ago
0.13.50
4 years ago
0.13.49
4 years ago
0.13.48
4 years ago
0.13.47
4 years ago
0.13.46
4 years ago
0.13.45
4 years ago
0.13.44
4 years ago
0.13.43
4 years ago
0.13.42
4 years ago
0.13.41
4 years ago
0.13.40
4 years ago
0.13.39
4 years ago
0.13.38
4 years ago
0.13.37
4 years ago
0.13.36
4 years ago
0.13.35
4 years ago
0.13.34
4 years ago
0.13.14
4 years ago
0.13.33
4 years ago