概要
Cloud9 で BitMEX のBotをTESTNETで動かすときにはまったので防備録
Cloud9の環境構築
注意点はCost-saving settingをNeverくらい。
PreferenceのPython SupportをPython3に
.bashrcをvimで開く
$ vi ~/.bashrc
にて.bashrcを開き
# User specific aliases and functions
alias python=python27
を
# User specific aliases and functions
alias python=python36
にvimコマンドを以下選んで実行。
key | 内容 |
---|---|
ZZ | 上書き保存し、viを終了 |
:w | 内容を保存 |
:q! | 保存せずに終了 |
.bashrcを閉じる。
ちなみに編集モード、コマンドモードの変更は以下
key | 内容 |
---|---|
i | 挿入モードへ |
ESC | コマンドモードに戻る |
aliasの設定を反映させるため
$ source ~/.bashrc
を実行すると
function
と表示され、aliasが反映される。
pythonコマンドを実行した際にPython3.6を利用するための設定。
$ sudo update-alternatives --config python
で以下が表示されるので
There are 2 programs which provide 'python'.
Selection Command
-----------------------------------------------
*+ 1 /usr/bin/python2.7
2 /usr/bin/python3.6
Enter to keep the current selection[+], or type selection number:
で2と入力する
pythonのバージョン、pipのバージョンが3.6で表示されることを確認
$ python -V
Python 3.6.5
$ pip -V
pip 9.0.3 from /usr/lib/python3.6/dist-packages (python 3.6)
Gitのインストール
$ sudo yum -y update
...
$ sudo yum -y install git
...
$ git --version
git version 2.14.4
GitでClone
$ git clone https://github.com/BitMEX/sample-market-maker
$ cd sample-market-maker
$ sudo pip install -r requirements.txt
$ cp market_maker/_settings_base.py settings.py
$ set BITMEX_KEY=”APIキーのID”
$ set BITMEX_SECRET=”APIキーの秘密鍵”
$ python marketmaker XBTUSD
ここでいろいろエラーがでたので(missing 1 required positional argument: 'ws'等)
pip install bitmex-market-maker
pip install bitmex-ws
をやったらMarket Makerが動いた!
2018-08-20 17:22:39,589 - INFO - ws_thread - Connecting to wss://testnet.bitmex.com/realtime?subscribe=quote:XBTUSD,trade:XBTUSD,instrument,order:XBTUSD,execution:XBTUSD,margin,position
2018-08-20 17:22:39,590 - INFO - ws_thread - Authenticating with API Key.
2018-08-20 17:22:39,591 - INFO - ws_thread - Started thread
2018-08-20 17:22:40,592 - INFO - ws_thread - Connected to WS. Waiting for data images, this may take a moment...
2018-08-20 17:22:40,592 - INFO - ws_thread - Got all market data. Starting.
2018-08-20 17:22:40,592 - INFO - market_maker - Using symbol XBTUSD.
2018-08-20 17:22:40,592 - INFO - market_maker - Order Manager initializing, connecting to BitMEX. Live run: executing real trades.
2018-08-20 17:22:40,592 - INFO - market_maker - Resetting current position. Canceling all existing orders.
2018-08-20 17:22:40,593 - INFO - bitmex - sending req to https://testnet.bitmex.com/api/v1/order: {"filter": "{\"ordStatus.isTerminated\": false, \"symbol\": \"XBTUSD\"}", "count": 500}
2018-08-20 17:22:41,821 - INFO - market_maker - XBTUSD Ticker: Buy: 6432.0, Sell: 6432.5
2018-08-20 17:22:41,821 - INFO - market_maker - Start Positions: Buy: 6400.3, Sell: 6464.2, Mid: 6432.0
2018-08-20 17:22:41,822 - INFO - market_maker - Current XBT Balance: 1.110000
2018-08-20 17:22:41,822 - INFO - market_maker - Current Contract Position: 0
2018-08-20 17:22:41,822 - INFO - market_maker - Contracts Traded This Run: 0
2018-08-20 17:22:41,823 - INFO - market_maker - Total Contract Delta: 0.0000 XBT
2018-08-20 17:22:41,823 - INFO - market_maker - Creating 12 orders:
2018-08-20 17:22:41,823 - INFO - market_maker - Sell 100 @ 6464.0
2018-08-20 17:22:41,824 - INFO - market_maker - Sell 200 @ 6496.5
2018-08-20 17:22:41,824 - INFO - market_maker - Sell 300 @ 6529.0
2018-08-20 17:22:41,824 - INFO - market_maker - Sell 400 @ 6561.5
2018-08-20 17:22:41,825 - INFO - market_maker - Sell 500 @ 6594.5
2018-08-20 17:22:41,825 - INFO - market_maker - Sell 600 @ 6627.5
2018-08-20 17:22:41,825 - INFO - market_maker - Buy 100 @ 6400.5
2018-08-20 17:22:41,825 - INFO - market_maker - Buy 200 @ 6368.5
2018-08-20 17:22:41,826 - INFO - market_maker - Buy 300 @ 6337.0
2018-08-20 17:22:41,826 - INFO - market_maker - Buy 400 @ 6305.5
2018-08-20 17:22:41,826 - INFO - market_maker - Buy 500 @ 6274.0
2018-08-20 17:22:41,827 - INFO - market_maker - Buy 600 @ 6242.5
何かの参考になれば幸いです。
参考情報
AWS Cloud9 でPython3を使うための設定
https://qiita.com/acecrc/items/fb34a12b265122816d4b
よく使う Vim のコマンドまとめ
https://qiita.com/hide/items/5bfe5b322872c61a6896
【BitMEX】自動取引ボットの設定と使い方をわかりやすく解説(sample-market-maker)
https://oboegaki.me/archives/1049
BitMEXWebsocket error #148
https://github.com/BitMEX/sample-market-maker/issues/148
ビットコインでマーケットメーキング
http://blockrabbit.io/marketing-making-with-bitcoin/