Cache market accounts for trading (#55)
* Cache accounts for longer and warm up the cache * Prettier
This commit is contained in:
parent
5fa2b521cc
commit
cdcc8c6f5c
|
@ -19,7 +19,7 @@ import {
|
||||||
} from '../utils/utils';
|
} from '../utils/utils';
|
||||||
import { useSendConnection } from '../utils/connection';
|
import { useSendConnection } from '../utils/connection';
|
||||||
import FloatingElement from './layout/FloatingElement';
|
import FloatingElement from './layout/FloatingElement';
|
||||||
import { placeOrder } from '../utils/send';
|
import { getUnixTs, placeOrder } from '../utils/send';
|
||||||
import { SwitchChangeEventHandler } from 'antd/es/switch';
|
import { SwitchChangeEventHandler } from 'antd/es/switch';
|
||||||
import { refreshCache } from '../utils/fetch-loop';
|
import { refreshCache } from '../utils/fetch-loop';
|
||||||
import tuple from 'immutable-tuple';
|
import tuple from 'immutable-tuple';
|
||||||
|
@ -98,6 +98,31 @@ export default function TradeForm({
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [price, baseSize]);
|
}, [price, baseSize]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const warmUpCache = async () => {
|
||||||
|
if (!wallet || !wallet.publicKey || !market) {
|
||||||
|
console.log(`Skipping refreshing accounts`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const startTime = getUnixTs();
|
||||||
|
console.log(`Refreshing accounts for ${market.address}`);
|
||||||
|
await market.findOpenOrdersAccountsForOwner(
|
||||||
|
sendConnection,
|
||||||
|
wallet.publicKey,
|
||||||
|
);
|
||||||
|
await market.findBestFeeDiscountKey(sendConnection, wallet.publicKey);
|
||||||
|
const endTime = getUnixTs();
|
||||||
|
console.log(
|
||||||
|
`Finished refreshing accounts for ${market.address} after ${
|
||||||
|
endTime - startTime
|
||||||
|
}`,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
warmUpCache();
|
||||||
|
const id = setInterval(warmUpCache, 30_000);
|
||||||
|
return () => clearInterval(id);
|
||||||
|
}, [market, sendConnection, wallet, wallet.publicKey]);
|
||||||
|
|
||||||
const onSetBaseSize = (baseSize: number | undefined) => {
|
const onSetBaseSize = (baseSize: number | undefined) => {
|
||||||
setBaseSize(baseSize);
|
setBaseSize(baseSize);
|
||||||
if (!baseSize) {
|
if (!baseSize) {
|
||||||
|
|
|
@ -442,15 +442,18 @@ export async function placeOrder({
|
||||||
|
|
||||||
const matchOrderstransaction = market.makeMatchOrdersTransaction(5);
|
const matchOrderstransaction = market.makeMatchOrdersTransaction(5);
|
||||||
transaction.add(matchOrderstransaction);
|
transaction.add(matchOrderstransaction);
|
||||||
|
const startTime = getUnixTs();
|
||||||
let {
|
let {
|
||||||
transaction: placeOrderTx,
|
transaction: placeOrderTx,
|
||||||
signers: placeOrderSigners,
|
signers: placeOrderSigners,
|
||||||
} = await market.makePlaceOrderTransaction(
|
} = await market.makePlaceOrderTransaction(
|
||||||
connection,
|
connection,
|
||||||
params,
|
params,
|
||||||
10_000,
|
120_000,
|
||||||
10_000,
|
120_000,
|
||||||
);
|
);
|
||||||
|
const endTime = getUnixTs();
|
||||||
|
console.log(`Creating order transaction took ${endTime - startTime}`);
|
||||||
transaction.add(placeOrderTx);
|
transaction.add(placeOrderTx);
|
||||||
transaction.add(market.makeMatchOrdersTransaction(5));
|
transaction.add(market.makeMatchOrdersTransaction(5));
|
||||||
signers.push(...placeOrderSigners);
|
signers.push(...placeOrderSigners);
|
||||||
|
@ -614,7 +617,7 @@ export async function listMarket({
|
||||||
return market.publicKey;
|
return market.publicKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getUnixTs = () => {
|
export const getUnixTs = () => {
|
||||||
return new Date().getTime() / 1000;
|
return new Date().getTime() / 1000;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue