Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions chartiq/src/main/java/com/chartiq/sdk/ChartIQHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ class ChartIQHandler(
QuoteFeedParams(symbol, period?.toInt(), interval, start, end, meta, callbackId)
dataSource?.pullInitialData(quoteFeedParams) { data ->
callbackId?.let {
invokePullCallback(callbackId, data)
// set moreAvailable to true as you want to see if there is more historical data after the initial pull
invokePullCallback(callbackId, data, true)
}
}
}
Expand All @@ -109,7 +110,8 @@ class ChartIQHandler(
QuoteFeedParams(symbol, period?.toInt(), interval, start, null, meta, callbackId)
dataSource?.pullUpdateData(quoteFeedParams) { data ->
callbackId?.let {
invokePullCallback(callbackId, data)
// just an update, no need to see if there is more historical data available
invokePullCallback(callbackId, data, false)
}
}
}
Expand All @@ -128,7 +130,13 @@ class ChartIQHandler(
QuoteFeedParams(symbol, period?.toInt(), interval, start, end, meta, callbackId)
dataSource?.pullPaginationData(quoteFeedParams) { data ->
callbackId?.let {
invokePullCallback(callbackId, data)
// Check to see if you need to try and retrieve more historical data.
// This is where you can put your own logic on when to stop retrieving historical data.
// By default if the last pagination request return 0 data then it has probably reached the end.
// If you have spotty data then another idea might be to check the last historical date, this would require you knowing what date to stop at though.
var moreAvailable = true
if(data.size < 1) moreAvailable = false
invokePullCallback(callbackId, data, moreAvailable)
}
}
}
Expand Down Expand Up @@ -445,8 +453,8 @@ class ChartIQHandler(
chartIQView.evaluateJavascript(script, callback)
}

private fun invokePullCallback(callbackId: String, data: List<OHLCParams>) {
executeJavascript(scriptManager.getParseDataScript(data, callbackId))
private fun invokePullCallback(callbackId: String, data: List<OHLCParams>, moreAvailable: Boolean) {
executeJavascript(scriptManager.getParseDataScript(data, callbackId, moreAvailable))
}

override fun getActiveSeries(callback: OnReturnCallback<List<Series>>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ internal class ChartIQScriptManager : ScriptManager {
override fun getGetEnginePropertyScript(property: String): String =
MOBILE_BRIDGE_NAME_SPACE + "getEngineProperty(\"$property\");"

override fun getParseDataScript(data: List<OHLCParams>, callbackId: String): String =
MOBILE_BRIDGE_NAME_SPACE + "parseData('${Gson().toJson(data)}', \"$callbackId\")"
override fun getParseDataScript(data: List<OHLCParams>, callbackId: String, moreAvailable: Boolean): String =
MOBILE_BRIDGE_NAME_SPACE + "parseData('${Gson().toJson(data)}', \"$callbackId\", $moreAvailable)"

override fun getInvertYAxisScript(): String =
MOBILE_BRIDGE_NAME_SPACE + "getLayoutProperty(\"flipped\");"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ internal interface ScriptManager {

fun getGetEnginePropertyScript(property: String): String

fun getParseDataScript(data: List<OHLCParams>, callbackId: String): String
fun getParseDataScript(data: List<OHLCParams>, callbackId: String, moreAvailable: Boolean): String

fun getInvertYAxisScript(): String

Expand Down
2 changes: 1 addition & 1 deletion demo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name">Demo</string>
<string name="app_name">ChartIQ</string>

<string name="title_chart">Chart</string>
<string name="title_study">Studies</string>
Expand Down