Skip to content

Commit

Permalink
Merge pull request #80 from msamprz/handle-unknown-contracts
Browse files Browse the repository at this point in the history
Handle unknown contracts
  • Loading branch information
negarn committed May 21, 2019
2 parents cf3ccb1 + 36124a2 commit 0bbb91e
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 37 deletions.
102 changes: 67 additions & 35 deletions src/javascript/app/Constants/contract.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
import { localize } from '_common/localize';

const getContractConfig = is_high_low => ({
const getUnsupportedContracts = () => ({
EXPIRYMISS: {
name : localize('Ends Outside'),
position: 'top',
},
EXPIRYRANGE: {
name : localize('Ends Between'),
position: 'bottom',
},
RANGE: {
name : localize('Stays Between'),
position: 'top',
},
UPORDOWN: {
name : localize('Goes Outside'),
position: 'bottom',
},
RESETCALL: {
name : localize('Reset Call'),
position: 'top',
},
RESETPUT: {
name : localize('Reset Put'),
position: 'bottom',
},
TICKHIGH: {
name : localize('High Tick'),
position: 'top',
},
TICKLOW: {
name : localize('Low Tick'),
position: 'bottom',
},
ASIANU: {
name : localize('Asian Up'),
position: 'top',
Expand All @@ -9,6 +41,37 @@ const getContractConfig = is_high_low => ({
name : localize('Asian Down'),
position: 'bottom',
},
LBFLOATCALL: {
name : localize('Close-Low'),
position: 'top',
},
LBFLOATPUT: {
name : localize('High-Close'),
position: 'top',
},
LBHIGHLOW: {
name : localize('High-Low'),
position: 'top',
},
CALLSPREAD: {
name : localize('Call Spread'),
position: 'top',
},
PUTSPREAD: {
name : localize('Put Spread'),
position: 'bottom',
},
RUNHIGH: {
name : localize('Only Ups'),
position: 'top',
},
RUNLOW: {
name : localize('Only Downs'),
position: 'bottom',
},
});

const getContractConfig = is_high_low => ({
CALL: {
name : is_high_low ? localize('Higher') : localize('Rise'),
position: 'top',
Expand Down Expand Up @@ -49,38 +112,6 @@ const getContractConfig = is_high_low => ({
name : localize('Under'),
position: 'bottom',
},
EXPIRYMISS: {
name : localize('Ends Outside'),
position: 'top',
},
EXPIRYRANGE: {
name : localize('Ends Between'),
position: 'bottom',
},
EXPIRYRANGEE: {
name : localize('Ends Between'),
position: 'top',
},
LBFLOATCALL: {
name : localize('Close-Low'),
position: 'top',
},
LBFLOATPUT: {
name : localize('High-Close'),
position: 'bottom',
},
LBHIGHLOW: {
name : localize('High-Low'),
position: 'top',
},
RANGE: {
name : localize('Stays Between'),
position: 'top',
},
UPORDOWN: {
name : localize('Goes Outside'),
position: 'bottom',
},
ONETOUCH: {
name : localize('Touch'),
position: 'top',
Expand All @@ -89,7 +120,8 @@ const getContractConfig = is_high_low => ({
name : localize('No Touch'),
position: 'bottom',
},
...getUnsupportedContracts(),
});

export const getContractTypeDisplay = (type, is_high_low = false) => (getContractConfig(is_high_low)[type].name);
export const getContractTypePosition = (type, is_high_low = false) => (getContractConfig(is_high_low)[type].position);
export const getContractTypeDisplay = (type, is_high_low = false) => (getContractConfig(is_high_low)[type] ? getContractConfig(is_high_low)[type].name : '');
export const getContractTypePosition = (type, is_high_low = false) => (getContractConfig(is_high_low)[type] ? getContractConfig(is_high_low)[type].position : 'top');
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ export default connect(
is_loading : modules.portfolio.is_loading,
onMount : modules.portfolio.onMount,
onUnmount : modules.portfolio.onUnmount,
totals : modules.portfolio.totals,
totals : modules.portfolio.active_positions_totals,
})
)(withRouter(OpenPositions));
20 changes: 19 additions & 1 deletion src/javascript/app/Stores/Modules/Portfolio/portfolio-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default class PortfolioStore extends BaseStore {
if (isUserSold(contract_response)) this.positions[i].exit_spot = '-';
this.positions[i].is_loading = false;
}
};
@action.bound
pushNewPosition(new_pos) {
Expand Down Expand Up @@ -247,6 +247,24 @@ export default class PortfolioStore extends BaseStore {
};
}

@computed
get active_positions_totals() {
let indicative = 0;
let payout = 0;
let purchase = 0;

this.active_positions.forEach((portfolio_pos) => {
indicative += (+portfolio_pos.indicative);
payout += (+portfolio_pos.payout);
purchase += (+portfolio_pos.purchase);
});
return {
indicative,
payout,
purchase,
};
}

@computed
get active_positions() {
return this.positions.filter((portfolio_pos) => !portfolio_pos.result);
Expand Down

0 comments on commit 0bbb91e

Please sign in to comment.