From f59267af0ad060fd2fdcc0aa4098d1ea18af0cc6 Mon Sep 17 00:00:00 2001 From: Mariusz Klochowicz Date: Wed, 6 Oct 2021 17:15:00 +1030 Subject: [PATCH 1/2] Allow auto-refreshing price suggestions in the maker If the switch is enabled, the maker gets price suggestions based on the current ask price on Bitmex + 3% spread. Auto-refresh turns off whenever user modifies the field manually, and can be re-enabled later if desired. Fixes #214 --- frontend/src/MakerApp.tsx | 46 ++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/frontend/src/MakerApp.tsx b/frontend/src/MakerApp.tsx index 40dd64e..68e0c9f 100644 --- a/frontend/src/MakerApp.tsx +++ b/frontend/src/MakerApp.tsx @@ -1,4 +1,3 @@ -import { RepeatIcon } from "@chakra-ui/icons"; import { Box, Button, @@ -7,7 +6,7 @@ import { Grid, GridItem, HStack, - IconButton, + Switch, Tab, TabList, TabPanel, @@ -17,7 +16,7 @@ import { useToast, VStack, } from "@chakra-ui/react"; -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; import { useAsync } from "react-async"; import { useEventSource } from "react-sse-hooks"; import { CfdTable } from "./components/cfdtables/CfdTable"; @@ -44,7 +43,13 @@ export default function App() { let [minQuantity, setMinQuantity] = useState("10"); let [maxQuantity, setMaxQuantity] = useState("100"); let [orderPrice, setOrderPrice] = useState("0"); - let [hasEnteredPrice, setHasEnteredPrice] = useState(false); + let [autoRefresh, setAutoRefresh] = useState(true); + + useEffect(() => { + if (autoRefresh && priceInfo) { + setOrderPrice((priceInfo.ask * SPREAD).toFixed(2).toString()); + } + }, [priceInfo, autoRefresh]); let { run: makeNewCfdSellOrder, isLoading: isCreatingNewCfdOrder } = useAsync({ deferFn: async ([payload]: any[]) => { @@ -107,19 +112,18 @@ export default function App() { { setOrderPrice(parse(valueString)); - setHasEnteredPrice(true); - }} - value={priceToDisplay(hasEnteredPrice, orderPrice, priceInfo)} - /> - } - onClick={() => { - if (priceInfo) { - setOrderPrice((priceInfo.ask * SPREAD).toString()); - } + setAutoRefresh(false); }} + value={format(orderPrice)} /> + + setAutoRefresh(!autoRefresh)} + /> + Auto-refresh + Leverage: @@ -187,18 +191,6 @@ export default function App() { ); } -function priceToDisplay(hasEnteredPrice: boolean, orderPrice: string, priceInfo: PriceInfo | null) { - if (!priceInfo) { - return format("0"); - } - - if (!hasEnteredPrice) { - return format((priceInfo.ask * SPREAD).toString()); - } - - return format(orderPrice); -} - function format(val: any) { return `$` + val; } From 9c46ea4046f0aebcc79ff21fe919db2c3cc411ce Mon Sep 17 00:00:00 2001 From: Mariusz Klochowicz Date: Wed, 6 Oct 2021 14:37:26 +1030 Subject: [PATCH 2/2] Disable posting new offers in the maker when there is no order price --- frontend/src/MakerApp.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/MakerApp.tsx b/frontend/src/MakerApp.tsx index 68e0c9f..fe008e5 100644 --- a/frontend/src/MakerApp.tsx +++ b/frontend/src/MakerApp.tsx @@ -139,7 +139,7 @@ export default function App() {