Compare commits

..

No commits in common. "448403c922b7df672f955663dc4bb2cfa88ff652" and "808c1a715d36c151dee9e18a2a5ac1985eb80dce" have entirely different histories.

35 changed files with 23 additions and 20668 deletions

View File

@ -12,3 +12,4 @@
// //
//= require rails-ujs //= require rails-ujs
//= require turbolinks //= require turbolinks
//= require_tree .

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -10,32 +10,6 @@
* files in this directory. Styles in this file should be added after the last require_* statement. * files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope. * It is generally better to create a new file per style scope.
* *
*= require bootstrap.min *= require_tree .
*= require_self *= require_self
*/ */
/* Sticky footer styles -------------------------------------------------- */
html {
position: relative;
min-height: 100%;
}
body {
padding-top: 5rem;
/* Margin bottom by footer height */
margin-bottom: 60px;
}
.starter {
padding-left: 0.2em;
padding-right: 0.2em;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
line-height: 60px; /* Vertically center the text there */
background-color: #f5f5f5;
}
.li_active {
color: #0923ff;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,342 +0,0 @@
/*!
* Bootstrap Reboot v4.0.0-beta.2 (https://getbootstrap.com)
* Copyright 2011-2017 The Bootstrap Authors
* Copyright 2011-2017 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md)
*/
*,
*::before,
*::after {
box-sizing: border-box;
}
html {
font-family: sans-serif;
line-height: 1.15;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
-ms-overflow-style: scrollbar;
-webkit-tap-highlight-color: transparent;
}
@-ms-viewport {
width: device-width;
}
article, aside, dialog, figcaption, figure, footer, header, hgroup, main, nav, section {
display: block;
}
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #212529;
text-align: left;
background-color: #fff;
}
[tabindex="-1"]:focus {
outline: none !important;
}
hr {
box-sizing: content-box;
height: 0;
overflow: visible;
}
h1, h2, h3, h4, h5, h6 {
margin-top: 0;
margin-bottom: 0.5rem;
}
p {
margin-top: 0;
margin-bottom: 1rem;
}
abbr[title],
abbr[data-original-title] {
text-decoration: underline;
-webkit-text-decoration: underline dotted;
text-decoration: underline dotted;
cursor: help;
border-bottom: 0;
}
address {
margin-bottom: 1rem;
font-style: normal;
line-height: inherit;
}
ol,
ul,
dl {
margin-top: 0;
margin-bottom: 1rem;
}
ol ol,
ul ul,
ol ul,
ul ol {
margin-bottom: 0;
}
dt {
font-weight: 700;
}
dd {
margin-bottom: .5rem;
margin-left: 0;
}
blockquote {
margin: 0 0 1rem;
}
dfn {
font-style: italic;
}
b,
strong {
font-weight: bolder;
}
small {
font-size: 80%;
}
sub,
sup {
position: relative;
font-size: 75%;
line-height: 0;
vertical-align: baseline;
}
sub {
bottom: -.25em;
}
sup {
top: -.5em;
}
a {
color: #007bff;
text-decoration: none;
background-color: transparent;
-webkit-text-decoration-skip: objects;
}
a:hover {
color: #0056b3;
text-decoration: underline;
}
a:not([href]):not([tabindex]) {
color: inherit;
text-decoration: none;
}
a:not([href]):not([tabindex]):focus, a:not([href]):not([tabindex]):hover {
color: inherit;
text-decoration: none;
}
a:not([href]):not([tabindex]):focus {
outline: 0;
}
pre,
code,
kbd,
samp {
font-family: monospace, monospace;
font-size: 1em;
}
pre {
margin-top: 0;
margin-bottom: 1rem;
overflow: auto;
-ms-overflow-style: scrollbar;
}
figure {
margin: 0 0 1rem;
}
img {
vertical-align: middle;
border-style: none;
}
svg:not(:root) {
overflow: hidden;
}
a,
area,
button,
[role="button"],
input:not([type="range"]),
label,
select,
summary,
textarea {
-ms-touch-action: manipulation;
touch-action: manipulation;
}
table {
border-collapse: collapse;
}
caption {
padding-top: 0.75rem;
padding-bottom: 0.75rem;
color: #868e96;
text-align: left;
caption-side: bottom;
}
th {
text-align: inherit;
}
label {
display: inline-block;
margin-bottom: .5rem;
}
button {
border-radius: 0;
}
button:focus {
outline: 1px dotted;
outline: 5px auto -webkit-focus-ring-color;
}
input,
button,
select,
optgroup,
textarea {
margin: 0;
font-family: inherit;
font-size: inherit;
line-height: inherit;
}
button,
input {
overflow: visible;
}
button,
select {
text-transform: none;
}
button,
html [type="button"],
[type="reset"],
[type="submit"] {
-webkit-appearance: button;
}
button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
padding: 0;
border-style: none;
}
input[type="radio"],
input[type="checkbox"] {
box-sizing: border-box;
padding: 0;
}
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="month"] {
-webkit-appearance: listbox;
}
textarea {
overflow: auto;
resize: vertical;
}
fieldset {
min-width: 0;
padding: 0;
margin: 0;
border: 0;
}
legend {
display: block;
width: 100%;
max-width: 100%;
padding: 0;
margin-bottom: .5rem;
font-size: 1.5rem;
line-height: inherit;
color: inherit;
white-space: normal;
}
progress {
vertical-align: baseline;
}
[type="number"]::-webkit-inner-spin-button,
[type="number"]::-webkit-outer-spin-button {
height: auto;
}
[type="search"] {
outline-offset: -2px;
-webkit-appearance: none;
}
[type="search"]::-webkit-search-cancel-button,
[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}
::-webkit-file-upload-button {
font: inherit;
-webkit-appearance: button;
}
output {
display: inline-block;
}
summary {
display: list-item;
}
template {
display: none;
}
[hidden] {
display: none !important;
}
/*# sourceMappingURL=bootstrap-reboot.css.map */

File diff suppressed because one or more lines are too long

View File

@ -1,8 +0,0 @@
/*!
* Bootstrap Reboot v4.0.0-beta.2 (https://getbootstrap.com)
* Copyright 2011-2017 The Bootstrap Authors
* Copyright 2011-2017 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md)
*/*,::after,::before{box-sizing:border-box}html{font-family:sans-serif;line-height:1.15;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;-ms-overflow-style:scrollbar;-webkit-tap-highlight-color:transparent}@-ms-viewport{width:device-width}article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}body{margin:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:1rem;font-weight:400;line-height:1.5;color:#212529;text-align:left;background-color:#fff}[tabindex="-1"]:focus{outline:0!important}hr{box-sizing:content-box;height:0;overflow:visible}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem}p{margin-top:0;margin-bottom:1rem}abbr[data-original-title],abbr[title]{text-decoration:underline;-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;border-bottom:0}address{margin-bottom:1rem;font-style:normal;line-height:inherit}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-left:0}blockquote{margin:0 0 1rem}dfn{font-style:italic}b,strong{font-weight:bolder}small{font-size:80%}sub,sup{position:relative;font-size:75%;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#007bff;text-decoration:none;background-color:transparent;-webkit-text-decoration-skip:objects}a:hover{color:#0056b3;text-decoration:underline}a:not([href]):not([tabindex]){color:inherit;text-decoration:none}a:not([href]):not([tabindex]):focus,a:not([href]):not([tabindex]):hover{color:inherit;text-decoration:none}a:not([href]):not([tabindex]):focus{outline:0}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}pre{margin-top:0;margin-bottom:1rem;overflow:auto;-ms-overflow-style:scrollbar}figure{margin:0 0 1rem}img{vertical-align:middle;border-style:none}svg:not(:root){overflow:hidden}[role=button],a,area,button,input:not([type=range]),label,select,summary,textarea{-ms-touch-action:manipulation;touch-action:manipulation}table{border-collapse:collapse}caption{padding-top:.75rem;padding-bottom:.75rem;color:#868e96;text-align:left;caption-side:bottom}th{text-align:inherit}label{display:inline-block;margin-bottom:.5rem}button{border-radius:0}button:focus{outline:1px dotted;outline:5px auto -webkit-focus-ring-color}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,input{overflow:visible}button,select{text-transform:none}[type=reset],[type=submit],button,html [type=button]{-webkit-appearance:button}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{padding:0;border-style:none}input[type=checkbox],input[type=radio]{box-sizing:border-box;padding:0}input[type=date],input[type=datetime-local],input[type=month],input[type=time]{-webkit-appearance:listbox}textarea{overflow:auto;resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{display:block;width:100%;max-width:100%;padding:0;margin-bottom:.5rem;font-size:1.5rem;line-height:inherit;color:inherit;white-space:normal}progress{vertical-align:baseline}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:none}[type=search]::-webkit-search-cancel-button,[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}summary{display:list-item}template{display:none}[hidden]{display:none!important}
/*# sourceMappingURL=bootstrap-reboot.min.css.map */

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,12 +1,6 @@
class HomeController < ApplicationController class HomeController < ApplicationController
def index def index
@currencies = Currency.all @currencies = Currency.all
if params[:curr_id].blank?
@curr_id = Currency.first.id
else
@curr_id = params[:curr_id]
end
bbt
end end
def seed def seed
@ -24,20 +18,4 @@ class HomeController < ApplicationController
end end
end end
end end
def get_trades
@currencies = Currency.all
@curr_id = params[:curr_id]
bbt
end
def bbt
@bbt = BitBayTrade.where('currency_id = ?', @curr_id).order('cast(tid as unsigned) DESC').limit(20)
@bbt_max_lifetime = BitBayTrade.where('currency_id = ?', @curr_id).order('price DESC').first
@bbt_min_lifetime = BitBayTrade.where('currency_id = ?', @curr_id).order('price ASC').first
time = Time.now - 24.hours
@bbt_max_24h = BitBayTrade.where('currency_id = ? AND date > ?', @curr_id,time).order('price DESC').first
@bbt_min_24h = BitBayTrade.where('currency_id = ? AND date > ?', @curr_id,time).order('price ASC').first
end
end end

View File

@ -2,47 +2,43 @@
# encoding: UTF-8 # encoding: UTF-8
ENV["RAILS_ENV"] ||= "development" ENV["RAILS_ENV"] ||= "development"
require File.dirname(__FILE__) + "/../config/environment" require File.dirname(__FILE__) + "/../../config/environment"
require 'uri' require 'uri'
require 'net/http' require 'net/http'
require 'json' require 'json'
pause_interval = 3 pause_interval = 60
start_index = '-1' start_index = '-1'
currencies = {1 => "BTC", 4 => "LSK", 5 => "LTC", 7 => "GAME"} currency = Currency.where(name: 'GAME').first
currency_ids = [5,4,7]
#currency = Currency.where(name: 'LSK').first
while true while true
for currency_id in currency_ids
start_time = Time.now.to_i start_time = Time.now.to_i
bbt_index = BitBayTrade.where('currency_id = ?', currency_id).order('cast(tid as unsigned) DESC').first bbt_index = BitBayTrade.where('currency_id = ?', currency.id).order('cast(tid as unsigned) DESC').first
unless bbt_index.blank? unless bbt_index.blank?
start_index = bbt_index.tid start_index = bbt_index.tid
else
start_index = -1
end end
uri = "https://bitbay.net/API/Public/#{currencies[currency_id]}PLN/trades.json?since=#{start_index}" uri = "https://bitbay.net/API/Public/#{currency.name}PLN/trades.json?since=#{start_index}"
puts "start at #{start_index} index for #{currencies[currency_id]}" puts "start at #{start_index} index"
url = URI.parse(uri) url = URI.parse(uri)
resp = Net::HTTP.get_response(url) resp = Net::HTTP.get_response(url)
my_hash = JSON.parse(resp.body) my_hash = JSON.parse(resp.body)
for mh in my_hash for mh in my_hash
bbt = BitBayTrade.where('currency_id = ? AND tid = ?', currency_id, mh['tid']).first bbt = BitBayTrade.where('currency_id = ? AND tid = ?', currency.id, mh['tid']).first
if bbt.blank? if bbt.blank?
BitBayTrade.create(currency_id: currency_id, tid: mh['tid'], date: Time.at(mh['date'].to_i), transaction_type: mh['type'], price: mh['price'], amount: mh['amount']) BitBayTrade.create(currency_id: currency.id, tid: mh['tid'], date: Time.at(mh['date'].to_i), transaction_type: mh['type'], price: mh['price'], amount: mh['amount'])
#puts "#{mh['tid']} -#{mh['date']} - #{mh['price']} - #{mh['type']} - #{mh['amount']}" #puts "#{mh['tid']} -#{mh['date']} - #{mh['price']} - #{mh['type']} - #{mh['amount']}"
end end
end end
end_time = Time.now.to_i end_time = Time.now.to_i
=begin
if end_time > start_time if end_time > start_time
diff_time = end_time - start_time diff_time = end_time - start_time
if diff_time < pause_interval if diff_time < 60
puts "Sleep #{pause_interval - diff_time + 1} dla #{diff_time}" puts "Sleep #{pause_interval - diff_time + 1} dla #{diff_time}"
sleep(pause_interval - diff_time + 1) sleep(pause_interval - diff_time + 1)
end end
else else
sleep(pause_interval) sleep(pause_interval)
end end
end =end
end end

View File

@ -1,2 +0,0 @@
$("#bbt_ajax").html("<%= escape_javascript(render('/home/partials/bb_trades')) %>");
$("#left_menu").html("<%= escape_javascript(render('/home/partials/left_menu')) %>");

View File

@ -1,15 +1,8 @@
<div class="row"> <h1>Currencies</h1>
<div class="col-md-2"> <p>
<h1>Currencies</h1> <ul>
<p> <% for curr in @currencies %>
<div id="left_menu"> <li><%= curr.name %> (<%= curr.description %>)</li>
<%= render :partial => '/home/partials/left_menu' %> <% end %>
</div> </ul>
</p> </p>
</div>
<div class="col-md-10">
<div id="bbt_ajax">
<%= render :partial => '/home/partials/bb_trades'%>
</div>
</div>
</div>

View File

@ -1,32 +0,0 @@
<% if !@bbt_max_lifetime.blank? %>
<h6>Max (<%= @bbt_max_lifetime.date %>): <span class="badge badge-success"><%= '%.2f' % @bbt_max_lifetime.price %></span> Min (<%= @bbt_min_lifetime.date %>): <span class="badge badge-danger"><%= '%.2f' % @bbt_min_lifetime.price %></span></h6>
<% else %>
<h6><span class="badge badge-warning">Brak danych dla tej monety</span></h6>
<% end %>
<% if !@bbt_max_24h.blank? %>
<h6>Max 24h: <span class="badge badge-success"><%= '%.2f' % @bbt_max_24h.price %></span> Min 24h: <span class="badge badge-danger"><%= '%.2f' % @bbt_min_24h.price %></span></h6>
<% else %>
<h6><span class="badge badge-danger">Brak danych z ostatnich 24h</span></h6>
<% end %>
<table class="table table-sm table-dark">
<thead>
<tr>
<th scope="col">tid</th>
<th scope="col">Data</th>
<th scope="col">Cena</th>
<th scope="col">Ilość</th>
<th scope="col">Koszt transakcji</th>
</tr>
</thead>
<tbody>
<% for bbt in @bbt %>
<tr class="<%= bbt.transaction_type == 'buy' ? 'bg-success' : 'bg-danger' %>">
<th scope="row"><%= bbt.tid %></th>
<td><%= bbt.date %></td>
<td><%= '%.2f' % bbt.price %></td>
<td><%= bbt.amount %></td>
<td><%= '%.2f' % (bbt.price * bbt.amount) %></td>
</tr>
<% end %>
</tbody>
</table>

View File

@ -1,7 +0,0 @@
<% for curr in @currencies %>
<% if @curr_id.to_i == curr.id %>
<%= link_to "#{curr.name} (#{curr.description})", {controller: :home, action: :get_trades, curr_id: curr.id}, remote: true, class: "badge badge-success" %><br/>
<% else %>
<%= link_to "#{curr.name} (#{curr.description})", {controller: :home, action: :get_trades, curr_id: curr.id}, remote: true, class: "badge badge-primary" %><br/>
<% end%>
<% end %>

View File

@ -9,49 +9,6 @@
</head> </head>
<body> <body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
<div class="starter">
<%= yield %> <%= yield %>
</div>
<footer class="footer">
<div class="container">
<span class="text-muted">CryptoBot <%= Time.now.to_date %></span>
</div>
</footer>
<%= javascript_include_tag 'jquery-3.2.1.min.js', 'popper.min', 'bootstrap.min' %>
</body> </body>
</html> </html>

View File

@ -1,27 +0,0 @@
#!/usr/bin/env ruby
# encoding: UTF-8
@table = [
['0','0','0','0','0','0','0','0','0','0','0','0','0'],
['0','1','1','1','1','1','1','1','1','0','0','0','0'],
['0','0','1','0','0','0','1','0','1','1','0','0','0'],
['0','1','1','0','0','1','0','0','0','1','1','0','0'],
['0','1','1','1','1','1','1','1','1','0','1','0','0'],
['0','0','0','0','0','0','0','0','1','0','1','0','0'],
['0','1','1','1','1','1','1','0','1','0','1','0','0'],
['0','1','0','0','0','0','1','0','1','0','1','0','0'],
['0','1','1','1','1','0','1','0','1','0','1','0','0'],
['0','S','1','0','1','0','1','1','1','0','1','1','1'],
['0','0','0','0','0','0','0','0','0','0','0','0','0']
]
def find_start_pos(table, start_symbol='S')
table.each_with_index { |row,index_row|
row.each_with_index { |cell,index_cell|
return [index_row, index_cell] if cell.eql?(start_symbol)
}
}
return nil
end
puts find_start_pos(@table).inspect

View File

@ -12,4 +12,3 @@ Rails.application.config.assets.paths << Rails.root.join('node_modules')
# application.js, application.css, and all non-JS/CSS in the app/assets # application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added. # folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css ) # Rails.application.config.assets.precompile += %w( admin.js admin.css )
Rails.application.config.assets.precompile += %w( bootstrap.min.js bootstrap.css jquery-3.2.1.min.js popper.min.js)

View File

@ -1,7 +1,6 @@
Rails.application.routes.draw do Rails.application.routes.draw do
get 'home/index' get 'home/index'
get 'home/seed' get 'home/seed'
get 'home/get_trades'
root 'home#index' root 'home#index'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end end