Class: Darwinex::Api::TradingApi

Inherits:
Api
  • Object
show all
Defined in:
lib/darwinex/api/trading_api.rb

Constant Summary collapse

BASE_URI =
'https://api.darwinex.com/trading/1.1'

Instance Method Summary collapse

Methods inherited from Api

#send

Constructor Details

#initialize(config:, logger:) ⇒ TradingApi

Returns a new instance of TradingApi.



14
15
16
17
# File 'lib/darwinex/api/trading_api.rb', line 14

def initialize(config:, logger:)
  super(logger)
  @config = config
end

Instance Method Details

#create_buy_order(account_id, buy_order) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/darwinex/api/trading_api.rb', line 51

def create_buy_order(, buy_order)
  body = {
    body: buy_order.to_json
  }

  send('post', "/investoraccounts/#{}/orders/buy", options.merge(body), max_retries: config.max_retries)
end

#create_conditional_order(account_id, conditional_order_dto) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/darwinex/api/trading_api.rb', line 19

def create_conditional_order(, conditional_order_dto)
  body = {
    body: conditional_order_dto.to_json
  }

  send('post', "/investoraccounts/#{}/conditionalorders", options.merge(body), max_retries: config.max_retries)
end

#create_product_stopout(account_id, product_name) ⇒ Object



71
72
73
# File 'lib/darwinex/api/trading_api.rb', line 71

def create_product_stopout(, product_name)
  send('post', "/investoraccounts/#{}/stopout/#{product_name}", options, max_retries: config.max_retries)
end

#create_sell_order(account_id, sell_order) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/darwinex/api/trading_api.rb', line 59

def create_sell_order(, sell_order)
  body = {
    body: sell_order.to_json
  }

  send('post', "/investoraccounts/#{}/orders/sell", options.merge(body), max_retries: config.max_retries)
end

#create_stopout(account_id) ⇒ Object



67
68
69
# File 'lib/darwinex/api/trading_api.rb', line 67

def create_stopout()
  send('post', "/investoraccounts/#{}/stopout", options, max_retries: config.max_retries)
end

#delete_conditional_order(account_id, conditional_order_id) ⇒ Object



35
36
37
# File 'lib/darwinex/api/trading_api.rb', line 35

def delete_conditional_order(, conditional_order_id)
  send('delete', "/investoraccounts/#{}/conditionalorders/#{conditional_order_id}", options, max_retries: config.max_retries)
end

#get_leverage(account_id) ⇒ Object



39
40
41
# File 'lib/darwinex/api/trading_api.rb', line 39

def get_leverage()
  send('get', "/investoraccounts/#{}/leverage", options, max_retries: config.max_retries)
end

#get_product_market_statusObject



75
76
77
# File 'lib/darwinex/api/trading_api.rb', line 75

def get_product_market_status
  send('get', '/productmarket/status', options, max_retries: config.max_retries)
end

#update_conditional_order(account_id, conditional_order_id, conditional_order_dto) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/darwinex/api/trading_api.rb', line 27

def update_conditional_order(, conditional_order_id, conditional_order_dto)
  body = {
    body: conditional_order_dto.to_json
  }

  send('put', "/investoraccounts/#{}/conditionalorders/#{conditional_order_id}", options.merge(body), max_retries: config.max_retries)
end

#update_leverage(account_id, leverage) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/darwinex/api/trading_api.rb', line 43

def update_leverage(, leverage)
  body = {
    body: { leverage: leverage }.to_json
  }

  send('put', "/investoraccounts/#{}/leverage", options.merge(body), max_retries: config.max_retries)
end