Skip to content

Commit

Permalink
Merge pull request #117 from zakibinary/fix_candle_sell
Browse files Browse the repository at this point in the history
zaki/fix_candle_sell
  • Loading branch information
ashkanx committed May 30, 2019
2 parents c551069 + e458127 commit a7d7d28
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ import {
import { unique } from '../../../../../_common/utility';
import { MARKER_TYPES_CONFIG } from '../../SmartChart/Constants/markers';

export const createChartMarkers = (SmartChartStore, contract_info, replay_config) => {
export const createChartMarkers = (SmartChartStore, contract_info) => {
if (contract_info) {
const chart_type = replay_config ? replay_config.chart_type : SmartChartStore.chart_type;
const end_time = getEndTime(contract_info);
const end_time = getEndTime(contract_info);
const chart_type = getChartType(contract_info.date_start, end_time);
if (contract_info.tick_count) {
addTickMarker(SmartChartStore, contract_info);
}
if (end_time && getChartType(contract_info.date_start, end_time) !== 'candle') {
addMarker(marker_spots, SmartChartStore, contract_info);
} else if (chart_type === 'mountain') {
} else if (chart_type !== 'candle') {
addMarker(marker_spots, SmartChartStore, contract_info);
}
addMarker(marker_lines, SmartChartStore, contract_info);
Expand Down
40 changes: 12 additions & 28 deletions src/javascript/app/Stores/Modules/Contract/contract-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ export default class ContractStore extends BaseStore {
// ---- Normal properties ---
forget_id;
chart_type = 'mountain';
is_granularity_set = false;
is_left_epoch_set = false;
is_from_positions = false;
is_ongoing_contract = false;
Expand All @@ -64,12 +62,11 @@ export default class ContractStore extends BaseStore {
// -------------------
@action.bound
drawChart(SmartChartStore, contract_info) {
this.forget_id = contract_info.id;
const { date_start } = contract_info;
const end_time = getEndTime(contract_info);
const should_update_chart_type = (!contract_info.tick_count && !this.is_granularity_set);
this.forget_id = contract_info.id;
const { date_start } = contract_info;
const end_time = getEndTime(contract_info);
SmartChartStore.setChartView(contract_info.purchase_time);
if (!end_time) this.is_ongoing_contract = true;
// finish contracts if end_time exists
Expand All @@ -82,7 +79,7 @@ export default class ContractStore extends BaseStore {
SmartChartStore.setContractStart(date_start);
SmartChartStore.setContractEnd(end_time);
if (should_update_chart_type) {
if (!contract_info.tick_count) {
this.handleChartType(SmartChartStore, date_start, end_time);
} else {
SmartChartStore.updateGranularity(0);
Expand All @@ -94,25 +91,15 @@ export default class ContractStore extends BaseStore {
}
// setters for ongoing contracts, will only init once onMount after left_epoch is set
} else if (!this.is_left_epoch_set) {
} else {
if (this.is_from_positions) {
SmartChartStore.setContractStart(date_start);
}
if (contract_info.tick_count) {
SmartChartStore.updateGranularity(0);
SmartChartStore.updateChartType('mountain');
}
this.is_left_epoch_set = true;
SmartChartStore.setChartView(contract_info.purchase_time);
}
if (should_update_chart_type && !contract_info.tick_count) {
this.handleChartType(SmartChartStore, date_start, null);
}
if (this.is_granularity_set) {
if (getChartType(date_start, null) !== this.chart_type) {
this.is_granularity_set = false;
} else {
this.handleChartType(SmartChartStore, date_start, null);
}
}
Expand Down Expand Up @@ -191,9 +178,7 @@ export default class ContractStore extends BaseStore {
this.error_message = '';
this.forget_id = null;
this.has_error = false;
this.is_granularity_set = false;
this.is_sell_requested = false;
this.is_left_epoch_set = false;
this.is_from_positions = false;
this.is_ongoing_contract = false;
this.sell_info = {};
Expand Down Expand Up @@ -260,7 +245,7 @@ export default class ContractStore extends BaseStore {
}
createChartBarrier(this.smart_chart, this.replay_info, this.root_store.ui.is_dark_mode_on);
createChartMarkers(this.smart_chart, this.replay_info, this.replay_config);
createChartMarkers(this.smart_chart, this.replay_info);
this.handleDigits(this.replay_info);
this.waitForChartListener(this.smart_chart);
Expand Down Expand Up @@ -340,15 +325,14 @@ export default class ContractStore extends BaseStore {
const chart_type = getChartType(start, expiry);
const granularity = getChartGranularity(start, expiry);

if (chart_type === 'candle' && granularity !== 0) {
SmartChartStore.updateChartType(chart_type);
if (chart_type === 'candle') {
this.chart_type = chart_type;
SmartChartStore.updateChartType(chart_type);
} else {
SmartChartStore.updateChartType('mountain');
this.chart_type = 'mountain';
SmartChartStore.updateChartType('mountain');
}
SmartChartStore.updateGranularity(granularity);
this.is_granularity_set = true;
}

forgetProposalOpenContract() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default class PortfolioStore extends BaseStore {
// the Portfolio API returns an empty `contracts` array.
// This causes the contract to not be pushed to the `positions` property here.
// The statement below prevents accessing undefined values caused by the above explanation.
if (i === -1) { return; }
if (i === -1) return;
this.positions[i].is_loading = true;
WS.subscribeProposalOpenContract(contract_id.toString(), this.populateResultDetails, false);
Expand Down

0 comments on commit a7d7d28

Please sign in to comment.