Skip to content

Instantly share code, notes, and snippets.

@GitSumito
Last active February 7, 2018 01:46
Show Gist options
  • Save GitSumito/35cdcb925f0d23eaedfb563c8bb0c134 to your computer and use it in GitHub Desktop.
Save GitSumito/35cdcb925f0d23eaedfb563c8bb0c134 to your computer and use it in GitHub Desktop.
ビットコインでアービトラージを稼げるのか ref: https://qiita.com/S-T/items/f454c2668c6805e690e4
#!/bin/sh
TABLE=BITHUMB_JPY_BTC
ORIGINALPRICE=`curl -s https://api.bithumb.com/public/ticker/BTC | jq -r '.data.buy_price'`
RATE=`curl -s http://api.aoikujira.com/kawase/json/krw | jq -r '.JPY'`
PRICE=`echo "scale=0 ; $ORIGINALPRICE * $RATE" | /usr/bin/bc`
echo "insert into $TABLE(price) values(${PRICE%.*});" > sql/$TABLE.sql;
#!/bin/sh
TABLE=COINCHECK_JPY_BTC
PRICE=`curl -s https://coincheck.com/api/rate/btc_jpy | jq -r .rate | awk -F'.' '{print $1}'`
echo "insert into $TABLE(price) values($PRICE);" > sql/$TABLE.sql;
echo "insert...."
for i in `ls sql`; do
echo sql/$i
mysql -uroot coin < sql/$i
sleep 5;
done
echo "insert....done"
yum install mariadb mariadb-server -y
rpm -qa | grep maria
# MariaDBの起動
systemctl start mariadb
systemctl enable mariadb
# ログイン (ノーパスで入れる)
mysql -uroot -p
MariaDB [(none)]>
MariaDB [(none)]> create database coin;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]>
MariaDB [(none)]> SELECT PASSWORD('password');
+-------------------------------------------+
| PASSWORD('password') |
+-------------------------------------------+
| *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
+-------------------------------------------+
1 row in set (0.00 sec)
MariaDB [(none)]> GRANT USAGE ON *.* TO 'redash'@'172.18.0.%' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT SELECT, EXECUTE ON `coin`.* TO 'redash'@'172.18.0.%';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> select user,host from mysql.user;
+--------+------------+
| user | host |
+--------+------------+
| root | 127.0.0.1 |
| redash | 172.18.0.% |
| root | ::1 |
| | instance-1 |
| root | instance-1 |
| | localhost |
| root | localhost |
+--------+------------+
7 rows in set (0.00 sec)
MariaDB [(none)]> show grants for 'redash'@'172.18.0.%';
select b1.price as BITHUMB_JPY_BTC ,
c1.price as COINCHECK_JPY_BTC ,
b1.price / c1.price as percent ,
c1.creation_time
from BITHUMB_JPY_BTC as b1
left join COINCHECK_JPY_BTC as c1
on b1.creation_time >= c1.creation_time
where b1.creation_time between '2018-01-11 10:55' and '2120-01-11 12:55'
order by creation_time desc
limit 1000
MariaDB [(none)]> use coin;
Database changed
MariaDB [coin]>
CREATE TABLE `COINCHECK_JPY_BTC` (
`price` int(10) unsigned NOT NULL,
`creation_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`price`,`creation_time`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `BITHUMB_JPY_BTC` (
`price` int(10) unsigned NOT NULL,
`creation_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`price`,`creation_time`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
curl -o /usr/bin/jq -L https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 && chmod +x /usr/bin/jq
yum install bc -y
# docker install
yum -y install docker-io
systemctl start docker
systemctl enable docker
# docker compose install
curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
# re:dash container
git clone https://github.com/getredash/redash
cd redash/
docker-compose -f docker-compose.production.yml run --rm server create_db
docker-compose -f docker-compose.production.yml up -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment