Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

darwinex

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

darwinex

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Darwinex

Build Status

Ruby client for the Darwinex API.

Installation

Gemfile

gem 'darwinex'

Install

$ gem install darwinex

Usage

Require the client:

require 'darwinex/client'

Initialise the client:

client = Darwinex::Client.new(
  consumer_key: "<consumer key>",
  consumer_secret: "<consumer secret>"
)

If you would like to use a custom logger:

client = Darwinex::Client.new(
  consumer_key: "<consumer key>",
  consumer_secret: "<consumer secret>",
  logger: Logger.new(STDOUT)
)

If you would like to configure the maximum number of API call retries:

client = Darwinex::Client.new(
  consumer_key: "<consumer key>",
  consumer_secret: "<consumer secret>",
  max_retries: 10 # Default: 5
)

Before you use the client, you must generate a new access token for the client to use:

resp = client.refresh_access_token("<refresh token>")

refresh_token = resp["refresh_token"]

The client will now be ready for use.

You will need to persist the refresh token returned by .refresh_access_token - you will need it the next time you want to generate a new access token.

Examples

Investor Accounts

client.list_investor_accounts
client.investor_account("<account id>")
client.investor_account("<account id>").summary
client.investor_account("<account id>").leverage
client.investor_account("<account id>").update_leverage(3)
buy_order = { long: "eurusd" }

client.investor_account("<account id>").create_buy_order(buy_order)
sell_order = { long: "eurusd" }

client.investor_account("<account id>").create_sell_order(sell_order)
# Will create a stopout for all products
client.investor_account("<account id>").create_stopout
product_name = 'DWC.4.20'

client.investor_account("<account id>").create_stopout(product_name)
order = {
  'amount' => 215.15,
  'productName' => 'DWC.4.20',
  'quote' => 20.23,
  'side' => 'BUY',
  'type' => 'LESS_THAN_EQUAL',
  'thresholdParameters' => {
    'quoteStopLoss' => 10.05,
    'quoteTakeProfit' => 250.1
  }
}

client.investor_account("<account id>").create_conditional_order(order)
order_id = 123

order = {
  'amount' => 215.15,
  'productName' => 'DWC.4.20',
  'quote' => 20.23,
  'side' => 'BUY',
  'type' => 'LESS_THAN_EQUAL',
  'thresholdParameters' => {
    'quoteStopLoss' => 10.05,
    'quoteTakeProfit' => 250.1
  }
}

client.investor_account("<account id>").update_conditional_order(order_id, order)
order_id = 123

client.investor_account("<account id>").delete_conditional_order(order_id)
client.investor_account("<account id>").current_positions
product_name = 'DWC.4.20'

client.investor_account("<account id>").current_positions(product_name)
client.investor_account("<account id>").executed_orders
options = {
  product_name: 'DWC.4.20',
  page: 2,
  per_page: 10
}

client.investor_account("<account id>").executed_orders(options)
order_id = 'DWC.4.20'

client.investor_account("<account id>").order(order_id)
client.investor_account("<account id>").performance_fees
options = {
  page: 2,
  per_page: 10
}

client.investor_account("<account id>").performance_fees(options)
product_name = 'DWC.4.20'

client.investor_account("<account id>").product_performance_fees(product_name)
trade_status = 'open'

client.investor_account("<account id>").trades(trade_status)
trade_status = 'open'

options = {
  product_name: 'DWC.4.20',
  page: 2,
  per_page: 10
}

client.investor_account("<account id>").trades(trade_status, options)
trade_id = 'DWC.4.20'

client.investor_account("<account id>").trade(trade_id)

Products

client.list_products
client.product("<product name>")
client.product("<product name>").candles(from: epoch_timestamp, to: epoch_timestamp)
client.product("<product name>").candles(resolution: '1m', from: epoch_timestamp, to: epoch_timestamp)
client.product("<product name>").dxscore
client.product("<product name>").badges
client.product("<product name>").close_strategy
client.product("<product name>").duration_consistency
client.product("<product name>").experience
client.product("<product name>").losing_consistency
client.product("<product name>").market_correlation
client.product("<product name>").performance
client.product("<product name>").open_strategy
client.product("<product name>").capacity
client.product("<product name>").quotes
client.product("<product name>").quotes(from: epoch_timestamp, to: epoch_timestamp)
client.product("<product name>").risk_stability
client.product("<product name>").winning_consistency
client.product("<product name>").order_divergence
client.product("<product name>").return_divergence
client.product("<product name>").monthly_divergence
client.product("<product name>").status
client.product("<product name>").scores
badge = "EXPERIENCE"

client.product("<product name>").scores(badge)

Exceptions

All exceptions extend the base exception class Darwinex::Error.

Invalid Credentials

Raised when the consumer key or secret passed to the client are not valid.

Throttled

Raised when you exceed the API rate limit.

The client will automatically back off and retry throttled API responses until the max retries limit is hit.

Refresh Token Expired

Raised when Darwinex::Client#refresh_access_token is called with a refresh token that has expired.

Refresh tokens are only valid for a short period of time, after which they expire. As such, it's important your application regularly refreshes the access tokens to stop them from expiring.

In order to resolve this issue, you must go to the Darwinex Web console and issue a new refresh token.

FAQs

Package last updated on 01 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc