<commit_before>require_relative 'market.rb'
require 'net/http'
require 'openssl'
require 'json'

module Bot

  # Zaif Wrapper Class
  # https://corp.zaif.jp/api-docs/
  class Zaif < Market

    def initialize()
      super()
      @name        = "Zaif"
      @api_key     = ENV["ZAIF_KEY"]
      @api_secret  = ENV["ZAIF_SECRET"]
      @url_public  = "https://api.zaif.jp/api/1/"
      @url_private = "https://api.zaif.jp/tapi"
      @nonce = 0;
    end

    #############################################################
    # API for public information
    #############################################################

    # Get ticker information.
    # @return [hash] ticker       
    #   ask: [N] 最良売気配値
    #   bid: [N] 最良買気配値
    #   last: [N] 最近値(?用語要チェック), last price
    #   high: [N] 高値    
    #   low: [N] 安値     
    #   timestamp: [nil]
    #   ltimestamp: [int] ローカルタイムスタンプ
    #   volume: [N] 取引量
    def ticker
      h = get_ssl(@url_public + "ticker/btc_jpy")
      {
        "ask"    => N.new(h["ask"]),
        "bid"    => N.new(h["bid"]),
        "last"   => N.new(h["last"]),
        "high"   => N.new(h["high"]),
        "low"    => N.new(h["low"]),
        # "timestamp" is not supply
        "ltimestamp" => Time.now.to_i,
        "volume" => N.new(h["volume"].to_s),
        "vwap"   => N.new(h["vwap"].to_s) # additional param
      }
    end

    # Get order book.
    # @return [hash] array of market depth
    def depth
      have_key?
      h = get_ssl(@url_public + "depth/btc_jpy")
      {
        "asks" => h["asks"].map{|a,b| [N.new(a), N.new(b.to_s)]}, # to_s でないと誤差が生じる
        "bids" => h["bids"].map{|a,b| [N.new(a), N.new(b.to_s)]}, # to_s でないと誤差が生じる
        "ltimestamp" => Time.now.to_i,
      }
    end

    #############################################################
    # API for private user data and trading
    #############################################################

    # Get account balance
    def balance
      have_key?
      post_ssl(@url_private,
               "get_info",
               {})
    end

    # Bought the amount of Bitcoin at the rate.
    # 指数注文 買い.
    # Abstract Method.
    # @param [N] rate<commit_msg>[fix] remove no needed key check<commit_after>require_relative 'market.rb'
require 'net/http'
require 'openssl'
require 'json'

module Bot

  # Zaif Wrapper Class
  # https://corp.zaif.jp/api-docs/
  class Zaif < Market

    def initialize()
      super()
      @name        = "Zaif"
      @api_key     = ENV["ZAIF_KEY"]
      @api_secret  = ENV["ZAIF_SECRET"]
      @url_public  = "https://api.zaif.jp/api/1/"
      @url_private = "https://api.zaif.jp/tapi"
      @nonce = 0;
    end

    #############################################################
    # API for public information
    #############################################################

    # Get ticker information.
    # @return [hash] ticker       
    #   ask: [N] 最良売気配値
    #   bid: [N] 最良買気配値
    #   last: [N] 最近値(?用語要チェック), last price
    #   high: [N] 高値    
    #   low: [N] 安値     
    #   timestamp: [nil]
    #   ltimestamp: [int] ローカルタイムスタンプ
    #   volume: [N] 取引量
    def ticker
      h = get_ssl(@url_public + "ticker/btc_jpy")
      {
        "ask"    => N.new(h["ask"]),
        "bid"    => N.new(h["bid"]),
        "last"   => N.new(h["last"]),
        "high"   => N.new(h["high"]),
        "low"    => N.new(h["low"]),
        # "timestamp" is not supply
        "ltimestamp" => Time.now.to_i,
        "volume" => N.new(h["volume"].to_s),
        "vwap"   => N.new(h["vwap"].to_s) # additional param
      }
    end

    # Get order book.
    # @return [hash] array of market depth
    def depth
      h = get_ssl(@url_public + "depth/btc_jpy")
      {
        "asks" => h["asks"].map{|a,b| [N.new(a), N.new(b.to_s)]}, # to_s でないと誤差が生じる
        "bids" => h["bids"].map{|a,b| [N.new(a), N.new(b.to_s)]}, # to_s でないと誤差が生じる
        "ltimestamp" => Time.now.to_i,
      }
    end

    #############################################################
    # API for private user data and trading
    #############################################################

    # Get account balance
    def balance
      have_key?
      post_ssl(@url_private,
               "get_info",
               {})
    end

    # Bought the amount of Bitcoin at the rate.
    # 指数注文 買い.
    # Abstract Method.
    # @param [N] rate
{'fraction_non_alphanumeric': 0.256111491889422, 'fraction_numerical': 0.0009138679460817912, 'mean_word_length': 2.212032281731475, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '688428', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1626, 'n_words': 317}