fix key loading

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2021-09-24 13:56:27 +02:00
parent 18b0ff0ac0
commit 4a2f0e26da
7 changed files with 48 additions and 33 deletions

View File

@ -1,7 +1,7 @@
import {
getMarketByPublicKey,
PerpMarket,
ZERO_BN
ZERO_BN,
} from "@blockworks-foundation/mango-client";
import BN from "bn.js";
import Controller from "controller.interface";
@ -122,7 +122,8 @@ class AccountController implements Controller {
openSize: undefined,
realizedPnl: undefined,
recentAverageOpenPrice: undefined,
recentBreakEvenPrice: breakEvenPrice!=null?breakEvenPrice.toNumber():null,
recentBreakEvenPrice:
breakEvenPrice != null ? breakEvenPrice.toNumber() : null,
recentPnl: undefined,
shortOrderSize: undefined,
side: perpAccount.basePosition.gt(ZERO_BN) ? "long" : "short",

View File

@ -15,8 +15,6 @@ class App {
constructor() {
this.app = express();
MangoSimpleClient.create().then((mangoSimpleClient) => {
this.mangoSimpleClient = mangoSimpleClient;
this.app.use(bodyParser.json({ limit: "50mb" }));

View File

@ -1,10 +1,10 @@
export interface BadRequestError {
value: string;
msg: string;
param: string;
location: string;
value: string;
msg: string;
param: string;
location: string;
}
export interface BadRequestErrorCustom {
msg: string;
msg: string;
}

View File

@ -6,13 +6,14 @@ import {
getMarketByBaseSymbolAndKind,
getMarketByPublicKey,
getMultipleAccounts,
GroupConfig, MangoAccount,
GroupConfig,
MangoAccount,
MangoClient,
MangoGroup,
MarketConfig,
PerpMarket,
PerpMarketLayout,
PerpOrder
PerpOrder,
} from "@blockworks-foundation/mango-client";
import { Market, Orderbook } from "@project-serum/serum";
import { Order } from "@project-serum/serum/lib/market";
@ -21,7 +22,7 @@ import {
AccountInfo,
Commitment,
Connection,
PublicKey
PublicKey,
} from "@solana/web3.js";
import fs from "fs";
import fetch from "node-fetch";
@ -92,11 +93,11 @@ class MangoSimpleClient {
logger.info(`- loading cache`);
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(
JSON.parse(
process.env.KEYPAIR ||
fs.readFileSync(os.homedir() + "/.config/solana/id.json", "utf-8")
)
JSON.parse(fs.readFileSync(privateKeyPath, "utf-8"))
);
logger.info(`- fetching mango accounts for ${owner.publicKey.toBase58()}`);

View File

@ -2,7 +2,7 @@ import {
getAllMarkets,
getTokenBySymbol,
MarketConfig,
PerpMarket
PerpMarket,
} from "@blockworks-foundation/mango-client";
import { Market } from "@project-serum/serum";
import Big from "big.js";
@ -77,7 +77,9 @@ class MarketsController implements Controller {
) => {
const errors = validationResult(request);
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;
@ -222,7 +224,9 @@ class MarketsController implements Controller {
) => {
const errors = validationResult(request);
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;
@ -261,7 +265,9 @@ class MarketsController implements Controller {
) => {
const errors = validationResult(request);
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(
@ -280,16 +286,17 @@ class MarketsController implements Controller {
if ("s" in parsedTradesResponse && parsedTradesResponse["s"] === "error") {
tradeDtos = [];
} else {
tradeDtos = parsedTradesResponse["data"].map((trade: any) => {
return {
id: trade["orderId"],
liquidation: undefined,
price: trade["price"],
side: trade["side"],
size: trade["size"],
time: new Date(trade["time"]),
} as TradeDto;
})};
tradeDtos = parsedTradesResponse["data"].map((trade: any) => {
return {
id: trade["orderId"],
liquidation: undefined,
price: trade["price"],
side: trade["side"],
size: trade["size"],
time: new Date(trade["time"]),
} as TradeDto;
});
}
response.send({ success: true, result: tradeDtos } as TradesDto);
};
@ -301,7 +308,10 @@ class MarketsController implements Controller {
) => {
const errors = validationResult(request);
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 resolution = String(request.query.resolution);

View File

@ -1,5 +1,8 @@
import { logger } from "./utils";
import App from "./app";
const app = new App();
app.listen();
// todo add a handler for ctrl+c from docker

View File

@ -1,7 +1,9 @@
import {
getTokenBySymbol, I80F48, nativeI80F48ToUi,
getTokenBySymbol,
I80F48,
nativeI80F48ToUi,
nativeToUi,
QUOTE_INDEX
QUOTE_INDEX,
} from "@blockworks-foundation/mango-client";
import { OpenOrders } from "@project-serum/serum";
import Controller from "controller.interface";