Add documentation
This commit is contained in:
parent
9148c07986
commit
82f05636da
|
@ -0,0 +1,5 @@
|
||||||
|
ENVIRONMENT=dev
|
||||||
|
PORT=3005
|
||||||
|
SECRETS_FILE="path/to/secrets/file.json"
|
||||||
|
LOGGING_DIR=""
|
||||||
|
SOLANA_VALIDATORS_URL="http://vip-api.mainnet-beta.solana.com"
|
61
README.md
61
README.md
|
@ -1 +1,62 @@
|
||||||
# serum-rest-server
|
# serum-rest-server
|
||||||
|
|
||||||
|
# Install
|
||||||
|
|
||||||
|
This server uses `yarn` to manage node.js dependencies. To install dependencies, from the root directory run
|
||||||
|
|
||||||
|
```
|
||||||
|
yarn
|
||||||
|
```
|
||||||
|
|
||||||
|
to build the workspace run
|
||||||
|
|
||||||
|
```
|
||||||
|
yarn build
|
||||||
|
```
|
||||||
|
|
||||||
|
to start the server in debug mode
|
||||||
|
|
||||||
|
```
|
||||||
|
DEBUG=js:* yarn start
|
||||||
|
```
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
|
||||||
|
Server configurations are managed with [dotenv](https://www.npmjs.com/package/dotenv). A default configuration is
|
||||||
|
provided in `.env.development`. The server looks for solana private keys in the file specified by the `SECRETS_FILE`
|
||||||
|
config. Without any further configuration to permission the server, create a file with following format, replacing
|
||||||
|
`"your_bs58_private_key"` with your base58 encoded solana private key (which you can export from sollet.io).
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"serum_private_key": "your_bs58_private_key"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Then store this file at a location of your choosing and set the `SECRETS_FILE` config to your chosen location. Note
|
||||||
|
that `dotenv` by default looks for `.env` files, so you will need to rename `.env.development` to `.env` for the
|
||||||
|
configurtation file to take effect.
|
||||||
|
|
||||||
|
# Shell
|
||||||
|
|
||||||
|
A node.js shell is provided for debugging purposes. Start the shell with
|
||||||
|
|
||||||
|
```
|
||||||
|
yarn shell
|
||||||
|
```
|
||||||
|
|
||||||
|
An example of fetching an orderbook for the `BTC/USDC` pair is provided below.
|
||||||
|
|
||||||
|
```
|
||||||
|
[~/serum-rest-server]$ yarn shell
|
||||||
|
> sapi = await SerumApi.create()
|
||||||
|
...
|
||||||
|
> await sapi.getWsOrderbook('BTC', 'USDC')
|
||||||
|
{
|
||||||
|
bids: [...],
|
||||||
|
asks: [...],
|
||||||
|
market: Pair { coin: 'BTC', priceCurrency: 'USDC' },
|
||||||
|
validAt: ...,
|
||||||
|
receivedAt: ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
|
@ -62,6 +62,7 @@ import {
|
||||||
} from "./solana";
|
} from "./solana";
|
||||||
import { WRAPPED_SOL_MINT } from "@project-serum/serum/lib/token-instructions";
|
import { WRAPPED_SOL_MINT } from "@project-serum/serum/lib/token-instructions";
|
||||||
import { parse as urlParse } from "url";
|
import { parse as urlParse } from "url";
|
||||||
|
import bs58 from "bs58";
|
||||||
|
|
||||||
export class SerumApi {
|
export class SerumApi {
|
||||||
static readonly exchange: Exchange = "serum";
|
static readonly exchange: Exchange = "serum";
|
||||||
|
@ -115,7 +116,7 @@ export class SerumApi {
|
||||||
this.exchange = exchange;
|
this.exchange = exchange;
|
||||||
this._connections = conections;
|
this._connections = conections;
|
||||||
this._privateKey = getKeys([`${this.exchange}_private_key`])[0];
|
this._privateKey = getKeys([`${this.exchange}_private_key`])[0];
|
||||||
this._account = new Account(this._privateKey);
|
this._account = new Account(bs58.decode(this._privateKey));
|
||||||
this._publicKey = this._account.publicKey;
|
this._publicKey = this._account.publicKey;
|
||||||
this._loadedMarkets = {};
|
this._loadedMarkets = {};
|
||||||
this._wsOrderbooks = {};
|
this._wsOrderbooks = {};
|
||||||
|
@ -641,7 +642,7 @@ export class SerumApi {
|
||||||
logger.info(
|
logger.info(
|
||||||
`Order parameters: ${side}, ${coin}, ${priceCurrency}, ${quantity}, ${price}, ${orderType}`
|
`Order parameters: ${side}, ${coin}, ${priceCurrency}, ${quantity}, ${price}, ${orderType}`
|
||||||
);
|
);
|
||||||
const owner = new Account(this._privateKey);
|
const owner = this._account;
|
||||||
let payer;
|
let payer;
|
||||||
if (coin === "SOL" && side === Dir.S) {
|
if (coin === "SOL" && side === Dir.S) {
|
||||||
payer = this._publicKey;
|
payer = this._publicKey;
|
||||||
|
@ -808,7 +809,7 @@ export class SerumApi {
|
||||||
new BN(orderId)
|
new BN(orderId)
|
||||||
);
|
);
|
||||||
txn.add(market.makeMatchOrdersTransaction(5));
|
txn.add(market.makeMatchOrdersTransaction(5));
|
||||||
const signers = [new Account(this._privateKey)];
|
const signers = [this._account];
|
||||||
return {
|
return {
|
||||||
transaction: txn,
|
transaction: txn,
|
||||||
signers,
|
signers,
|
||||||
|
@ -861,7 +862,7 @@ export class SerumApi {
|
||||||
order.info.toSerumOrder()
|
order.info.toSerumOrder()
|
||||||
);
|
);
|
||||||
transaction.add(serumMarket.makeMatchOrdersTransaction(5));
|
transaction.add(serumMarket.makeMatchOrdersTransaction(5));
|
||||||
const signers = [new Account(this._privateKey)];
|
const signers = [this._account];
|
||||||
return {
|
return {
|
||||||
transaction,
|
transaction,
|
||||||
signers,
|
signers,
|
||||||
|
@ -1366,7 +1367,7 @@ export class SerumApi {
|
||||||
market
|
market
|
||||||
.settleFunds(
|
.settleFunds(
|
||||||
this._connection,
|
this._connection,
|
||||||
new Account(this._privateKey),
|
this._account,
|
||||||
openOrders,
|
openOrders,
|
||||||
baseTokenAccount,
|
baseTokenAccount,
|
||||||
quoteTokenAccount
|
quoteTokenAccount
|
||||||
|
|
|
@ -3,7 +3,9 @@ import { HARD_CODED_MINTS } from "../config";
|
||||||
import { Pair } from "./types";
|
import { Pair } from "./types";
|
||||||
import { PublicKey } from "@solana/web3.js";
|
import { PublicKey } from "@solana/web3.js";
|
||||||
|
|
||||||
export const MARKET_PARAMS = MARKETS.filter(marketInfo => !marketInfo.deprecated).map((marketInfo) => {
|
export const MARKET_PARAMS = MARKETS.filter(
|
||||||
|
(marketInfo) => !marketInfo.deprecated
|
||||||
|
).map((marketInfo) => {
|
||||||
const [coin, priceCurrency] = marketInfo.name.split("/");
|
const [coin, priceCurrency] = marketInfo.name.split("/");
|
||||||
return {
|
return {
|
||||||
address: marketInfo.address,
|
address: marketInfo.address,
|
||||||
|
|
Loading…
Reference in New Issue