module Kucoin::Rest::Private::Trading

Public Instance Methods

active_orders(symbol, type: :buy, options: {}) click to toggle source
# File lib/kucoin/rest/private/trading.rb, line 53
def active_orders(symbol, type: :buy, options: {})
  options.merge!(authenticate: true)
  
  params    =   {
    symbol: symbol.to_s.upcase,
    type:   type.to_s.upcase
  }
  
  response  =   get("/order/active", params: params, options: options)&.fetch("data", [])
  ::Kucoin::Models::Order.parse(response) if response
end
active_orders_map(symbol, type: :buy, options: {}) click to toggle source
# File lib/kucoin/rest/private/trading.rb, line 65
def active_orders_map(symbol, type: :buy, options: {})
  options.merge!(authenticate: true)
  
  params    =   {
    symbol: symbol.to_s.upcase,
    type:   type.to_s.upcase
  }
  
  response  =   get("/order/active-map", params: params, options: options)&.fetch("data", {})
  ::Kucoin::Models::Order.parse_map(response) if response
end
cancel_all_orders(symbol, type: nil, options: {}) click to toggle source
# File lib/kucoin/rest/private/trading.rb, line 40
def cancel_all_orders(symbol, type: nil, options: {})
  options.merge!(authenticate: true)
  
  payload   =     {
    symbol:   symbol.to_s.upcase,
    type:     type.to_s.upcase
  }
  
  payload.delete_if { |key, value| value.nil? || value.to_s.empty? }
  
  post("/order/cancel-all", data: payload, options: options)&.fetch("success", false)
end
cancel_order(symbol, type: :buy, order_id:, options: {}) click to toggle source
# File lib/kucoin/rest/private/trading.rb, line 29
def cancel_order(symbol, type: :buy, order_id:, options: {})
  options.merge!(authenticate: true)
  
  payload   =     {
    orderOid: order_id,
    type:     type.to_s.upcase
  }
  
  post("/#{symbol}/cancel-order", data: payload, options: options)&.fetch("success", false)
end
create_buy_order(symbol, price:, amount:, options: {}) click to toggle source
# File lib/kucoin/rest/private/trading.rb, line 6
def create_buy_order(symbol, price:, amount:, options: {})
  create_order(symbol, type: :buy, price: price, amount: amount, options: options)
end
create_order(symbol, type: :buy, price:, amount:, options: {}) click to toggle source
# File lib/kucoin/rest/private/trading.rb, line 14
def create_order(symbol, type: :buy, price:, amount:, options: {})
  options.merge!(authenticate: true)

  payload   =   {
    symbol: symbol.to_s.upcase,
    type:   type.to_s.upcase,
    price:  price,
    amount: amount
  }
  
  response  =   post("/order", data: payload, options: options)

  return {success: response&.fetch("success", false), id: response&.dig("data", "orderOid")}
end
create_sell_order(symbol, price:, amount:, options: {}) click to toggle source
# File lib/kucoin/rest/private/trading.rb, line 10
def create_sell_order(symbol, price:, amount:, options: {})
  create_order(symbol, type: :sell, price: price, amount: amount, options: options)
end
dealt_orders(symbol, type: nil, before: nil, since: nil, limit: nil, page: nil, options: {}) click to toggle source
# File lib/kucoin/rest/private/trading.rb, line 77
def dealt_orders(symbol, type: nil, before: nil, since: nil, limit: nil, page: nil, options: {})
  options.merge!(authenticate: true)
  
  params    =   {
    symbol: symbol.to_s.upcase,
    type:   type.to_s.upcase,
    before: before,
    since:  since,
    limit:  limit,
    page:   page
  }
  
  params.delete_if { |key, value| value.nil? }
  
  response  =   get("/order/dealt", params: params, options: options)&.dig("data", "datas")
  ::Kucoin::Models::Deal.parse(response) if response
end
order_detail(symbol, order_id:, type: :buy, limit: nil, page: nil, options: {}) click to toggle source
# File lib/kucoin/rest/private/trading.rb, line 111
def order_detail(symbol, order_id:, type: :buy, limit: nil, page: nil, options: {})
  options.merge!(authenticate: true)
  
  params    =   {
    symbol:     symbol.to_s.upcase,
    orderOid:   order_id,
    type:       type.to_s.upcase,
    limit:      limit,
    page:       page
  }
  
  params.delete_if { |key, value| value.nil? }
  
  response  =   get("/order/detail", params: params, options: options)&.fetch("data", {})
  ::Kucoin::Models::Order.new(response) if response
end
symbol_dealt_orders(symbol, type: nil, limit: nil, page: nil, options: {}) click to toggle source
# File lib/kucoin/rest/private/trading.rb, line 95
def symbol_dealt_orders(symbol, type: nil, limit: nil, page: nil, options: {})
  options.merge!(authenticate: true)
  
  params    =   {
    symbol: symbol.to_s.upcase,
    type:   type.to_s.upcase,
    limit:  limit,
    page:   page
  }
  
  params.delete_if { |key, value| value.nil? }
  
  response  =   get("/deal-orders", params: params, options: options)&.dig("data", "datas")
  ::Kucoin::Models::Deal.parse(response) if response
end