Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@MtkN1
Last active June 2, 2019 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MtkN1/9eb91cbf306f10e2396177eaebfdf29f to your computer and use it in GitHub Desktop.
Save MtkN1/9eb91cbf306f10e2396177eaebfdf29f to your computer and use it in GitHub Desktop.
import json
import time
# ①クラスをインポートする
from pybybit import Bybit
if __name__ == '__main__':
# ②インスタンスを生成、パラメーターを設定する
bybit = Bybit(api_key='xxxx',
secret='yyyy', symbol='BTCUSD', ws=True, test=True)
# ③各種メソッドを使用する
# ポジションを取得
position = bybit.get_position()
print('Position ----------------------------------------------------------')
print(json.dumps(position, indent=2))
# 板情報を取得
orderbook_buy = bybit.get_orderbook(side='Buy')
print('Orderbook (Buy) ---------------------------------------------------')
print(orderbook_buy.head(5))
best_buy = float(orderbook_buy.iloc[0]['price'])
# オーダーを送信
print('Sending Order... --------------------------------------------------')
order_resp = bybit.place_active_order(
side='Buy', order_type='Limit', qty=100, price=best_buy - 100, time_in_force='PostOnly')
print(json.dumps(order_resp, indent=2))
order_id = order_resp['result']['order_id'] if order_resp['result'] else None
time.sleep(5.0)
# オーダーをキャンセル
print('Cancel Order... ---------------------------------------------------')
cancel_resp = bybit.cancel_active_order(order_id=order_id)
print(json.dumps(cancel_resp, indent=2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment