-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6c49b8
commit ff6688a
Showing
108 changed files
with
5,378 additions
and
10,435 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,10 @@ | ||
# dependencies | ||
node_modules | ||
|
||
# builds | ||
build | ||
dist | ||
lib | ||
.rpt2_cache | ||
|
||
# misc | ||
node_modules/ | ||
build/ | ||
dist/ | ||
lib/ | ||
.DS_Store | ||
.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
*~ | ||
.idea | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
language: node_js | ||
node_js: | ||
- 12 | ||
- 10 | ||
node_js: 12 | ||
dist: bionic | ||
cache: yarn | ||
before_script: | ||
- yarn build |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,87 @@ | ||
[](https://www.npmjs.com/package/@project-serum/serum) | ||
[](https://travis-ci.com/project-serum/serum-js) | ||
<div align="center"> | ||
<img height="170" src="http://github.com/project-serum/awesome-serum/blob/master/logo-serum.png?raw=true" /> | ||
|
||
<h1>serum-ts</h1> | ||
|
||
<p> | ||
<strong>Project Serum Monorepo</strong> | ||
</p> | ||
|
||
<p> | ||
<a href="https://travis-ci.com/project-serum/serum-ts"><img alt="Build Status" src="https://travis-ci.com/project-serum/serum-ts.svg?branch=master" /></a> | ||
<a href="https://discord.com/channels/739225212658122886"><img alt="Discord Chat" src="https://img.shields.io/discord/739225212658122886?color=blueviolet" /></a> | ||
<a href="https://opensource.org/licenses/Apache-2.0"><img alt="License" src="https://img.shields.io/github/license/project-serum/serum-dex?color=blue" /></a> | ||
</p> | ||
|
||
<h4> | ||
<a href="https://projectserum.com/">Website</a> | ||
<span> | </span> | ||
<a href="https://serum-academy.com/en/">Academy</a> | ||
<span> | </span> | ||
<a href="https://github.com/project-serum/awesome-serum">Awesome</a> | ||
<span> | </span> | ||
<a href="https://dex.projectserum.com/#/">DEX</a> | ||
<span> | </span> | ||
<a href="https://github.com/project-serum/serum-dex">Rust</a> | ||
</h4> | ||
</div> | ||
|
||
## Packages | ||
|
||
| Package | Version | Description | | ||
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- | | ||
| [`@project-serum/borsh`](/packages/borsh) | [](https://www.npmjs.com/package/@project-serum/borsh) | Borsh serialization primitives | | ||
| [`@project-serum/common`](/packages/common) | [](https://www.npmjs.com/package/@project-serum/common) | Common utilities | | ||
| [`@project-serum/serum`](/packages/serum) | [](https://www.npmjs.com/package/@project-serum/tserum) | Library for interacting with the Serum DEX | | ||
| [`@project-serum/lockup`](/packages/lockup) | [](https://www.npmjs.com/package/@project-serum/lockup) | Client for interacting with the Lockup Program | | ||
| [`@project-serum/pool`](/packages/pool) | [](https://www.npmjs.com/package/@project-serum/pool) | Client for interacting with Pools | | ||
| [`@project-serum/registry`](/packages/registry) | [](https://www.npmjs.com/package/@project-serum/registry) | Client for interacting with the Registry Program | | ||
| [`@project-serum/swap`](/packages/swap) | [](https://www.npmjs.com/package/@project-serum/swap) | Client for interacting witht the Swap Program | | ||
| [`@project-serum/tokens`](/packages/tokens) | [](https://www.npmjs.com/package/@project-serum/tokens) | Solana token addresses | | ||
|
||
## Contributing | ||
|
||
### Installing | ||
|
||
To get started first install the required build tools: | ||
|
||
# Serum JS Client Library | ||
``` | ||
npm install -g lerna | ||
npm install -g yarn | ||
``` | ||
|
||
JavaScript client library for interacting with the Project Serum DEX. | ||
Then bootstrap the workspace: | ||
|
||
## Installation | ||
``` | ||
yarn | ||
``` | ||
|
||
Using npm: | ||
### Building | ||
|
||
To build the workspace: | ||
|
||
``` | ||
npm install @solana/web3.js @project-serum/serum | ||
yarn build | ||
``` | ||
|
||
Using yarn: | ||
### Testing | ||
|
||
To run all tests: | ||
|
||
``` | ||
yarn add @solana/web3.js @project-serum/serum | ||
yarn test | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
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, | ||
); | ||
} | ||
} | ||
### Linting | ||
|
||
To lint: | ||
|
||
``` | ||
yarn lint | ||
``` | ||
|
||
To apply lint fixes: | ||
|
||
``` | ||
yarn lint:fix | ||
``` |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.