serum-js/README.md

49 lines
1.3 KiB
Markdown
Raw Normal View History

2020-08-10 10:57:25 -07:00
![npm (scoped)](https://img.shields.io/npm/v/@project-serum/serum)
[![Build Status](https://travis-ci.com/project-serum/serum-js.svg?token=1ySaVeP6gHs8QRr2VTEi&branch=master)](https://travis-ci.com/project-serum/serum-js)
2020-08-10 09:26:22 -07:00
# Serum JS Client Library
WIP
2020-08-10 10:57:25 -07:00
`yarn add @project-serum/serum`
2020-08-10 09:26:22 -07:00
```js
import { 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);
let bids = await market.loadBids(connection);
let asks = await market.loadAsks(connection);
for (let [price, size] of bids.getL2(20)) {
console.log(price, size);
}
for (let order of asks) {
console.log(
order.orderId,
order.owner.toBase58(),
order.price,
order.quantity,
order.side,
);
}
let owner = new Account('...');
let payer = new PublicKey('...');
await market.placeOrder(connection, {
owner,
payer,
side: 'buy', // 'buy' or 'sell'
price: 123.45,
size: 17.0,
orderType: 'limit', // 'limit', 'ioc', 'postOnly'
});
for (let order of await market.loadBids(connection)) {
if (order.owner.equals(owner.publicKey)) {
2020-08-10 09:26:22 -07:00
await market.cancelOrder(connection, order);
}
}
```