Created
April 10, 2019 03:28
-
-
Save nvrossett/cfd4a6b7bc866378e1523af707683a0d to your computer and use it in GitHub Desktop.
SimpleFX - Favorites (Swing)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var SimpleFX = { | |
minNegotiation : 0, | |
marginRequired : 0, | |
totalFavorites : 0, | |
addFavoritos : false, | |
useTableCache : false, | |
elements : { | |
groupsInvestiments : $('.marketwatch__category-section'), | |
allInvestiments : $('.marketwatch-item__col-symbol'), | |
}, | |
data : { | |
collect : [], | |
table : [], | |
cleanFavorites : [], | |
addFavFavorites : [] | |
}, | |
init : function( config ) { | |
console.clear() | |
SimpleFX.marginRequired = config.margin | |
SimpleFX.addFavoritos = config.addFavoritos | |
SimpleFX.useTableCache = config.useTableCache | |
if ( SimpleFX.useTableCache ){ | |
SimpleFX.data.table = JSON.parse( localStorage.getItem("cache_table") ) | |
} | |
SimpleFX.map.go() | |
}, | |
clearAllFavorites : function() { | |
console.clear() | |
$.each(SimpleFX.elements.groupsInvestiments, function(){ | |
var tab = $(this).find('.marketwatch__category'); | |
SimpleFX.map.verifyTabGroup( tab ) | |
var category = $(this).find('.marketwatch__category').text().trim() | |
if (category === 'Favorites'){ | |
var lineItem = $(this).find('.table__row') | |
$.each(lineItem, function(){ | |
var symbol = $(this).find('.marketwatch__col-symbol').text().trim() | |
SimpleFX.data.cleanFavorites.push({ | |
symbol : symbol, | |
open : $(this).find('.sfi-dots') | |
}) | |
}); | |
} | |
}) | |
setTimeout(function(){ | |
console.table( SimpleFX.data.cleanFavorites ); | |
SimpleFX.openFavMenu() | |
}, 100) | |
}, | |
openFavMenu : function(){ | |
var currentItem = SimpleFX.data.cleanFavorites[0] | |
if ( currentItem ){ | |
SimpleFX.removeFavorite( currentItem ) | |
}else{ | |
console.log('Concluído') | |
} | |
}, | |
removeFavorite : function( currentItem ){ | |
currentItem.open.trigger('click') | |
setTimeout(function(){ | |
$('.cdk-overlay-pane').find('.sfi-recycle-bin-small').parent().trigger('click') | |
setTimeout(function(){ | |
SimpleFX.data.cleanFavorites.shift() | |
SimpleFX.openFavMenu() | |
}, 100) | |
}, 100) | |
}, | |
map : { | |
go : function(){ | |
SimpleFX.map.getGroups() | |
}, | |
getGroups : function(){ | |
SimpleFX.data.table.push({ | |
category : 'Categorias', | |
symbol : 'Ativo', | |
sell : 'Venda', | |
spread : 'Spread', | |
buy : 'Compra', | |
change : '%', | |
margin : 'Margin', | |
minNegotiation : 'Negotiation' | |
}) | |
$.each(SimpleFX.elements.groupsInvestiments, function(){ | |
var tab = $(this).find('.marketwatch__category'); | |
SimpleFX.map.verifyTabGroup( tab ) | |
}); | |
setTimeout(function(){ | |
$.each(SimpleFX.elements.groupsInvestiments, function(){ | |
var category = $(this).find('.marketwatch__category').text().trim() | |
if ( category !== 'Favorites' ){ | |
var lineItem = $(this).find('.table__row') | |
$.each(lineItem, function(){ | |
var symbol = $(this).find('.marketwatch__col-symbol').text().trim() | |
var sell = $(this).find('.marketwatch__col-sell').text().trim() | |
var spread = $(this).find('.marketwatch__col-spread').text().trim() | |
var buy = $(this).find('.marketwatch__col-buy').text().trim() | |
var change = $(this).find('.marketwatch__col-session-change').text().trim() | |
if ( parseFloat( sell ) !== NaN ){ | |
SimpleFX.data.collect.push({ | |
category : category, | |
symbol : symbol, | |
sell : parseFloat( sell ), | |
spread : parseFloat( spread ), | |
buy : parseFloat( buy ), | |
change : parseFloat( change ) + '%', | |
action : $(this).find('.marketwatch__col-sell'), | |
menu : $(this).find('.sfi-dots') | |
}) | |
} | |
}); | |
} | |
}) | |
if ( !SimpleFX.useTableCache ){ | |
setTimeout(function(){ | |
SimpleFX.map.discoveryData() | |
}, 1000) | |
} else { | |
SimpleFX.map.remapCache() | |
} | |
}, 1000) | |
}, | |
remapCache : function(){ | |
$.each(SimpleFX.data.collect, function( indexCollect, itemCollect ){ | |
$.each(SimpleFX.data.table, function( indexTable, itemTable ){ | |
if ( itemCollect.symbol === itemTable.symbol ){ | |
SimpleFX.data.collect[indexCollect].margin = itemTable.margin | |
SimpleFX.data.collect[indexCollect].minNegotiation = itemTable.minNegotiation | |
} | |
}); | |
}); | |
SimpleFX.data.table = SimpleFX.data.collect | |
SimpleFX.map.discoveryFav() | |
}, | |
verifyTabGroup : function( tab ){ | |
var currentTab = $('.ng-star-inserted', tab); | |
if ( currentTab.hasClass('sfi-down-small') ){ | |
tab.trigger('click') | |
} | |
}, | |
discoveryData : function(){ | |
var item = SimpleFX.data.collect[0] | |
if ( item ){ | |
SimpleFX.map.openModal( item ) | |
}else{ | |
var csv = SimpleFX.data.table.map(function(d){ | |
var result = '"' + d.category + '","' + d.symbol + '","' + d.sell + '","' + d.spread + '","' + d.buy + '","' + d.change + '","' + d.margin + '","' + d.minNegotiation + '"' | |
return result; | |
}).join('\n') | |
console.log( ' CSV GERADO, ADICIONANCO ATIVOS AO FAVORITOS ' ) | |
console.log( csv ) | |
SimpleFX.data.table.shift() | |
localStorage.setItem("cache_table", JSON.stringify( SimpleFX.data.table ) ) | |
SimpleFX.map.discoveryFav() | |
} | |
}, | |
addFav : function ( item ){ | |
if ( ( item.margin <= SimpleFX.marginRequired && item.minNegotiation <= SimpleFX.minNegotiation ) || ( !SimpleFX.marginRequired && item.minNegotiation <= SimpleFX.minNegotiation ) || ( item.margin <= SimpleFX.marginRequired && !SimpleFX.minNegotiation ) ){ | |
if ( SimpleFX.addFavoritos ){ | |
item.menu.trigger('click') | |
setTimeout(function(){ | |
$('.cdk-overlay-pane').find('.sfi-star-small').parent().trigger('click') | |
SimpleFX.totalFavorites++ | |
setTimeout(function(){ | |
SimpleFX.data.table.shift() | |
SimpleFX.map.discoveryFav() | |
}, 100) | |
}, 200) | |
}else{ | |
setTimeout(function(){ | |
SimpleFX.data.table.shift() | |
SimpleFX.map.discoveryFav() | |
}, 100) | |
} | |
} else { | |
if ( item.symbol !== "Ativo" ){ | |
item.menu.parent().parent().parent().remove() | |
} | |
SimpleFX.data.table.shift() | |
SimpleFX.map.discoveryFav() | |
} | |
}, | |
discoveryFav : function (){ | |
var item = SimpleFX.data.table[0] | |
if ( item ){ | |
SimpleFX.map.addFav( item ) | |
}else{ | |
console.log( 'Concluído:' + SimpleFX.totalFavorites + ' ativos adicionados ao favoritos' ) | |
} | |
}, | |
openModal : function( item ){ | |
$('.sfi-close-small').trigger('click') | |
var btnOpenModal = item.action | |
btnOpenModal.find('.ng-star-inserted').trigger('click') | |
setTimeout(function(){ | |
var modal = $('.open-order__modal .flex-column.align-start .margin__value--estimation-margin').size() | |
if ( modal > 0 ){ | |
var margin = $('.open-order__modal .flex-column.align-start .margin__value--estimation-margin').text().trim().replace(' ','') | |
var minNegotiation = $('.open-order__modal .order__value.money-value.ng-star-inserted').text().trim().replace(' ','') | |
item.margin = parseFloat( margin ) | |
item.minNegotiation = parseFloat( minNegotiation ) | |
setTimeout(function(){ | |
delete item.action | |
SimpleFX.data.table.push( item ) | |
$('.sfi-close-small').trigger('click') | |
SimpleFX.data.collect.shift() | |
SimpleFX.map.discoveryData() | |
}, 1000) | |
} else { | |
$('.sfi-close-small').trigger('click') | |
SimpleFX.map.openModal( item ) | |
} | |
}, 1500) | |
} | |
} | |
}; | |
// Adiciona ao Favoritos apenas ativos com margem minima de 50 cents (gera csv geral no final) | |
SimpleFX.init( { minNegotiation : 1.75, margin : false, addFavoritos : true, useTableCache : true } ); | |
// Retira todos os ativos dos favoritos | |
// SimpleFX.clearAllFavorites() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment