pubnubを使用して約定情報を得る
BitFlyerが提供しているRealtime APIを使用してリアルタイムに
約定情報を取得します。
動作はCentOS7上でnode.jsを使用します。
まずはインストール。
epelリポジトリを使用します。
yum -y install epel-release
続いてnodejsをインストール。
yum --enablerepo=epel install nodejs
そしてコードを書きます。
jsファイルを作ったディレクトリ上でpubnubのインストールコマンドを実行します。
npm install pubnub --save-dev
node_modulesディレクトリが作成されます。
中身は今回は気にしません。
そして実行。
node getRTYakutei.js
こんな感じに表示されます。
61043317 BUY 426361 0.3 2017-09-23T10:39:39.9226427Z JRF20170923-073939-511591 JRF20170923-073938-685211 61043318 SELL 426362 1 2017-09-23T10:39:40.0945199Z JRF20170923-073939-511591 JRF20170923-163938-379485 61043319 SELL 426301 0.02 2017-09-23T10:39:41.5633084Z JRF20170923-073845-747593 JRF20170923-163939-321348 61043320 SELL 426352 0.05 2017-09-23T10:39:42.7664744Z JRF20170923-073940-220626 JRF20170923-163941-542666
建玉情報を得る
BitFlyerのWebApiを使って建玉情報を取得してみます。
言語はPHPです。
アクセスキーとアクセスシークレットは当然自分のアカウントのものを使用します。
ログインして取得して下さい。
建玉の一覧を取得
クエリパラメータはproduct_code: "FX_BTC_JPY" を指定します。
と書いてあったのでpathには
/v1/me/getpositions/
に続き
?product_code=FX_BTC_JPY
を指定します。
またGETコマンドを使用しますが、29行目のようにCURLOPT_POSTFIELDSを使用します。
curl_execの結果が勝手に展開されてしまうので、その対策として
CURLOPT_RETURNTRANSFERをtrueの指定を入れて下さい。
※2017年9月26日 修正
gistのソースから無駄な行を削除しました。
CentOS7にpostgresをインストール
CentOS7にpostgresql-9.6をインストールしてクライアント(OSはWin10 DB接続ツールはA5:SQL MK2)からアクセスしてみました。
CentOS7とクライアントは同セグメントです。
rpmパッケージをインストール
wget https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm rpm -ivh pgdg-centos96-9.6-3.noarch.rpm
続いてyumにて下記をインストール
rpmパッケージインストール後でないと下記のコマンドでは何もインストールされませんでした。
yum -y install postgresql96-server postgresql96-devel postgresql96-contrib
セットアップファイルを検索
find / -name "postgresql*-setup*" -print
下記場所が出力される
/usr/pgsql-9.6/bin/postgresql96-setup
dbinitを実行
/usr/pgsql-9.6/bin/postgresql96-setup initdb
postgresユーザが作成されるので、必要であればパスワード変更。
コンフィグファイルの修正(場所はfindコマンドで検索)
pg_hba.confの編集
IPv4 local connectionsにローカルエリアを追記
# TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all peer # IPv4 local connections: host all all 127.0.0.1/32 ident host all all 192.168.0.0/16 ident # IPv6 local connections: host all all ::1/128 ident # Allow replication connections from localhost, by a user with the # replication privilege. #local replication postgres peer #host replication postgres 127.0.0.1/32 ident #host replication postgres ::1/128 ident
postgresql.confの編集
中頃にCONNECTIONS AND AUTHENTICATIONがあるのでリッスンアドレスやポートを設定する
#------------------------------------------------------------------------------ # CONNECTIONS AND AUTHENTICATION #------------------------------------------------------------------------------ # - Connection Settings - listen_addresses = '*' # what IP address(es) to listen on; #listen_addresses = 'localhost' # what IP address(es) to listen on; # comma-separated list of addresses; # defaults to 'localhost'; use '*' for all # (change requires restart) port = 5432 # (change requires restart) max_connections = 100 # (change requires restart) #superuser_reserved_connections = 3 # (change requires restart) #unix_socket_directories = '/var/run/postgresql, /tmp' # comma-separated list of directories # (change requires restart) #unix_socket_group = '' # (change requires restart) #unix_socket_permissions = 0777 # begin with 0 to use octal notation # (change requires restart) #bonjour = off # advertise server via Bonjour # (change requires restart) #bonjour_name = '' # defaults to the computer name # (change requires restart)
起動する。
systemctl start postgresql-9.6
外部から接続出来るようにポートが開いているかどうか確認
テスト環境なのでどこからでもアクセスおk。
netstat -antu Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN
ファイアーウォールの許可
firewall-cmd --add-service=postgresql --zone=public --permanent systemctl restart firewalld
postgresの初期設定
# su postgres $ psql
DBが持っているユーザ postgresのパスワードを変更
postgres=# alter role postgres with password 'パスワード';
テスト接続用DBを作成
postgres=# CREATE DATABASE TEST;
クライアントから接続してみます。
接続出来なかったらログを参照。
tail -f /var/lib/pgsql/9.6/data/pg_log/postgresql-Sun.log
< 2017-04-23 13:49:24.699 JST > FATAL: ユーザ"postgres"のパスワード認証に失敗しました < 2017-04-23 13:49:24.699 JST > 詳細: User "postgres" has no password assigned. 接続はpg_hba.confの行83に一致しました: "host all all 192.168.0.0/16 md5"
上で設定したDBが持っているユーザ postgresのパスワード変更を
してないと上記のように出力されていました。
使用するデータベースに接続
postgres=# \connect TEST
テスト用テーブル作成
CREATE TABLE testTbl (No INT NOT NULL, username varchar(100), create_datetime timestamp, PRIMARY KEY(No, username));
テスト用データインサート
insert into testTbl values (1, "テスト", current_timestamp);
クライアントからデータ取得出来るか確認できれば完了です。
lets encryptとお名前.comでドメイン取得
ssl証明書を無料で取得出来るなんて良い時代になりました。
https://letsencrypt.jp/
インストールです。
apacheに設定してやります。
opensslとmod_sslのインストールが済んでいないようならインストールします。
yum install -y openssl mod_ssl
epelリポジトリを有効にして下記コマンドを実行
wget https://dl.eff.org/certbot-auto chmod 700 certbot-auto ./certbot-auto
いよいよ証明書を取得します。
取得用にサーバが起動するようなのでapacheを止めます。
service httpd stop
以下は覚書なのでうまくいかなかったら調べ直す必要があるかもしれません。あってるかな。
ポート80なら↓
./certbot-auto certonly --standalone-supported-challenges http-01 -d ドメイン名
ポート443なら↓
./certbot-auto certonly --standalone-supported-challenges tls-sni-01 -d ドメイン名
mydnsのドメインでは証明書がなかなか発行されないので(1週間で同ドメインには20通まで?)
お名前.comにドメインを取得しcnameを張りました。
更新はwebサーバを止めて下記コマンドで実施することが出来ます。
./letsencrypt-auto renew
gitについて
gitサーバ、クライアントの設定
まずはサーバの構築
サーバはCentOSを想定。
# yum install git
グループ、ユーザを作成する。
unixのユーザがそのままgitで使用される。
# groupadd gitgroup # useradd -g gitgroup gituser
パスワードも忘れずに。
# passwd gituser
リポジトリディレクトリを作成する。
XXX.gitという名前が一般的。
# mkdir -p /usr/local/git/rep.git
作成したディレクトリの権限をgit用ユーザに。
# chown gituser rep.git/
作成したgit用ユーザにスイッチ。
# su - gituser
git initして完成。
$ git init --bare --shared
クライアント側
/usr/local/git/のとこは適宜修正します。
git clone ssh://gituser@サーバアドレス/usr/local/git/git.rep
新しいブランチを作る
git checkout -b new_branch
pushするとリモートに同名のブランチが作成される
git push
トラッキングブランチの設定をする
git branch --set-upstream-to=origin/リモートブランチ ローカルブランチ
以下調整中
git log --pretty=format:"[%ad] %h %an : %s"
git checkout-index -a -f --prefix=export/