=begin
#BitMEX API

### REST API for the BitMEX Trading Platform  _If you are building automated tools, please subscribe to the_ _[BitMEX API RSS Feed](https://blog.bitmex.com/api_announcement/feed/) for changes. The feed will be updated_ _regularly and is the most reliable way to get downtime and update announcements._  [View Changelog](/app/apiChangelog)  -  #### Getting Started  Base URI: [https://www.bitmex.com/api/v1](/api/v1)  ##### Fetching Data  All REST endpoints are documented below. You can try out any query right from this interface.  Most table queries accept `count`, `start`, and `reverse` params. Set `reverse=true` to get rows newest-first.  Additional documentation regarding filters, timestamps, and authentication is available in [the main API documentation](/app/restAPI).  _All_ table data is available via the [Websocket](/app/wsAPI). We highly recommend using the socket if you want to have the quickest possible data without being subject to ratelimits.  ##### Return Types  By default, all data is returned as JSON. Send `?_format=csv` to get CSV data or `?_format=xml` to get XML data.  ##### Trade Data Queries  _This is only a small subset of what is available, to get you started._  Fill in the parameters and click the `Try it out!` button to try any of these queries.  - [Pricing Data](#!/Quote/Quote_get)  - [Trade Data](#!/Trade/Trade_get)  - [OrderBook Data](#!/OrderBook/OrderBook_getL2)  - [Settlement Data](#!/Settlement/Settlement_get)  - [Exchange Statistics](#!/Stats/Stats_history)  Every function of the BitMEX.com platform is exposed here and documented. Many more functions are available.  ##### Swagger Specification  [⇩ Download Swagger JSON](swagger.json)  -  ## All API Endpoints  Click to expand a section. 

OpenAPI spec version: 1.2.0
Contact: support@bitmex.com
Generated by: https://github.com/swagger-api/swagger-codegen.git
Swagger Codegen version: 2.4.42-SNAPSHOT

=end

require 'date'

module SwaggerClient
  # Placement, Cancellation, Amending, and History
  class Order
    attr_accessor :order_id

    attr_accessor :cl_ord_id

    attr_accessor :cl_ord_link_id

    attr_accessor :account

    attr_accessor :symbol

    attr_accessor :side

    attr_accessor :order_qty

    attr_accessor :price

    attr_accessor :display_qty

    attr_accessor :stop_px

    attr_accessor :peg_offset_value

    attr_accessor :peg_price_type

    attr_accessor :currency

    attr_accessor :settl_currency

    attr_accessor :ord_type

    attr_accessor :time_in_force

    attr_accessor :exec_inst

    attr_accessor :contingency_type

    attr_accessor :ord_status

    attr_accessor :triggered

    attr_accessor :working_indicator

    attr_accessor :ord_rej_reason

    attr_accessor :leaves_qty

    attr_accessor :cum_qty

    attr_accessor :avg_px

    attr_accessor :text

    attr_accessor :transact_time

    attr_accessor :timestamp

    # Attribute mapping from ruby-style variable name to JSON key.
    def self.attribute_map
      {
        :'order_id' => :'orderID',
        :'cl_ord_id' => :'clOrdID',
        :'cl_ord_link_id' => :'clOrdLinkID',
        :'account' => :'account',
        :'symbol' => :'symbol',
        :'side' => :'side',
        :'order_qty' => :'orderQty',
        :'price' => :'price',
        :'display_qty' => :'displayQty',
        :'stop_px' => :'stopPx',
        :'peg_offset_value' => :'pegOffsetValue',
        :'peg_price_type' => :'pegPriceType',
        :'currency' => :'currency',
        :'settl_currency' => :'settlCurrency',
        :'ord_type' => :'ordType',
        :'time_in_force' => :'timeInForce',
        :'exec_inst' => :'execInst',
        :'contingency_type' => :'contingencyType',
        :'ord_status' => :'ordStatus',
        :'triggered' => :'triggered',
        :'working_indicator' => :'workingIndicator',
        :'ord_rej_reason' => :'ordRejReason',
        :'leaves_qty' => :'leavesQty',
        :'cum_qty' => :'cumQty',
        :'avg_px' => :'avgPx',
        :'text' => :'text',
        :'transact_time' => :'transactTime',
        :'timestamp' => :'timestamp'
      }
    end

    # Attribute type mapping.
    def self.swagger_types
      {
        :'order_id' => :'String',
        :'cl_ord_id' => :'String',
        :'cl_ord_link_id' => :'String',
        :'account' => :'Integer',
        :'symbol' => :'String',
        :'side' => :'String',
        :'order_qty' => :'Integer',
        :'price' => :'Float',
        :'display_qty' => :'Integer',
        :'stop_px' => :'Float',
        :'peg_offset_value' => :'Float',
        :'peg_price_type' => :'String',
        :'currency' => :'String',
        :'settl_currency' => :'String',
        :'ord_type' => :'String',
        :'time_in_force' => :'String',
        :'exec_inst' => :'String',
        :'contingency_type' => :'String',
        :'ord_status' => :'String',
        :'triggered' => :'String',
        :'working_indicator' => :'BOOLEAN',
        :'ord_rej_reason' => :'String',
        :'leaves_qty' => :'Integer',
        :'cum_qty' => :'Integer',
        :'avg_px' => :'Float',
        :'text' => :'String',
        :'transact_time' => :'DateTime',
        :'timestamp' => :'DateTime'
      }
    end

    # Initializes the object
    # @param [Hash] attributes Model attributes in the form of hash
    def initialize(attributes = {})
      return unless attributes.is_a?(Hash)

      # convert string to symbol for hash key
      attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }

      if attributes.has_key?(:'orderID')
        self.order_id = attributes[:'orderID']
      end

      if attributes.has_key?(:'clOrdID')
        self.cl_ord_id = attributes[:'clOrdID']
      end

      if attributes.has_key?(:'clOrdLinkID')
        self.cl_ord_link_id = attributes[:'clOrdLinkID']
      end

      if attributes.has_key?(:'account')
        self.account = attributes[:'account']
      end

      if attributes.has_key?(:'symbol')
        self.symbol = attributes[:'symbol']
      end

      if attributes.has_key?(:'side')
        self.side = attributes[:'side']
      end

      if attributes.has_key?(:'orderQty')
        self.order_qty = attributes[:'orderQty']
      end

      if attributes.has_key?(:'price')
        self.price = attributes[:'price']
      end

      if attributes.has_key?(:'displayQty')
        self.display_qty = attributes[:'displayQty']
      end

      if attributes.has_key?(:'stopPx')
        self.stop_px = attributes[:'stopPx']
      end

      if attributes.has_key?(:'pegOffsetValue')
        self.peg_offset_value = attributes[:'pegOffsetValue']
      end

      if attributes.has_key?(:'pegPriceType')
        self.peg_price_type = attributes[:'pegPriceType']
      end

      if attributes.has_key?(:'currency')
        self.currency = attributes[:'currency']
      end

      if attributes.has_key?(:'settlCurrency')
        self.settl_currency = attributes[:'settlCurrency']
      end

      if attributes.has_key?(:'ordType')
        self.ord_type = attributes[:'ordType']
      end

      if attributes.has_key?(:'timeInForce')
        self.time_in_force = attributes[:'timeInForce']
      end

      if attributes.has_key?(:'execInst')
        self.exec_inst = attributes[:'execInst']
      end

      if attributes.has_key?(:'contingencyType')
        self.contingency_type = attributes[:'contingencyType']
      end

      if attributes.has_key?(:'ordStatus')
        self.ord_status = attributes[:'ordStatus']
      end

      if attributes.has_key?(:'triggered')
        self.triggered = attributes[:'triggered']
      end

      if attributes.has_key?(:'workingIndicator')
        self.working_indicator = attributes[:'workingIndicator']
      end

      if attributes.has_key?(:'ordRejReason')
        self.ord_rej_reason = attributes[:'ordRejReason']
      end

      if attributes.has_key?(:'leavesQty')
        self.leaves_qty = attributes[:'leavesQty']
      end

      if attributes.has_key?(:'cumQty')
        self.cum_qty = attributes[:'cumQty']
      end

      if attributes.has_key?(:'avgPx')
        self.avg_px = attributes[:'avgPx']
      end

      if attributes.has_key?(:'text')
        self.text = attributes[:'text']
      end

      if attributes.has_key?(:'transactTime')
        self.transact_time = attributes[:'transactTime']
      end

      if attributes.has_key?(:'timestamp')
        self.timestamp = attributes[:'timestamp']
      end
    end

    # Show invalid properties with the reasons. Usually used together with valid?
    # @return Array for valid properties with the reasons
    def list_invalid_properties
      invalid_properties = Array.new
      if @order_id.nil?
        invalid_properties.push('invalid value for "order_id", order_id cannot be nil.')
      end

      invalid_properties
    end

    # Check to see if the all the properties in the model are valid
    # @return true if the model is valid
    def valid?
      return false if @order_id.nil?
      true
    end

    # Checks equality by comparing each attribute.
    # @param [Object] Object to be compared
    def ==(o)
      return true if self.equal?(o)
      self.class == o.class &&
          order_id == o.order_id &&
          cl_ord_id == o.cl_ord_id &&
          cl_ord_link_id == o.cl_ord_link_id &&
          account == o.account &&
          symbol == o.symbol &&
          side == o.side &&
          order_qty == o.order_qty &&
          price == o.price &&
          display_qty == o.display_qty &&
          stop_px == o.stop_px &&
          peg_offset_value == o.peg_offset_value &&
          peg_price_type == o.peg_price_type &&
          currency == o.currency &&
          settl_currency == o.settl_currency &&
          ord_type == o.ord_type &&
          time_in_force == o.time_in_force &&
          exec_inst == o.exec_inst &&
          contingency_type == o.contingency_type &&
          ord_status == o.ord_status &&
          triggered == o.triggered &&
          working_indicator == o.working_indicator &&
          ord_rej_reason == o.ord_rej_reason &&
          leaves_qty == o.leaves_qty &&
          cum_qty == o.cum_qty &&
          avg_px == o.avg_px &&
          text == o.text &&
          transact_time == o.transact_time &&
          timestamp == o.timestamp
    end

    # @see the `==` method
    # @param [Object] Object to be compared
    def eql?(o)
      self == o
    end

    # Calculates hash code according to all attributes.
    # @return [Fixnum] Hash code
    def hash
      [order_id, cl_ord_id, cl_ord_link_id, account, symbol, side, order_qty, price, display_qty, stop_px, peg_offset_value, peg_price_type, currency, settl_currency, ord_type, time_in_force, exec_inst, contingency_type, ord_status, triggered, working_indicator, ord_rej_reason, leaves_qty, cum_qty, avg_px, text, transact_time, timestamp].hash
    end

    # Builds the object from hash
    # @param [Hash] attributes Model attributes in the form of hash
    # @return [Object] Returns the model itself
    def build_from_hash(attributes)
      return nil unless attributes.is_a?(Hash)
      self.class.swagger_types.each_pair do |key, type|
        if type =~ /\AArray<(.*)>/i
          # check to ensure the input is an array given that the attribute
          # is documented as an array but the input is not
          if attributes[self.class.attribute_map[key]].is_a?(Array)
            self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
          end
        elsif !attributes[self.class.attribute_map[key]].nil?
          self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
        end # or else data not found in attributes(hash), not an issue as the data can be optional
      end

      self
    end

    # Deserializes the data based on type
    # @param string type Data type
    # @param string value Value to be deserialized
    # @return [Object] Deserialized data
    def _deserialize(type, value)
      case type.to_sym
      when :DateTime
        DateTime.parse(value)
      when :Date
        Date.parse(value)
      when :String
        value.to_s
      when :Integer
        value.to_i
      when :Float
        value.to_f
      when :BOOLEAN
        if value.to_s =~ /\A(true|t|yes|y|1)\z/i
          true
        else
          false
        end
      when :Object
        # generic object (usually a Hash), return directly
        value
      when /\AArray<(?<inner_type>.+)>\z/
        inner_type = Regexp.last_match[:inner_type]
        value.map { |v| _deserialize(inner_type, v) }
      when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
        k_type = Regexp.last_match[:k_type]
        v_type = Regexp.last_match[:v_type]
        {}.tap do |hash|
          value.each do |k, v|
            hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
          end
        end
      else # model
        temp_model = SwaggerClient.const_get(type).new
        temp_model.build_from_hash(value)
      end
    end

    # Returns the string representation of the object
    # @return [String] String presentation of the object
    def to_s
      to_hash.to_s
    end

    # to_body is an alias to to_hash (backward compatibility)
    # @return [Hash] Returns the object in the form of hash
    def to_body
      to_hash
    end

    # Returns the object in the form of hash
    # @return [Hash] Returns the object in the form of hash
    def to_hash
      hash = {}
      self.class.attribute_map.each_pair do |attr, param|
        value = self.send(attr)
        next if value.nil?
        hash[param] = _to_hash(value)
      end
      hash
    end

    # Outputs non-array value in the form of hash
    # For object, use to_hash. Otherwise, just return the value
    # @param [Object] value Any valid value
    # @return [Hash] Returns the value in the form of hash
    def _to_hash(value)
      if value.is_a?(Array)
        value.compact.map { |v| _to_hash(v) }
      elsif value.is_a?(Hash)
        {}.tap do |hash|
          value.each { |k, v| hash[k] = _to_hash(v) }
        end
      elsif value.respond_to? :to_hash
        value.to_hash
      else
        value
      end
    end

  end
end
