Upgrade to Pro — share decks privately, control downloads, hide ads and more …

zaifbotのlt

英 谷口
May 07, 2017
110

 zaifbotのlt

英 谷口

May 07, 2017
Tweet

Transcript

  1. from zaifbot.modules.api.cache import ZaifCurrencyPairs
 
 zaif = ZaifCurrencyPairs()
 print(zaif.all) #ZaifͰѻ͑Δ͢΂ͯͷ௨՟ϖΞ৘ใΛऔಘ


    print(zaif[‘btc_jpy']) #௨՟ϖΞΛࢦఆ͢Ε͹ɺ୯ମͷ৘ใΛऔಘ
 >> [{‘aux_unit_step': 5.0 ʙʙʙ௕͍ͷͰলུʙʙʙ 'currency_pair': ‘btc_jpy'}] >> { >> 'aux_unit_step': 5.0, >> 'event_number': 0, >> 'item_unit_step': 0.0001, >> 'description': 'ϏοτίΠϯɾ೔ຊԁͷऔҾΛߦ͏͜ͱ͕Ͱ͖·͢', >> 'name': 'BTC/JPY', >> 'is_token': False, >> 'aux_unit_min': 5.0, >> 'title': 'BTC/JPY', >> 'item_unit_min': 0.0001, >> 'currency_pair': ‘btc_jpy' >> }
  2. from time import sleep
 from zaifbot.modules.utils import get_current_last_price
 
 print(get_current_last_price('btc_jpy'))

    #औಘ͍ͨ͠currency_pairΛࢦఆ
 print(get_current_last_price('mona_jpy'))
 sleep(30)
 print(get_current_last_price('btc_jpy')) #ϦΞϧλΠϜͰऔಘՄೳ
 print(get_current_last_price('mona_jpy')) >> {'last_price': 165800.0, 'timestamp': '2017-05-02 18:17:55.322019'} >> {'last_price': 15.3, 'timestamp': '2017-05-02 18:17:56.533959’} ʙʙ30ඵޙʙʙ >> {'last_price': 165830.0, 'timestamp': '2017-05-02 18:18:26.415696'} >> {'last_price': 15.3, 'timestamp': '2017-05-02 18:18:22.328562’}
  3. from zaifbot.moving_average import get_sma, get_ema
 
 print(get_sma()) #୯७Ҡಈฏۉઢऔಘ
 print(get_ema()) #ࢦ਺Ҡಈฏۉઢऔಘ

    >> [{'time_stamp': 1408719600, 'close': 53000.0, 'moving_average': 53410.0, 'closed': True}, {'time_stamp': 1408806000, 'close': 53900.0, 'moving_average': 54090.0, 'closed': True}] >> [{'time_stamp': 1408287600, 'close': 47001.0, 'moving_average': 50702.24516926622, 'closed': True}, {'time_stamp': 1408374000, 'close': 50500.0, 'moving_average': 50634.83011284415, 'closed': True}]
  4. from zaifbot.modules.api.wrapper import BotTradeApi
 
 
 key = '࡞੒ͨ͠key'
 secret

    = '࡞੒ͨ͠secret'
 api = BotTradeApi(key, secret)
 trade_result = api.trade(currency_pair='btc_jpy', action='bid', price=180000, amount=2)
 print(trade_result) >> { >> "received": 0.1, >> "remains": 0, >> "order_id": 354323, >> "funds": { >> "jpy": 325, >> "btc": 1.392, >> "mona": 2600 >> } >> }
  5. from zaifbot.modules.api.wrapper import BotTradeApi
 from zaifbot.modules.api.order import AutoCancelClient
 
 


    key = '࡞੒ͨ͠key'
 secret = '࡞੒ͨ͠secret'
 api = BotTradeApi(key, secret)
 trade_result = api.trade(currency_pair='btc_jpy',
 action='bid',
 price=180000,
 amount=2)
 order_id = trade_result['order_id']
 auto_canceler = AutoCancelClient(api)
 # ࠷ऴ஋ஈ͔Β10000ԁ཭ΕͨΒࣗಈͰΦʔμʔऔΓফ͠ auto_canceler.cancel_by_price(order_id, 'btc_jpy', 10000) # ̍࣌ؒ໿ఆ͠ͳ͔ͬͨΒࣗಈͰΦʔμʔऔΓফ͠ auto_canceler.cancel_by_time(order_id, 'btc_jpy', 3600) # ΞΫςΟϒͳࣗಈऔΓফ͠ઃఆͷΦʔμʔҰཡ active_cancel_orders = auto_canceler.get_active_cancel_orders() 
 for active_cancel_order in active_cancel_orders:
 print(active_cancel_order)
 >> {‘id’: ‘583hjf7whj345’, ‘cancel_type’: ‘by_time’ ʙলུʙ} 
 # ࣗಈऔΓফ͠ΛΩϟϯηϧ
 auto_canceler.stop_cancel(active_cancel_orders[0]['id'])