-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add buys and sells as marks on tv chart #927
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
.toNumber(); | ||
} | ||
|
||
function averageFillPrice(fills: SubaccountFills) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to consolidate this method with logic from this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
'1': timeUnits.second, | ||
'5': 5 * timeUnits.minute, | ||
'15': 15 * timeUnits.minute, | ||
'30': 30 * timeUnits.minute, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, unrelated to this PR specifically, I wonder if it'd be better to convert CandleResolution
, RESOLUTION_MAP
, and RESOLUTION_CHART_CONFIGS
to functions where we swtich case on the keys (that we could convert to an enum) just to make sure we catch all the cases. But honestly I don't imagine this code will change too much so just a light consider
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i like all of these as enums! nice way to get free typing so people don't put in something crazy (unless resolutionStrings already gives us that? that type has a few layers of abstraction to it so it's not immediately clear what it refers to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh yeah, there's actually a way we can do that with just typescript by converting the library's ResolutionString
(which is unfort just a generic string type) to an enum with the same values and changing the type of these maps. for example if you do:
enum InterfaceResolutionString {
ONE_MINUTE = '1',
FIVE_MINUTES = '5',
FIFTEEN_MINUTES = '15',
THIRTY_MINUTES = '30',
ONE_HOUR = '60',
FOUR_HOURS = '240',
ONE_DAY = '1D',
}
/**
* @description ResolutionStrings used with TradingView's charting library mapped to time interval per candle in ms
*/
export const RESOLUTION_TO_INTERVAL_MS: { [resolution in InterfaceResolutionString]: number } = {
'1': timeUnits.second,
'5': 5 * timeUnits.minute,
'15': 15 * timeUnits.minute,
'30': 30 * timeUnits.minute,
'60': timeUnits.hour,
'240': 4 * timeUnits.hour,
// '1D': timeUnits.day,
};
you'll see that this gives a typescript error because the key 1D
is missing. we can address this separately if we'd like though :P
we can alternatively also combine all three maps into one map, so something like
type ResolutionConfig = { candleResolution: CandleResolution, intervalMs: number, defaultRange: number }
export const RESOLUTION_MAP: { [resolution: ResolutionString]: ResolutionConfig } = {
'1': { candleResolution: CandleResolution.ONE_MINUTE, intervalMs: timeUnits.second, defaultRange: timeUnits.hour },
...
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeahhh that's very much in line with what i was envisioning. i dont think either have to be done in this PR but good to keep in mind for a cleanup task 👍
} else { | ||
orderLineToggle?.classList?.remove('order-lines-active'); | ||
orderLineToggle?.classList?.remove('toggle-active'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
orderbookCandlesToggleRef.current.setAttribute('title', ohlcBody as string); | ||
} | ||
if (buySellMarksToggleRef) { | ||
buySellMarksToggleRef.current = tvWidgetRef.current.createButton(); | ||
buySellMarksToggleRef.current.innerHTML = `<span>Buys/Sells</span> <div class="toggle"></div>`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we localize Buys/Sells
? i.e. like ORDER_LINES does it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OMG yes i forgot! i even added it to v4-localization already 😂
buySellMarksToggleRef.current.innerHTML = `<span>Buys/Sells</span> <div class="toggle"></div>`; | ||
buySellMarksToggleRef.current.setAttribute( | ||
'title', | ||
'Display historic buys and sells' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
localize?
const timestampInSeconds = getBarTime(1716091200000, 1723573418524, '1D' as ResolutionString); | ||
expect(timestampInSeconds).toBe(1723521600); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yessss 🔥
tvWidget, | ||
isChartReady, | ||
currentMarketFills, | ||
theme.positive, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the theme.positive
dependency for display pref changes? if so, maybe we update it to theme
(because I imagine the red shades and green shades can also be diff for diff themes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oo yes!
@@ -119,7 +126,7 @@ export const useTradingView = ({ | |||
orderLineToggleRef.current = tvWidgetRef.current.createButton(); | |||
orderLineToggleRef.current.innerHTML = `<span>${stringGetter({ | |||
key: STRING_KEYS.ORDER_LINES, | |||
})}</span> <div class="displayOrdersButton-toggle"></div>`; | |||
})}</span> <div class="toggle"></div>`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I wonder if it's worth factoring out toggleHtml()
helper
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think as a followup im going to investigate just combining a lot of the logic here for the three settings that we have :P so combining the html here can be part of that!
time: getBarTime(barStartMs, fill.createdAtMilliseconds, resolution) ?? 0, | ||
minSize: 16, | ||
text, | ||
labelFontColor: 'white', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok unfort theres no exposed way for us to change the border color until we upgrade the library but i can add that to the TODO!
will update the text color based on theme tho :D
@@ -0,0 +1,26 @@ | |||
import { ResolutionString } from 'public/tradingview/charting_library'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love the tests!
i have a preference for test file names matching the file they are testing, to prevent overlap, duplication, or gaps in testing.
i'd recommend creating a __test__
folder in the lib/tradingView/dydxfeed
path, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yesss for sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work! have some q's and thoughts but nothing major and it looks like you've already gotten a stamp :)
@@ -140,3 +142,13 @@ export const getHydratedTradingData = < | |||
|
|||
export const getTradeType = (orderType: string) => | |||
TRADE_TYPES[orderType as KotlinIrEnumValues<typeof AbacusOrderType>]; | |||
|
|||
export const getAverageFillPrice = (fills: SubaccountFills) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a quick test for this?
@@ -96,6 +116,41 @@ export const getDydxDatafeed = ( | |||
setTimeout(() => onSymbolResolvedCallback(symbolInfo), 0); | |||
}, | |||
|
|||
getMarks: async ( | |||
symbolInfo: LibrarySymbolInfo, | |||
from: number, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we rename these fromSeconds
and toSeconds
or some other name that describes denomination
.toNumber(); | ||
} | ||
|
||
export const getMarkForOrderFills = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[q] i noticed we tested getBarTime but i don't see a test for getMarkForOrderFills in the spec file. is this because the overhead to create all the necessary fixtures is too high?
if so, could we make a ticket + comment it in code as a TODO. If we find that there's a lot of instances where we're unable to test due to lack of features it may be worth actively investing time to remediate this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm so i personally dont think it's that important to add a unit test here since this is just a function that prepares all the little UI components - probably more interesting to add unit tests separately for each piece (like i did for getBarTime
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
This PR adds Marks to the TradingView chart for historical buy and sell orders.
supports_marks: true
to the datafeed configuration will tell TV to query the newgetMarks
methodgetMarks
.toggle
and.toggle-active
Testing plan