use placeSpotOrder2 and add reduce only orders for perps
This commit is contained in:
parent
efe7990056
commit
f1d59d32e1
|
@ -7,6 +7,7 @@ type TooltipProps = {
|
||||||
placement?: any
|
placement?: any
|
||||||
className?: string
|
className?: string
|
||||||
children?: ReactNode
|
children?: ReactNode
|
||||||
|
delay?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
const Tooltip = ({
|
const Tooltip = ({
|
||||||
|
@ -14,6 +15,7 @@ const Tooltip = ({
|
||||||
content,
|
content,
|
||||||
className,
|
className,
|
||||||
placement = 'top',
|
placement = 'top',
|
||||||
|
delay = 0,
|
||||||
}: TooltipProps) => {
|
}: TooltipProps) => {
|
||||||
return (
|
return (
|
||||||
<Tippy
|
<Tippy
|
||||||
|
@ -22,9 +24,10 @@ const Tooltip = ({
|
||||||
appendTo={() => document.body}
|
appendTo={() => document.body}
|
||||||
maxWidth="20rem"
|
maxWidth="20rem"
|
||||||
interactive
|
interactive
|
||||||
|
delay={delay}
|
||||||
content={
|
content={
|
||||||
<div
|
<div
|
||||||
className={`rounded p-3 text-xs bg-th-bkg-3 leading-5 shadow-md text-th-fgd-3 outline-none focus:outline-none ${className}`}
|
className={`rounded p-2 text-xs bg-th-bkg-3 leading-4 shadow-md text-th-fgd-3 outline-none focus:outline-none ${className}`}
|
||||||
>
|
>
|
||||||
{content}
|
{content}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -19,6 +19,7 @@ import Big from 'big.js'
|
||||||
import MarketFee from './MarketFee'
|
import MarketFee from './MarketFee'
|
||||||
import LeverageSlider from './LeverageSlider'
|
import LeverageSlider from './LeverageSlider'
|
||||||
import Loading from './Loading'
|
import Loading from './Loading'
|
||||||
|
import Tooltip from './Tooltip'
|
||||||
|
|
||||||
const StyledRightInput = styled(Input)`
|
const StyledRightInput = styled(Input)`
|
||||||
border-left: 1px solid transparent;
|
border-left: 1px solid transparent;
|
||||||
|
@ -37,6 +38,7 @@ export default function TradeForm() {
|
||||||
const { side, baseSize, quoteSize, price, tradeType } = useMangoStore(
|
const { side, baseSize, quoteSize, price, tradeType } = useMangoStore(
|
||||||
(s) => s.tradeForm
|
(s) => s.tradeForm
|
||||||
)
|
)
|
||||||
|
const [reduceOnly, setReduceOnly] = useState(false)
|
||||||
|
|
||||||
const [postOnly, setPostOnly] = useState(false)
|
const [postOnly, setPostOnly] = useState(false)
|
||||||
const [ioc, setIoc] = useState(false)
|
const [ioc, setIoc] = useState(false)
|
||||||
|
@ -212,6 +214,12 @@ export default function TradeForm() {
|
||||||
}
|
}
|
||||||
setIoc(checked)
|
setIoc(checked)
|
||||||
}
|
}
|
||||||
|
const reduceOnChange = (checked) => {
|
||||||
|
if (checked) {
|
||||||
|
setReduceOnly(false)
|
||||||
|
}
|
||||||
|
setReduceOnly(checked)
|
||||||
|
}
|
||||||
|
|
||||||
async function onSubmit() {
|
async function onSubmit() {
|
||||||
if (!price && tradeType === 'Limit') {
|
if (!price && tradeType === 'Limit') {
|
||||||
|
@ -256,7 +264,7 @@ export default function TradeForm() {
|
||||||
const orderType = ioc ? 'ioc' : postOnly ? 'postOnly' : 'limit'
|
const orderType = ioc ? 'ioc' : postOnly ? 'postOnly' : 'limit'
|
||||||
let txid
|
let txid
|
||||||
if (market instanceof Market) {
|
if (market instanceof Market) {
|
||||||
txid = await mangoClient.placeSpotOrder(
|
txid = await mangoClient.placeSpotOrder2(
|
||||||
mangoGroup,
|
mangoGroup,
|
||||||
mangoAccount,
|
mangoAccount,
|
||||||
mangoGroup.mangoCache,
|
mangoGroup.mangoCache,
|
||||||
|
@ -277,9 +285,10 @@ export default function TradeForm() {
|
||||||
side,
|
side,
|
||||||
orderPrice,
|
orderPrice,
|
||||||
baseSize,
|
baseSize,
|
||||||
orderType,
|
tradeType === 'Market' ? 'market' : orderType,
|
||||||
0,
|
0,
|
||||||
side === 'buy' ? askInfo : bidInfo
|
side === 'buy' ? askInfo : bidInfo,
|
||||||
|
reduceOnly
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
notify({ title: 'Successfully placed trade', txid })
|
notify({ title: 'Successfully placed trade', txid })
|
||||||
|
@ -404,18 +413,47 @@ export default function TradeForm() {
|
||||||
price
|
price
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
{tradeType !== 'Market' ? (
|
<div className="flex mt-2">
|
||||||
<div className="flex mt-2">
|
{tradeType !== 'Market' ? (
|
||||||
<Switch checked={postOnly} onChange={postOnChange}>
|
<>
|
||||||
POST
|
<div className="mr-4">
|
||||||
</Switch>
|
<Tooltip
|
||||||
<div className="ml-4">
|
delay={250}
|
||||||
<Switch checked={ioc} onChange={iocOnChange}>
|
placement="left"
|
||||||
IOC
|
content="Post only orders are guaranteed to be the maker order or else it will be canceled."
|
||||||
</Switch>
|
>
|
||||||
|
<Switch checked={postOnly} onChange={postOnChange}>
|
||||||
|
POST
|
||||||
|
</Switch>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
<div className="mr-4">
|
||||||
|
<Tooltip
|
||||||
|
delay={250}
|
||||||
|
placement="left"
|
||||||
|
content="Immediate or cancel orders are guaranteed to be the taker."
|
||||||
|
>
|
||||||
|
<Switch checked={ioc} onChange={iocOnChange}>
|
||||||
|
IOC
|
||||||
|
</Switch>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
{marketConfig.kind === 'perp' ? (
|
||||||
|
<div>
|
||||||
|
<Tooltip
|
||||||
|
delay={250}
|
||||||
|
placement="left"
|
||||||
|
content="Reduce only orders will only reduce your overall position."
|
||||||
|
>
|
||||||
|
<Switch checked={reduceOnly} onChange={reduceOnChange}>
|
||||||
|
Reduce Only
|
||||||
|
</Switch>
|
||||||
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
) : null}
|
||||||
) : null}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className={`flex pt-4`}>
|
<div className={`flex pt-4`}>
|
||||||
{ipAllowed ? (
|
{ipAllowed ? (
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@blockworks-foundation/mango-client": "git+https://github.com/blockworks-foundation/mango-client-v3.git",
|
"@blockworks-foundation/mango-client": "git+https://github.com/blockworks-foundation/mango-client-v3.git#dd/marketorder",
|
||||||
"@emotion/react": "^11.1.5",
|
"@emotion/react": "^11.1.5",
|
||||||
"@emotion/styled": "^11.1.5",
|
"@emotion/styled": "^11.1.5",
|
||||||
"@headlessui/react": "^1.2.0",
|
"@headlessui/react": "^1.2.0",
|
||||||
|
|
|
@ -37,8 +37,8 @@ export const ENDPOINTS: EndpointInfo[] = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'devnet',
|
name: 'devnet',
|
||||||
// url: "https://mango.devnet.rpcpool.com",
|
// url: 'https://mango.devnet.rpcpool.com',
|
||||||
// websocket: "https://mango.devnet.rpcpool.com",
|
// websocket: 'https://mango.devnet.rpcpool.com',
|
||||||
url: 'https://api.devnet.solana.com',
|
url: 'https://api.devnet.solana.com',
|
||||||
websocket: 'https://api.devnet.solana.com',
|
websocket: 'https://api.devnet.solana.com',
|
||||||
custom: false,
|
custom: false,
|
||||||
|
@ -47,7 +47,7 @@ export const ENDPOINTS: EndpointInfo[] = [
|
||||||
|
|
||||||
type ClusterType = 'mainnet' | 'devnet'
|
type ClusterType = 'mainnet' | 'devnet'
|
||||||
|
|
||||||
const CLUSTER = (process.env.NEXT_PUBLIC_CLUSTER as ClusterType) || 'mainnet'
|
const CLUSTER = (process.env.NEXT_PUBLIC_CLUSTER as ClusterType) || 'devnet'
|
||||||
const ENDPOINT = ENDPOINTS.find((e) => e.name === CLUSTER)
|
const ENDPOINT = ENDPOINTS.find((e) => e.name === CLUSTER)
|
||||||
|
|
||||||
export const WEBSOCKET_CONNECTION = new Connection(
|
export const WEBSOCKET_CONNECTION = new Connection(
|
||||||
|
@ -55,7 +55,7 @@ export const WEBSOCKET_CONNECTION = new Connection(
|
||||||
'processed' as Commitment
|
'processed' as Commitment
|
||||||
)
|
)
|
||||||
|
|
||||||
const DEFAULT_MANGO_GROUP_NAME = process.env.NEXT_PUBLIC_GROUP || 'mainnet.1'
|
const DEFAULT_MANGO_GROUP_NAME = process.env.NEXT_PUBLIC_GROUP || 'devnet.2'
|
||||||
const DEFAULT_MANGO_GROUP_CONFIG = Config.ids().getGroup(
|
const DEFAULT_MANGO_GROUP_CONFIG = Config.ids().getGroup(
|
||||||
CLUSTER,
|
CLUSTER,
|
||||||
DEFAULT_MANGO_GROUP_NAME
|
DEFAULT_MANGO_GROUP_NAME
|
||||||
|
@ -164,10 +164,9 @@ interface MangoStore extends State {
|
||||||
|
|
||||||
const useMangoStore = create<MangoStore>((set, get) => {
|
const useMangoStore = create<MangoStore>((set, get) => {
|
||||||
const rpcUrl =
|
const rpcUrl =
|
||||||
typeof window !== 'undefined'
|
typeof window !== 'undefined' && CLUSTER === 'mainnet'
|
||||||
? JSON.parse(localStorage.getItem(NODE_URL_KEY)) || ENDPOINT.url
|
? JSON.parse(localStorage.getItem(NODE_URL_KEY)) || ENDPOINT.url
|
||||||
: ENDPOINT.url
|
: ENDPOINT.url
|
||||||
console.log('rpc url', rpcUrl, ENDPOINT.url, rpcUrl === ENDPOINT.url)
|
|
||||||
|
|
||||||
const connection = new Connection(rpcUrl, 'processed' as Commitment)
|
const connection = new Connection(rpcUrl, 'processed' as Commitment)
|
||||||
return {
|
return {
|
||||||
|
|
42
yarn.lock
42
yarn.lock
|
@ -988,9 +988,9 @@
|
||||||
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
||||||
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
||||||
|
|
||||||
"@blockworks-foundation/mango-client@git+https://github.com/blockworks-foundation/mango-client-v3.git":
|
"@blockworks-foundation/mango-client@git+https://github.com/blockworks-foundation/mango-client-v3.git#dd/marketorder":
|
||||||
version "3.0.16"
|
version "3.0.17"
|
||||||
resolved "git+https://github.com/blockworks-foundation/mango-client-v3.git#775fb41280a0920cd57a6973b99ee18b5388e558"
|
resolved "git+https://github.com/blockworks-foundation/mango-client-v3.git#32de55356e9076b1d7ec1b26574935b8734c124f"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@project-serum/serum" "0.13.55"
|
"@project-serum/serum" "0.13.55"
|
||||||
"@project-serum/sol-wallet-adapter" "^0.2.0"
|
"@project-serum/sol-wallet-adapter" "^0.2.0"
|
||||||
|
@ -1608,9 +1608,9 @@
|
||||||
tweetnacl "^1.0.0"
|
tweetnacl "^1.0.0"
|
||||||
|
|
||||||
"@solana/web3.js@^1.21.0":
|
"@solana/web3.js@^1.21.0":
|
||||||
version "1.26.0"
|
version "1.27.0"
|
||||||
resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.26.0.tgz#bdd71616ce0ff40258dfe3a8d3a401ed5658fbae"
|
resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.27.0.tgz#e8db617455a03e6cfc087fa692cdb03e722b71aa"
|
||||||
integrity sha512-XXrE8srfA3ilMvpOs6WdGOIuY8epc0sF9Tl4M6BHNnfS5pbSQ+jJJdEhwi6AzURgXWWu//242Tq347iLSQhRqQ==
|
integrity sha512-1vz503S39CgVwT3b8Y8HhDl4u7NpyoG/UtJKwlPZCYx+11q/qqcfpdbHXNSq2cu7FQma3MHa5wHILd8k1Vz2wQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@babel/runtime" "^7.12.5"
|
"@babel/runtime" "^7.12.5"
|
||||||
"@solana/buffer-layout" "^3.0.0"
|
"@solana/buffer-layout" "^3.0.0"
|
||||||
|
@ -1894,14 +1894,14 @@
|
||||||
integrity sha512-/BHF5HAx3em7/KkzVKm3LrsD6HZAXuXO1AJZQ3cRRBZj4oHZDviWPYu0aEplAqDFNHZPW6d3G7KN+ONcCCC7pw==
|
integrity sha512-/BHF5HAx3em7/KkzVKm3LrsD6HZAXuXO1AJZQ3cRRBZj4oHZDviWPYu0aEplAqDFNHZPW6d3G7KN+ONcCCC7pw==
|
||||||
|
|
||||||
"@types/node@*":
|
"@types/node@*":
|
||||||
version "16.9.0"
|
version "16.9.1"
|
||||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.9.0.tgz#d9512fe037472dcb58931ce19f837348db828a62"
|
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.9.1.tgz#0611b37db4246c937feef529ddcc018cf8e35708"
|
||||||
integrity sha512-nmP+VR4oT0pJUPFbKE4SXj3Yb4Q/kz3M9dSAO1GGMebRKWHQxLfDNmU/yh3xxCJha3N60nQ/JwXWwOE/ZSEVag==
|
integrity sha512-QpLcX9ZSsq3YYUUnD3nFDY8H7wctAhQj/TFKL8Ya8v5fMm3CFXxo8zStsLAl780ltoYoo1WvKUVGBQK+1ifr7g==
|
||||||
|
|
||||||
"@types/node@^12.12.54":
|
"@types/node@^12.12.54":
|
||||||
version "12.20.24"
|
version "12.20.25"
|
||||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.24.tgz#c37ac69cb2948afb4cef95f424fa0037971a9a5c"
|
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.25.tgz#882bea2ca0d2ec22126b92b4dd2dc24b35a07469"
|
||||||
integrity sha512-yxDeaQIAJlMav7fH5AQqPH1u8YIuhYJXYBzxaQ4PifsU0GDO38MSdmEDeRlIxrKbC6NbEaaEHDanWb+y30U8SQ==
|
integrity sha512-hcTWqk7DR/HrN9Xe7AlJwuCaL13Vcd9/g/T54YrJz4Q3ESM5mr33YCzW2bOfzSIc3aZMeGBvbLGvgN6mIJ0I5Q==
|
||||||
|
|
||||||
"@types/node@^14.14.25":
|
"@types/node@^14.14.25":
|
||||||
version "14.17.3"
|
version "14.17.3"
|
||||||
|
@ -2166,9 +2166,9 @@ ansi-escapes@^4.2.1, ansi-escapes@^4.3.0, ansi-escapes@^4.3.1:
|
||||||
type-fest "^0.21.3"
|
type-fest "^0.21.3"
|
||||||
|
|
||||||
ansi-regex@^5.0.0:
|
ansi-regex@^5.0.0:
|
||||||
version "5.0.0"
|
version "5.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75"
|
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
|
||||||
integrity sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==
|
integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==
|
||||||
|
|
||||||
ansi-styles@^3.2.1:
|
ansi-styles@^3.2.1:
|
||||||
version "3.2.1"
|
version "3.2.1"
|
||||||
|
@ -4256,9 +4256,9 @@ flatten@^1.0.2:
|
||||||
integrity sha512-dVsPA/UwQ8+2uoFe5GHtiBMu48dWLTdsuEd7CKGlZlD78r1TTWBvDuFaFGKCo/ZfEr95Uk56vZoX86OsHkUeIg==
|
integrity sha512-dVsPA/UwQ8+2uoFe5GHtiBMu48dWLTdsuEd7CKGlZlD78r1TTWBvDuFaFGKCo/ZfEr95Uk56vZoX86OsHkUeIg==
|
||||||
|
|
||||||
follow-redirects@^1.14.0:
|
follow-redirects@^1.14.0:
|
||||||
version "1.14.3"
|
version "1.14.4"
|
||||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.3.tgz#6ada78118d8d24caee595595accdc0ac6abd022e"
|
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.4.tgz#838fdf48a8bbdd79e52ee51fb1c94e3ed98b9379"
|
||||||
integrity sha512-3MkHxknWMUtb23apkgz/83fDoe+y+qr0TdgacGIA7bew+QLBo3vdgEN2xEsuXNivpFy4CyDhBBZnNZOtalmenw==
|
integrity sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g==
|
||||||
|
|
||||||
for-in@^1.0.2:
|
for-in@^1.0.2:
|
||||||
version "1.0.2"
|
version "1.0.2"
|
||||||
|
@ -6225,9 +6225,9 @@ node-fetch@^2.6.1:
|
||||||
integrity sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA==
|
integrity sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA==
|
||||||
|
|
||||||
node-gyp-build@^4.2.0:
|
node-gyp-build@^4.2.0:
|
||||||
version "4.2.3"
|
version "4.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.2.3.tgz#ce6277f853835f718829efb47db20f3e4d9c4739"
|
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.3.0.tgz#9f256b03e5826150be39c764bf51e993946d71a3"
|
||||||
integrity sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg==
|
integrity sha512-iWjXZvmboq0ja1pUGULQBexmxq8CV4xBhX7VDOTbL7ZR4FOowwY/VOtRxBN/yKxmdGoIp4j5ysNT4u3S2pDQ3Q==
|
||||||
|
|
||||||
node-html-parser@1.4.9:
|
node-html-parser@1.4.9:
|
||||||
version "1.4.9"
|
version "1.4.9"
|
||||||
|
|
Loading…
Reference in New Issue