Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mmintel committed Sep 21, 2022
1 parent 6d2c599 commit f64ec39
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
build.zip
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "chrome-bybit-extension",
"description": "A chrome extension to help with position sizing according to risk and reward. Takes your balance, stoploss, margin and risk, returns a the right leverage.",
"version": "0.1.0",
"private": true,
"homepage": ".",
Expand Down
Binary file added public/logo128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"short_name": "Bybit R:R",
"name": "Bybit Risk:Reward Calculator",
"description": "A chrome extension to help with position sizing according to risk and reward.",
"version": "1.0",
"manifest_version": 3,
"icons": {
Expand All @@ -12,7 +13,7 @@
"default_popup": "index.html",
"default_title": "Bybit Risk:Reward Calculator"
},
"permissions": ["activeTab", "storage"],
"permissions": ["https://*.bybit.com/*", "storage"],
"content_scripts": [
{
"matches": ["https://*.bybit.com/*"],
Expand Down
26 changes: 24 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum PersistableSetting {
MARGIN,
STOPLOSS,
RISK,
DECIMALS,
}

function App() {
Expand All @@ -33,6 +34,7 @@ function App() {
const [stoplossStored, setStoplossStored] = useState(true);
const [riskStored, setRiskStored] = useState(true);
const [decimals, setDecimals] = useState(2);
const [decimalsStored, setDecimalsStored] = useState(true);

useEffect(() => {
if (stoplossRelative && marketPrice) {
Expand Down Expand Up @@ -168,6 +170,11 @@ function App() {
if (risk) {
setRiskRelative(risk);
}

const decimals = await getSetting(PersistableSetting.DECIMALS);
if (decimals) {
setDecimals(decimals);
}
})();
}, []);

Expand All @@ -193,10 +200,25 @@ function App() {
id="decimals"
label="Decimals"
type="number"
append={<DecimalsIcon className="w-6 h-6" />}
value={decimals}
onChange={(e) => setDecimals(Number(e.target.value))}
onChange={(e) => {
setDecimals(Number(e.target.value));
setDecimalsStored(false);
}}
showLabel
append={
!decimalsStored ? (
<SaveIcon
className="w-6 h-6 cursor-pointer"
onClick={() => {
storeSetting(PersistableSetting.DECIMALS, decimals);
setDecimalsStored(true);
}}
/>
) : (
<DecimalsIcon className="w-6 h-6" />
)
}
/>
</div>
<Input
Expand Down
9 changes: 3 additions & 6 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ const messagesFromReactAppListener = (msg: MessageRequest, sender: chrome.runtim
const marginContent = $('.by-popover__el:contains("Order by")').closest('.oc__row-bottom--12').find('.by-input__inner').val()
const margin = parseVal(String(marginContent));

console.log(marginContent, margin)

const response: MessageResponse[MessageType.GET_DOM] = {
equity,
marketPrice,
Expand All @@ -43,10 +41,9 @@ const messagesFromReactAppListener = (msg: MessageRequest, sender: chrome.runtim

sendResponse<MessageResponse[MessageType.SET_TRADE_TYPE]>({ success: true })
} else if (msg.type === MessageType.SET_STOPLOSS) {
const stoploss = $('.tpsl-modal-item__title:contains("Stop Loss")').closest('.oc__row-bottom--12').find('.profit-input .by-input__inner');
console.log(stoploss, msg.payload.stoploss)
stoploss.val(Number(msg.payload.stoploss))
// stoploss.trigger($.Event('keypress', { keyCode: 49 }))
// TODO Bybit reverts changes to the input.value, need to find another way.
// const stoploss = $('.tpsl-modal-item__title:contains("Stop Loss")').closest('.oc__row-bottom--12').find('.profit-input .by-input__inner');
// stoploss.val(Number(msg.payload.stoploss))
}
}

Expand Down

0 comments on commit f64ec39

Please sign in to comment.