fix key loading
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
18b0ff0ac0
commit
4a2f0e26da
|
@ -1,7 +1,7 @@
|
||||||
import {
|
import {
|
||||||
getMarketByPublicKey,
|
getMarketByPublicKey,
|
||||||
PerpMarket,
|
PerpMarket,
|
||||||
ZERO_BN
|
ZERO_BN,
|
||||||
} from "@blockworks-foundation/mango-client";
|
} from "@blockworks-foundation/mango-client";
|
||||||
import BN from "bn.js";
|
import BN from "bn.js";
|
||||||
import Controller from "controller.interface";
|
import Controller from "controller.interface";
|
||||||
|
@ -122,7 +122,8 @@ class AccountController implements Controller {
|
||||||
openSize: undefined,
|
openSize: undefined,
|
||||||
realizedPnl: undefined,
|
realizedPnl: undefined,
|
||||||
recentAverageOpenPrice: undefined,
|
recentAverageOpenPrice: undefined,
|
||||||
recentBreakEvenPrice: breakEvenPrice!=null?breakEvenPrice.toNumber():null,
|
recentBreakEvenPrice:
|
||||||
|
breakEvenPrice != null ? breakEvenPrice.toNumber() : null,
|
||||||
recentPnl: undefined,
|
recentPnl: undefined,
|
||||||
shortOrderSize: undefined,
|
shortOrderSize: undefined,
|
||||||
side: perpAccount.basePosition.gt(ZERO_BN) ? "long" : "short",
|
side: perpAccount.basePosition.gt(ZERO_BN) ? "long" : "short",
|
||||||
|
|
|
@ -15,8 +15,6 @@ class App {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.app = express();
|
this.app = express();
|
||||||
MangoSimpleClient.create().then((mangoSimpleClient) => {
|
MangoSimpleClient.create().then((mangoSimpleClient) => {
|
||||||
|
|
||||||
|
|
||||||
this.mangoSimpleClient = mangoSimpleClient;
|
this.mangoSimpleClient = mangoSimpleClient;
|
||||||
|
|
||||||
this.app.use(bodyParser.json({ limit: "50mb" }));
|
this.app.use(bodyParser.json({ limit: "50mb" }));
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
export interface BadRequestError {
|
export interface BadRequestError {
|
||||||
value: string;
|
value: string;
|
||||||
msg: string;
|
msg: string;
|
||||||
param: string;
|
param: string;
|
||||||
location: string;
|
location: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BadRequestErrorCustom {
|
export interface BadRequestErrorCustom {
|
||||||
msg: string;
|
msg: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,14 @@ import {
|
||||||
getMarketByBaseSymbolAndKind,
|
getMarketByBaseSymbolAndKind,
|
||||||
getMarketByPublicKey,
|
getMarketByPublicKey,
|
||||||
getMultipleAccounts,
|
getMultipleAccounts,
|
||||||
GroupConfig, MangoAccount,
|
GroupConfig,
|
||||||
|
MangoAccount,
|
||||||
MangoClient,
|
MangoClient,
|
||||||
MangoGroup,
|
MangoGroup,
|
||||||
MarketConfig,
|
MarketConfig,
|
||||||
PerpMarket,
|
PerpMarket,
|
||||||
PerpMarketLayout,
|
PerpMarketLayout,
|
||||||
PerpOrder
|
PerpOrder,
|
||||||
} from "@blockworks-foundation/mango-client";
|
} from "@blockworks-foundation/mango-client";
|
||||||
import { Market, Orderbook } from "@project-serum/serum";
|
import { Market, Orderbook } from "@project-serum/serum";
|
||||||
import { Order } from "@project-serum/serum/lib/market";
|
import { Order } from "@project-serum/serum/lib/market";
|
||||||
|
@ -21,7 +22,7 @@ import {
|
||||||
AccountInfo,
|
AccountInfo,
|
||||||
Commitment,
|
Commitment,
|
||||||
Connection,
|
Connection,
|
||||||
PublicKey
|
PublicKey,
|
||||||
} from "@solana/web3.js";
|
} from "@solana/web3.js";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
|
@ -92,11 +93,11 @@ class MangoSimpleClient {
|
||||||
logger.info(`- loading cache`);
|
logger.info(`- loading cache`);
|
||||||
await mangoGroup.loadCache(connection);
|
await mangoGroup.loadCache(connection);
|
||||||
|
|
||||||
|
const privateKeyPath =
|
||||||
|
process.env.PRIVATE_KEY_PATH || os.homedir() + "/.config/solana/id.json";
|
||||||
|
logger.info(`- loading private key at location ${privateKeyPath}`);
|
||||||
const owner = new Account(
|
const owner = new Account(
|
||||||
JSON.parse(
|
JSON.parse(fs.readFileSync(privateKeyPath, "utf-8"))
|
||||||
process.env.KEYPAIR ||
|
|
||||||
fs.readFileSync(os.homedir() + "/.config/solana/id.json", "utf-8")
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
logger.info(`- fetching mango accounts for ${owner.publicKey.toBase58()}`);
|
logger.info(`- fetching mango accounts for ${owner.publicKey.toBase58()}`);
|
||||||
|
|
|
@ -2,7 +2,7 @@ import {
|
||||||
getAllMarkets,
|
getAllMarkets,
|
||||||
getTokenBySymbol,
|
getTokenBySymbol,
|
||||||
MarketConfig,
|
MarketConfig,
|
||||||
PerpMarket
|
PerpMarket,
|
||||||
} from "@blockworks-foundation/mango-client";
|
} from "@blockworks-foundation/mango-client";
|
||||||
import { Market } from "@project-serum/serum";
|
import { Market } from "@project-serum/serum";
|
||||||
import Big from "big.js";
|
import Big from "big.js";
|
||||||
|
@ -77,7 +77,9 @@ class MarketsController implements Controller {
|
||||||
) => {
|
) => {
|
||||||
const errors = validationResult(request);
|
const errors = validationResult(request);
|
||||||
if (!errors.isEmpty()) {
|
if (!errors.isEmpty()) {
|
||||||
return response.status(400).json({ errors: errors.array() as BadRequestError[] });
|
return response
|
||||||
|
.status(400)
|
||||||
|
.json({ errors: errors.array() as BadRequestError[] });
|
||||||
}
|
}
|
||||||
|
|
||||||
const marketName = request.params.market_name;
|
const marketName = request.params.market_name;
|
||||||
|
@ -222,7 +224,9 @@ class MarketsController implements Controller {
|
||||||
) => {
|
) => {
|
||||||
const errors = validationResult(request);
|
const errors = validationResult(request);
|
||||||
if (!errors.isEmpty()) {
|
if (!errors.isEmpty()) {
|
||||||
return response.status(400).json({ errors: errors.array() as BadRequestError[] });
|
return response
|
||||||
|
.status(400)
|
||||||
|
.json({ errors: errors.array() as BadRequestError[] });
|
||||||
}
|
}
|
||||||
|
|
||||||
const marketName = request.params.market_name;
|
const marketName = request.params.market_name;
|
||||||
|
@ -261,7 +265,9 @@ class MarketsController implements Controller {
|
||||||
) => {
|
) => {
|
||||||
const errors = validationResult(request);
|
const errors = validationResult(request);
|
||||||
if (!errors.isEmpty()) {
|
if (!errors.isEmpty()) {
|
||||||
return response.status(400).json({ errors: errors.array() as BadRequestError[] });
|
return response
|
||||||
|
.status(400)
|
||||||
|
.json({ errors: errors.array() as BadRequestError[] });
|
||||||
}
|
}
|
||||||
|
|
||||||
const allMarketConfigs = getAllMarkets(
|
const allMarketConfigs = getAllMarkets(
|
||||||
|
@ -280,16 +286,17 @@ class MarketsController implements Controller {
|
||||||
if ("s" in parsedTradesResponse && parsedTradesResponse["s"] === "error") {
|
if ("s" in parsedTradesResponse && parsedTradesResponse["s"] === "error") {
|
||||||
tradeDtos = [];
|
tradeDtos = [];
|
||||||
} else {
|
} else {
|
||||||
tradeDtos = parsedTradesResponse["data"].map((trade: any) => {
|
tradeDtos = parsedTradesResponse["data"].map((trade: any) => {
|
||||||
return {
|
return {
|
||||||
id: trade["orderId"],
|
id: trade["orderId"],
|
||||||
liquidation: undefined,
|
liquidation: undefined,
|
||||||
price: trade["price"],
|
price: trade["price"],
|
||||||
side: trade["side"],
|
side: trade["side"],
|
||||||
size: trade["size"],
|
size: trade["size"],
|
||||||
time: new Date(trade["time"]),
|
time: new Date(trade["time"]),
|
||||||
} as TradeDto;
|
} as TradeDto;
|
||||||
})};
|
});
|
||||||
|
}
|
||||||
|
|
||||||
response.send({ success: true, result: tradeDtos } as TradesDto);
|
response.send({ success: true, result: tradeDtos } as TradesDto);
|
||||||
};
|
};
|
||||||
|
@ -301,7 +308,10 @@ class MarketsController implements Controller {
|
||||||
) => {
|
) => {
|
||||||
const errors = validationResult(request);
|
const errors = validationResult(request);
|
||||||
if (!errors.isEmpty()) {
|
if (!errors.isEmpty()) {
|
||||||
return response.status(400).json({ errors: errors.array() as BadRequestError[] }); }
|
return response
|
||||||
|
.status(400)
|
||||||
|
.json({ errors: errors.array() as BadRequestError[] });
|
||||||
|
}
|
||||||
|
|
||||||
const marketName = request.params.market_name;
|
const marketName = request.params.market_name;
|
||||||
const resolution = String(request.query.resolution);
|
const resolution = String(request.query.resolution);
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
|
import { logger } from "./utils";
|
||||||
import App from "./app";
|
import App from "./app";
|
||||||
|
|
||||||
const app = new App();
|
const app = new App();
|
||||||
|
|
||||||
app.listen();
|
app.listen();
|
||||||
|
|
||||||
|
// todo add a handler for ctrl+c from docker
|
|
@ -1,7 +1,9 @@
|
||||||
import {
|
import {
|
||||||
getTokenBySymbol, I80F48, nativeI80F48ToUi,
|
getTokenBySymbol,
|
||||||
|
I80F48,
|
||||||
|
nativeI80F48ToUi,
|
||||||
nativeToUi,
|
nativeToUi,
|
||||||
QUOTE_INDEX
|
QUOTE_INDEX,
|
||||||
} from "@blockworks-foundation/mango-client";
|
} from "@blockworks-foundation/mango-client";
|
||||||
import { OpenOrders } from "@project-serum/serum";
|
import { OpenOrders } from "@project-serum/serum";
|
||||||
import Controller from "controller.interface";
|
import Controller from "controller.interface";
|
||||||
|
|
Loading…
Reference in New Issue