Module: Tradecow::Spot
- Defined in:
- lib/tradecow/spot.rb
Class Method Summary collapse
- .bids ⇒ Object
- .depth(target) ⇒ Object
- .place_order(coin, coin_with_unit, type, amount = nil) ⇒ Object
Class Method Details
.bids ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/tradecow/spot.rb', line 14 def self.bids begin depth.dig("tick", "bids") rescue retry end end |
.depth(target) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/tradecow/spot.rb', line 6 def self.depth target begin Watchcow::MarketDepth.call(params: {symbol: target}, k: 'spot') rescue retry end end |
.place_order(coin, coin_with_unit, type, amount = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/tradecow/spot.rb', line 30 def self.place_order coin, coin_with_unit, type, amount=nil # 市价单,买amount是usdt,卖amount是币数量 # account-id string true NA 账户 ID,取值参考 GET /v1/account/accounts。现货交易使用 ‘spot’ 账户的 account-id;逐仓杠杆交易,请使用 ‘margin’ 账户的 account-id;全仓杠杆交易,请使用 ‘super-margin’ 账户的 account-id # symbol string true NA 交易对,即btcusdt, ethbtc...(取值参考GET /v1/common/symbols) # type string true NA 订单类型,包括buy-market, sell-market, buy-limit, sell-limit, buy-ioc, sell-ioc, buy-limit-maker, sell-limit-maker(说明见下文), buy-stop-limit, sell-stop-limit, buy-limit-fok, sell-limit-fok, buy-stop-limit-fok, sell-stop-limit-fok # amount string true NA 订单交易量(市价买单为订单交易额) # # Sell # Tradecow::Spot.place_order('btc','btcusdt','sell-market', 0.0001) binding.pry if amount.nil? group = Tradecow::Account.balances('spot').select{|x| x['currency'] == coin} trade = group.select{|x| x['type'] == 'trade'}.first['balance'].to_d rescue 0 frozen = group.select{|x| x['type'] == 'frozen'}.first['balance'].to_d rescue 0 amount = (trade - frozen).truncate(8).to_s end path = "/v1/order/orders/place" = { "account-id" => Tradecow::Account.ids('spot')['id'], "symbol" => coin_with_unit, "type" => type, "amount" => amount } req_url = Tradecow::Network.url('POST', path, ) begin r = HTTParty.post(req_url, body: .to_json, headers: {"Content-Type" => "application/json"}).parsed_response r rescue Exception => e puts "#{e}" end end |