Module: Tradecow::Future

Defined in:
lib/tradecow/future.rb

Class Method Summary collapse

Class Method Details

.contract_account_info(symbol = nil) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/tradecow/future.rb', line 67

def self. symbol=nil
  # btc, eth, ...
  path = "/api/v1/contract_account_info"
  options = symbol.nil? ? nil : {symbol: symbol.upcase}
  req_url = Tradecow::Network.dm_url('POST', path, options)
  i = 0
  begin
    HTTParty.post(req_url,
      body: options.to_json,
      headers: {"Content-Type" => "application/json"})
  rescue Exception => e
    puts "#{e}"
    i += 1
    if i <= 3
      puts 'Retrying'
      retry
    end
  end
end

.contract_order(code, volume, direction, offset, order_price_type) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/tradecow/future.rb', line 6

def self.contract_order code, volume, direction, offset, order_price_type
  # order_price_type
  # 订单报价类型
  # "limit":限价,"opponent":对手价 
  # "post_only":只做maker单,post only下单只受用户持仓数量限制,"optimal_5":最优5档
  # "optimal_10":最优10档
  # "optimal_20":最优20档
  # "ioc":IOC订单
  # "fok":FOK订单, "opponent_ioc": 对手价-IOC下单
  # "optimal_5_ioc":最优5档-IOC下单
  # "optimal_10_ioc":最优10档-IOC下单
  # "optimal_20_ioc":最优20档-IOC下单,"opponent_fok": 对手价-FOK下单
  # "optimal_5_fok":最优5档-FOK下单
  # "optimal_10_fok":最优10档-FOK下单
  # "optimal_20_fok":最优20档-FOK下单
  # 开多:买入开多(direction用buy、offset用open)
  # 平多:卖出平多(direction用sell、offset用close)
  # 开空:卖出开空(direction用sell、offset用open)
  # 平空:买入平空(direction用buy、offset用close)
  # Tradecow::Future.contract_order 'ltc210924', 100, 'buy', 'close', 'optimal_20'
  # Volume 张数
  path = "/api/v1/contract_order"
  options = {
    contract_code: code.upcase,
    volume: volume,
    direction: direction,
    offset: offset,
    order_price_type: order_price_type
  }
  req_url = Tradecow::Network.dm_url('POST', path, options)
  begin
    HTTParty.post(req_url,body: options.to_json,headers: {"Content-Type" => "application/json"}).parsed_response
  rescue Exception => e
    puts "#{e}"
  end
end

.contract_position_info(symbol = nil) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/tradecow/future.rb', line 43

def self.contract_position_info symbol=nil
  path = '/api/v1/contract_position_info'
  options = symbol.nil? ? nil : {symbol: symbol.upcase}
  req_url = Tradecow::Network.dm_url('POST', path, options)
  i = 0
  begin
    r = HTTParty.post(req_url, body: options.to_json, headers: {"Content-Type" => "application/json"}).parsed_response
    json_r = JSON.parse r
    if json_r.dig('status') == 'error'
      puts "Failed, msg: #{json_r.dig('err-msg')}"
    else
      puts 'Unknown response: '
    end
    r
  rescue Exception => e
    puts "#{e}"
    i += 1
    if i <= 3
      puts 'Retrying'
      retry
    end
  end
end