Module: Fcoin::Endpoint::Orders

Includes:
Utility
Included in:
Fcoin::Endpoint
Defined in:
lib/fcoin/endpoint/orders.rb

Instance Method Summary collapse

Instance Method Details

#cancel_order(order_id:) ⇒ Hash or JSON

Note:

This method can not be invoked without authentication.

Cancel order.

curl: POST api.fcoin.com/v2/orders/$order_id/submit-cancel

Examples:

cancel order specified by order_id.

client = Fcoin::Client.new(api_key: ENV['FCOIN_API_KEY'], secret_key: ENV['FCOIN_SECRET_KEY'])
puts client.cancel_order(order_id: "nMEC_VrW0LYlP4iCcWzmdL50jFrvNWZoaQxvZSjeUSA=") #=> {"status":0}

Parameters:

  • order_id (String)

Returns:

  • (Hash or JSON)

Raises:

  • (ArgumentError)

    If the order_id does not have.

See Also:



106
107
108
# File 'lib/fcoin/endpoint/orders.rb', line 106

def cancel_order(order_id:)
  post("orders/#{order_id}/submit-cancel")
end

#create_order_limit(symbol:, side:, price:, amount:) ⇒ Hash or JSON

Note:

This method can not be invoked without authentication.

Create limit order.

curl: POST api.fcoin.com/v2/orders

Examples:

Create an order to sell 0.010eth at a price of 1000usdt.

client = Fcoin::Client.new(api_key: ENV['FCOIN_API_KEY'], secret_key: ENV['FCOIN_SECRET_KEY'])
puts client.create_order_limit(symbol: :ethusdt, side: :sell, price: 1000, amount: 0.001) #=> {"status":0,"data":"R0moy92q4Qaf_G*********wwJM2bz_Zyacp-Ek8="}'

Parameters:

  • symbol (String or Symbol)

    Transaction of pair

  • side (String or Symbol)

    Direction of the transaction

  • type (String or Symbol)

    Order type.

  • price (Float)
  • amount (Float)

Returns:

  • (Hash or JSON)

    Returns receipt contains order_id.

Raises:

  • (ArgumentError)

    If the symbol or side or type or price or amount does not have.

  • (InvalidValueError)

    If symbol or side or type or price or amount is invalid.

See Also:



29
30
31
32
33
34
35
36
37
38
# File 'lib/fcoin/endpoint/orders.rb', line 29

def create_order_limit(symbol:, side:, price:, amount:)
  payload = { symbol: symbol, side: side, type: :limit, price: price, amount: amount }
  validator = Fcoin::Validator.new(payload.merge(method_name: __method__))
  if skip_validation || validator.valid?
    valid_payload = sort_payload(payload)
    post('orders', true, valid_payload)
  else
    raise InvalidValueError.new(validator.messages)
  end
end

#order_list(symbol:, states:, page_before: nil, page_after: nil, per_page: 20) ⇒ Hash or JSON

Note:

This method can not be invoked without authentication.

Get order list.

curl: GET api.fcoin.com/v2/orders

Examples:

get the canceled order list of ethusdt limit 20 per page.

client = Fcoin::Client.new(api_key: ENV['FCOIN_API_KEY'], secret_key: ENV['FCOIN_SECRET_KEY'])
puts client.order_list(symbol: :ethusdt, states: :canceled, page_before: nil, page_after: nil, per_page: 20) #=> {"status":0,"data":[{"id":"L7rbALEIoI0ymo3uOXBF4gT4BlyTxgHhGoZjvptIv2U=","symbol":"ethusdt","amount":"0.001000000000000000","price":"1000.000000000000000000","created_at":1531714218130,"type":"limit","side":"sell","filled_amount":"0.000000000000000000","executed_value":"0.000000000000000000","fill_fees":"0.000000000000000000","source":"api","state":"canceled"},{"id":"32ZZCBEpPz2J9oFIJ4RMTIbypltjrVD9PAdYxQTHhUE=","symbol":"ethusdt","amount":"0.001000000000000000","price":"1000.000000000000000000","created_at":1531714092732,"type":"limit","side":"sell","filled_amount":"0.000000000000000000","executed_value":"0.000000000000000000","fill_fees":"0.000000000000000000","source":"api","state":"canceled"},{"id":"VotO2IKI2opgyKRd1lhR5bYj9zNZ398IW85gcBNPisU=","symbol":"ethusdt","amount":"0.001000000000000000","price":"1000.000000000000000000","created_at":1531712709955,"type":"limit","side":"sell","filled_amount":"0.000000000000000000","executed_value":"0.000000000000000000","fill_fees":"0.000000000000000000","source":"api","state":"canceled"},{"id":"tYH6LczJxaVe_WhsLOzOk4YM53hK2q169nYn9ReiwGM=","symbol":"ethusdt","amount":"0.001000000000000000","price":"1000.000000000000000000","created_at":1531675732267,"type":"limit","side":"sell","filled_amount":"0.000000000000000000","executed_value":"0.000000000000000000","fill_fees":"0.000000000000000000","source":"web","state":"canceled"},{"id":"U50WtZkmIh_bbuVKoipAMayCIy0A7qk4hBLxpDvKdPk=","symbol":"ethusdt","amount":"0.025800000000000000","price":"491.100000000000000000","created_at":1529665880201,"type":"limit","side":"buy","filled_amount":"0.000000000000000000","executed_value":"0.000000000000000000","fill_fees":"0.000000000000000000","source":"web","state":"canceled"}]}

Parameters:

  • symbol (String or Symbol)

    Transaction of pair.

  • states (String or Symbol)

    Order states. states must be incldued in [submitted, partial_filled, canceled, partial_canceled, filled, pending_cancel]

  • page_before (Integer) (defaults to: nil)

    Query order before page number.

  • page_after (Integer) (defaults to: nil)

    Query order after page number.

  • per_page (Integer) (defaults to: 20)

    Order quantity per page. default is 20.

Returns:

  • (Hash or JSON)

    Returns order list.

Raises:

  • (ArgumentError)

    If the symbol or states or per_page does not have.

  • (InvalidValueError)

    If symbol or states or per_page is invalid.

See Also:



60
61
62
63
64
65
66
67
68
69
# File 'lib/fcoin/endpoint/orders.rb', line 60

def order_list(symbol:, states:, page_before: nil, page_after: nil, per_page: 20)
  params = { symbol: symbol, states: states.to_s, before: page_before, after: page_after, limit: per_page }
  validator = Fcoin::Validator.new(params.merge(method_name: __method__))
  if skip_validation || validator.valid?
    valid_params = sort_params(params)
    get('orders', true, valid_params)
  else
    raise InvalidValueError.new(validator.messages)
  end
end

#order_match_results(order_id:) ⇒ Hash or JSON Also known as: order_transaction

Note:

This method can not be invoked without authentication.

Query the transaction record for the specified by order_id.

curl: GET api.fcoin.com/v2/orders/$order_id/match-results

Examples:

Query the transaction record for the specified by order_id.

client = Fcoin::Client.new(api_key: ENV['FCOIN_API_KEY'], secret_key: ENV['FCOIN_SECRET_KEY'])
puts client.order_match_results(order_id: "kW3cRiXIGHG-cHNdter*********qfoMzbeHEQcqp4=") #=> {"status":0,"data":[{"price": "1000","fill_fees": "0.00010000000000000","filled_amount": "0.00500000000000000","side": "buy","type": "limit","created_at": 1531734385085}]}

Parameters:

  • order_id (String)

Returns:

  • (Hash or JSON)

    Returns transaction record for the specified by order_id.

Raises:

  • (ArgumentError)

    If the order_id does not have.

See Also:



125
126
127
# File 'lib/fcoin/endpoint/orders.rb', line 125

def order_match_results(order_id:)
  get("orders/#{order_id}/match-results")
end

#reference_order(order_id:) ⇒ Hash or JSON Also known as: order

Note:

This method can not be invoked without authentication.

Query order.

curl: GET api.fcoin.com/v2/orders/$order_id

Examples:

query order specified by order_id.

client = Fcoin::Client.new(api_key: ENV['FCOIN_API_KEY'], secret_key: ENV['FCOIN_SECRET_KEY'])
puts client.reference_order(order_id: "L7rbALEIoI0ymo3uOXBF4gT4Bl********jvptIv2U=") #=> {"status":0,"data":{"id":"L7rbALEIoI0ymo3uOXBF4gT4BlyTxgHhGoZjvptIv2U=","symbol":"ethusdt","amount":"0.001000000000000000","price":"1000.000000000000000000","created_at":1531714218130,"type":"limit","side":"sell","filled_amount":"0.000000000000000000","executed_value":"0.000000000000000000","fill_fees":"0.000000000000000000","source":"api","state":"canceled"}}

Parameters:

  • order_id (String)

Returns:

  • (Hash or JSON)

    Returns order specified by order_id.

Raises:

  • (ArgumentError)

    If the order_id does not have.

See Also:



86
87
88
# File 'lib/fcoin/endpoint/orders.rb', line 86

def reference_order(order_id:)
  get("orders/#{order_id}")
end