module Tradecow::Future
Public Class Methods
contract_account_info(symbol=nil)
click to toggle source
# File lib/tradecow/future.rb, line 67 def self.contract_account_info 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)
click to toggle source
# 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)
click to toggle source
# 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