fcoin_ruby_client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/issue_template.md +12 -0
- data/.github/pull_request_template.md +12 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +12 -0
- data/.rubocop_todo.yml +431 -0
- data/.travis.yml +26 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +176 -0
- data/LICENSE.txt +21 -0
- data/README.md +204 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/fcoin +95 -0
- data/bin/setup +8 -0
- data/examples/cli/realtime_api.md +78 -0
- data/examples/cli/rest_api.md +149 -0
- data/examples/cli/setting.md +39 -0
- data/examples/realtime_api.rb +43 -0
- data/examples/rest_api.rb +47 -0
- data/fcoin_ruby_client.gemspec +39 -0
- data/lib/fcoin/api.rb +47 -0
- data/lib/fcoin/authorization.rb +83 -0
- data/lib/fcoin/cli/endpoint/accounts_task.rb +33 -0
- data/lib/fcoin/cli/endpoint/market_task.rb +98 -0
- data/lib/fcoin/cli/endpoint/orders_task.rb +196 -0
- data/lib/fcoin/cli/endpoint/public_task.rb +59 -0
- data/lib/fcoin/cli/realtime/endpoint_task.rb +107 -0
- data/lib/fcoin/cli.rb +77 -0
- data/lib/fcoin/client.rb +7 -0
- data/lib/fcoin/config/custom_settings.yml +171 -0
- data/lib/fcoin/config/settings.yml +10 -0
- data/lib/fcoin/configuration.rb +95 -0
- data/lib/fcoin/connection.rb +33 -0
- data/lib/fcoin/endpoint/accounts.rb +23 -0
- data/lib/fcoin/endpoint/market.rb +91 -0
- data/lib/fcoin/endpoint/orders.rb +171 -0
- data/lib/fcoin/endpoint/public.rb +51 -0
- data/lib/fcoin/endpoint/utility.rb +14 -0
- data/lib/fcoin/endpoint.rb +13 -0
- data/lib/fcoin/error.rb +4 -0
- data/lib/fcoin/faraday/fcoin_formatter.rb +17 -0
- data/lib/fcoin/formatter/base_formatter.rb +8 -0
- data/lib/fcoin/formatter/depth_formatter.rb +33 -0
- data/lib/fcoin/formatter/ticker_formatter.rb +34 -0
- data/lib/fcoin/formatter.rb +38 -0
- data/lib/fcoin/generators/locale.rb +18 -0
- data/lib/fcoin/generators/templates/locale/locales/en.yml +176 -0
- data/lib/fcoin/generators/templates/locale/locales/ja.yml +176 -0
- data/lib/fcoin/generators/templates/locale/locales/zh_CN.yml +176 -0
- data/lib/fcoin/generators/templates/validation/my_settings.yml +171 -0
- data/lib/fcoin/generators/validation.rb +18 -0
- data/lib/fcoin/realtime/api.rb +38 -0
- data/lib/fcoin/realtime/client.rb +9 -0
- data/lib/fcoin/realtime/endpoint.rb +160 -0
- data/lib/fcoin/realtime/formatter/base_formatter.rb +10 -0
- data/lib/fcoin/realtime/formatter/depth_formatter.rb +37 -0
- data/lib/fcoin/realtime/formatter/ticker_formatter.rb +36 -0
- data/lib/fcoin/realtime/formatter.rb +40 -0
- data/lib/fcoin/realtime/wss.rb +113 -0
- data/lib/fcoin/request.rb +73 -0
- data/lib/fcoin/validator/market_validator.rb +60 -0
- data/lib/fcoin/validator/orders/base_validator.rb +96 -0
- data/lib/fcoin/validator/orders/create_order_limit_validator.rb +54 -0
- data/lib/fcoin/validator/orders/create_order_market_validator.rb +95 -0
- data/lib/fcoin/validator/orders/order_list_validator.rb +33 -0
- data/lib/fcoin/validator/orders_validator.rb +69 -0
- data/lib/fcoin/validator/validator_utility.rb +24 -0
- data/lib/fcoin/validator.rb +58 -0
- data/lib/fcoin/version.rb +3 -0
- data/lib/fcoin.rb +11 -0
- metadata +353 -0
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal:true
|
2
|
+
require 'faraday'
|
3
|
+
require 'config'
|
4
|
+
|
5
|
+
module Fcoin
|
6
|
+
module Configuration
|
7
|
+
|
8
|
+
# The adapter that will be used to connect if none is set
|
9
|
+
#
|
10
|
+
# @note The default faraday adapter is Net::HTTP
|
11
|
+
DEFAULT_ADAPTER = ::Faraday.default_adapter
|
12
|
+
|
13
|
+
# The endpoint that will be used to connect if none is set
|
14
|
+
#
|
15
|
+
# @note There is no reason to use any other endpoint at this time
|
16
|
+
DEFAULT_ENDPOINT = 'https://api.fcoin.com/v2/'
|
17
|
+
DEFAULT_WSS_ENDPOINT = 'wss://api.fcoin.com/v2/ws'
|
18
|
+
|
19
|
+
# The user agent that will be sent to the API endpoint if none is set
|
20
|
+
DEFAULT_USER_AGENT = "Fcoin Ruby Gem #{Fcoin::VERSION}".freeze
|
21
|
+
DEFAULT_PROXY = nil
|
22
|
+
DEFAULT_CA_PATH = %x[ openssl version -a | grep OPENSSLDIR | awk '{print $2}'|sed -e 's/\"//g' ].chomp
|
23
|
+
DEFAULT_CA_FILE = "#{DEFAULT_CA_PATH}/ca-certificates.crt"
|
24
|
+
DEFAULT_MIDDLEWARES = []
|
25
|
+
DEFAULT_API_KEY = 'Fcoin API Public Key'
|
26
|
+
DEFAULT_SECRET_KEY = 'Fcoin API Secret Key'
|
27
|
+
DEFAULT_SKIP_VALIDATION = true
|
28
|
+
DEFAULT_VALIDATION_SETTING_PATH = File.expand_path('../config/custom_settings.yml',__FILE__)
|
29
|
+
# support ruby Hash or JSON. default is ruby Hash
|
30
|
+
DEFAULT_FORMAT_TYPE = :hash
|
31
|
+
|
32
|
+
# An array of valid keys in the options hash when configuring a Fcoin::API
|
33
|
+
VALID_OPTIONS_KEYS = [
|
34
|
+
:adapter,
|
35
|
+
:endpoint,
|
36
|
+
:wss_endpoint,
|
37
|
+
:user_agent,
|
38
|
+
:api_key,
|
39
|
+
:secret_key,
|
40
|
+
:proxy,
|
41
|
+
:ca_path,
|
42
|
+
:ca_file,
|
43
|
+
:middlewares,
|
44
|
+
:skip_validation,
|
45
|
+
:validation_setting_path,
|
46
|
+
:format_type
|
47
|
+
].freeze
|
48
|
+
|
49
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
50
|
+
|
51
|
+
# When this module is extended, set all configuration options to their default values and load validation setting path
|
52
|
+
def self.extended(base)
|
53
|
+
base.set_default
|
54
|
+
base.load_validation_setting
|
55
|
+
end
|
56
|
+
|
57
|
+
# Convenience method to allow configuration options to be set in block
|
58
|
+
def configure
|
59
|
+
yield self
|
60
|
+
load_validation_setting
|
61
|
+
end
|
62
|
+
|
63
|
+
# Create a hash of options and their values
|
64
|
+
def options
|
65
|
+
VALID_OPTIONS_KEYS.inject({}) do |option, key|
|
66
|
+
option.merge!(key => send(key))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Load a configuration file to use in the gem that config
|
71
|
+
def load_validation_setting
|
72
|
+
Config.load_and_set_settings([
|
73
|
+
File.expand_path('../config/settings.yml', __FILE__),
|
74
|
+
validation_setting_path
|
75
|
+
])
|
76
|
+
end
|
77
|
+
|
78
|
+
# Set all configuration options to defaults
|
79
|
+
def set_default
|
80
|
+
self.adapter = DEFAULT_ADAPTER
|
81
|
+
self.endpoint = DEFAULT_ENDPOINT
|
82
|
+
self.wss_endpoint = DEFAULT_WSS_ENDPOINT
|
83
|
+
self.user_agent = DEFAULT_USER_AGENT
|
84
|
+
self.api_key = DEFAULT_API_KEY
|
85
|
+
self.secret_key = DEFAULT_SECRET_KEY
|
86
|
+
self.proxy = DEFAULT_PROXY
|
87
|
+
self.ca_path = DEFAULT_CA_PATH
|
88
|
+
self.ca_file = DEFAULT_CA_FILE
|
89
|
+
self.middlewares = DEFAULT_MIDDLEWARES
|
90
|
+
self.skip_validation = DEFAULT_SKIP_VALIDATION
|
91
|
+
self.validation_setting_path = DEFAULT_VALIDATION_SETTING_PATH
|
92
|
+
self.format_type = DEFAULT_FORMAT_TYPE
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
require_relative 'faraday/fcoin_formatter'
|
3
|
+
|
4
|
+
# Scope Fcoin::API
|
5
|
+
module Fcoin
|
6
|
+
module Connection
|
7
|
+
private
|
8
|
+
|
9
|
+
# @private
|
10
|
+
#
|
11
|
+
# To establish a connection using the faraday
|
12
|
+
def connection
|
13
|
+
options = {
|
14
|
+
:headers => { 'Accept' => 'application/json; charset=utf-8', 'User-Agent' => user_agent, 'Content-Type' => 'application/json' },
|
15
|
+
:proxy => proxy,
|
16
|
+
:url => endpoint,
|
17
|
+
:ssl => { :ca_path => ca_path, :ca_file => ca_file }
|
18
|
+
}
|
19
|
+
|
20
|
+
Faraday::Connection.new(options) do |conn|
|
21
|
+
Array(middlewares).each do |middleware|
|
22
|
+
conn.request middleware
|
23
|
+
end
|
24
|
+
conn.request :multipart
|
25
|
+
conn.request :url_encoded
|
26
|
+
conn.request :json
|
27
|
+
|
28
|
+
conn.response :fcoin_formatter
|
29
|
+
conn.adapter(adapter)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Scope Fcoin::API
|
2
|
+
module Fcoin
|
3
|
+
module Endpoint
|
4
|
+
module Accounts
|
5
|
+
# Get account info
|
6
|
+
#
|
7
|
+
# curl: GET https://api.fcoin.com/v2/accounts/balance
|
8
|
+
#
|
9
|
+
# @note This method can not be invoked without authentication.
|
10
|
+
#
|
11
|
+
# @example get account info
|
12
|
+
# client = Fcoin::Client.new(api_key: ENV['FCOIN_API_KEY'], secret_key: ENV['FCOIN_SECRET_KEY'])
|
13
|
+
# puts client.accounts_balance # => {"status":0,"data":[{"currency":"maya","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"gene","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"fres","category":"gpm","available":"60.000000000000000000","frozen":"0.000000000000000000","balance":"60.000000000000000000"},{"currency":"oas","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"tos","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"wte","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"zil","category":"gpm","available":"34.104656029395267656","frozen":"0.000000000000000000","balance":"34.104656029395267656"},{"currency":"omg","category":"innovation","available":"0.220459671644954039","frozen":"0.000000000000000000","balance":"0.220459671644954039"},{"currency":"icx","category":"gpm","available":"1.522982867743779579","frozen":"0.000000000000000000","balance":"1.522982867743779579"},{"currency":"btm","category":"innovation","available":"3.918842444121259336","frozen":"0.000000000000000000","balance":"3.918842444121259336"},{"currency":"ae","category":"gpm","available":"0.027787771125676705","frozen":"0.000000000000000000","balance":"0.027787771125676705"},{"currency":"dagt","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"zrx","category":"innovation","available":"0.027426476746268948","frozen":"0.000000000000000000","balance":"0.027426476746268948"},{"currency":"fota","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"xrp","category":"main","available":"0.043566063515862241","frozen":"0.000000000000000000","balance":"0.043566063515862241"},{"currency":"fbc","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"bnb","category":"innovation","available":"0.038305939165145111","frozen":"0.000000000000000000","balance":"0.038305939165145111"},{"currency":"iic","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"gtc","category":"gpm","available":"0.000000007538065563","frozen":"0.000000000000000000","balance":"0.000000007538065563"},{"currency":"ges","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"vns","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"jac","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"zsc","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"but","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"cofi","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"scl","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"fi","category":"innovation","available":"0.009046890230133252","frozen":"1378.620000000000000000","balance":"1378.629046890230133252"},{"currency":"baic","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"bcv","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"mot","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"wicc","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"vlc","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"fbee","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"icc","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"dht","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"fff","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"mesh","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"ink","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"ruff","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"fuel","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"latx","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"777","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"msc","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"cps","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"dta","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"mof","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"beauty","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"edu","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"dscoin","category":"gpm","available":"10.000000000000000000","frozen":"0.000000000000000000","balance":"10.000000000000000000"},{"currency":"musk","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"smt","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"dpn","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"see","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"ccc","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"sac","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"aidoc","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"18t","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"boc","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"hotc","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"xps","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"lmm","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"rte","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"rnt","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"vpp","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"pnt","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"idxe","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"mxm","category":"gpm","available":"8.000000000000000000","frozen":"0.000000000000000000","balance":"8.000000000000000000"},{"currency":"newos","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"tst","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"mdt","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"sss","category":"gpm","available":"9.000000000000000000","frozen":"0.000000000000000000","balance":"9.000000000000000000"},{"currency":"dcc","category":"gpm","available":"2650.000000000000000000","frozen":"0.000000000000000000","balance":"2650.000000000000000000"},{"currency":"pra","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"banca","category":"gpm","available":"6.000000000000000000","frozen":"0.000000000000000000","balance":"6.000000000000000000"},{"currency":"cccx","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"dscb","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"gus","category":"gpm","available":"2.000000000000000000","frozen":"0.000000000000000000","balance":"2.000000000000000000"},{"currency":"pmd","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"yee","category":"gpm","available":"6.000000000000000000","frozen":"0.000000000000000000","balance":"6.000000000000000000"},{"currency":"dag","category":"gpm","available":"1.000000000000000000","frozen":"0.000000000000000000","balance":"1.000000000000000000"},{"currency":"let","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"datx","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"ocn","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"blz","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"soc","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"at","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"ngot","category":"gpm","available":"1.000000000000000000","frozen":"0.000000000000000000","balance":"1.000000000000000000"},{"currency":"dws","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"tct","category":"gpm","available":"1.830000000000000000","frozen":"0.000000000000000000","balance":"1.830000000000000000"},{"currency":"3db","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"lxt","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"sgcc","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"hpc","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"ifood","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"tbcoin","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"gram","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"arp","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"ait","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"nc","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"aaa","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"cbr","category":"gpm","available":"6.660000000000000000","frozen":"0.000000000000000000","balance":"6.660000000000000000"},{"currency":"sda","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"brm","category":"gpm","available":"0.005000000000000000","frozen":"0.000000000000000000","balance":"0.005000000000000000"},{"currency":"fair","category":"gpm","available":"10.000000000000000000","frozen":"0.000000000000000000","balance":"10.000000000000000000"},{"currency":"ees","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"cit","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"rct","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"xmx","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"ionc","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"drct","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"drink","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"iht","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"ejoy","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"iov","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"mst","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"lovc","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"sec","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"btc","category":"main","available":"0.000156995481988083","frozen":"0.000000000000000000","balance":"0.000156995481988083"},{"currency":"eth","category":"main","available":"0.001177659105993741","frozen":"0.000000000000000000","balance":"0.001177659105993741"},{"currency":"pai","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"bch","category":"main","available":"0.000919246371553010","frozen":"0.000000000000000000","balance":"0.000919246371553010"},{"currency":"show","category":"gpm","available":"600.000000000000000000","frozen":"0.000000000000000000","balance":"600.000000000000000000"},{"currency":"ltc","category":"main","available":"0.001735178376909046","frozen":"0.000000000000000000","balance":"0.001735178376909046"},{"currency":"biz","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"usdt","category":"main","available":"1.542208102053158021","frozen":"0.000000000000000000","balance":"1.542208102053158021"},{"currency":"vct","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"tkt","category":"gpm","available":"0.000000000000000000","frozen":"0.000000000000000000","balance":"0.000000000000000000"},{"currency":"ft","category":"innovation","available":"20.671877714849728410","frozen":"0.000000000000000000","balance":"20.671877714849728410"},{"currency":"zip","category":"innovation","available":"3918.597034485853214932","frozen":"10000.000000000000000000","balance":"13918.597034485853214932"},{"currency":"etc","category":"main","available":"0.382569624756478966","frozen":"0.000000000000000000","balance":"0.382569624756478966"}]}
|
14
|
+
#
|
15
|
+
#
|
16
|
+
# @see https://developer.fcoin.com/zh.html#486f6037ed
|
17
|
+
# @return [Hash or JSON]
|
18
|
+
def accounts_balance
|
19
|
+
get('accounts/balance')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require_relative 'utility'
|
2
|
+
require_relative '../validator'
|
3
|
+
|
4
|
+
# Scope Fcoin::API
|
5
|
+
module Fcoin
|
6
|
+
module Endpoint
|
7
|
+
module Market
|
8
|
+
# Returns ticker info of symbol.
|
9
|
+
#
|
10
|
+
# curl: GET https://api.fcoin.com/v2/market/ticker/$symbol
|
11
|
+
#
|
12
|
+
# @example get ethusdt ticker info
|
13
|
+
# client = Fcoin::Client.new
|
14
|
+
# puts client.market_ticker(symbol: :ethusdt) #=> {"status"=>0, "data"=>{"ticker"=>{"latest_price"=>469.43, "most_recent_trade_vol"=>0.002, "max_buy_price"=>469.43, "max_buy_amount"=>7.6318, "min_sell_price"=>469.44, "min_sell_amount"=>0.0011, "trade_price_yesterday"=>468.75, "highest_price_today"=>472.0, "lowest_price_today"=>461.76, "symbol_base_vol_today"=>44442.419672207, "symbol_base_price_today"=>20784202.592831347}, "type"=>"ticker.ethusdt", "seq"=>100521295}}
|
15
|
+
#
|
16
|
+
#
|
17
|
+
# @see https://developer.fcoin.com/zh.html#ticker
|
18
|
+
# @raise [ArgumentError] If the symbol does not have.
|
19
|
+
# @param symbol [String or Symbol] Transaction pairs
|
20
|
+
# @return [Hash or JSON] Returns ticker info.
|
21
|
+
def market_ticker(symbol:)
|
22
|
+
get("market/ticker/#{symbol}", false)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns depth info of symbol specified by level.
|
26
|
+
#
|
27
|
+
# curl: GET https://api.fcoin.com/v2/market/depth/$level/$symbol
|
28
|
+
#
|
29
|
+
# @example get ethusdt depth info specified by L20 level.
|
30
|
+
# client = Fcoin::Client.new
|
31
|
+
# puts client.market_ticker(symbol: :ethusdt, level: :L20) #=> {"status"=>0, "data"=>{"bids"=>[{"price"=>468.16, "amount"=>0.009}, {"price"=>468.15, "amount"=>0.0077}, {"price"=>468.14, "amount"=>0.02}, {"price"=>468.1, "amount"=>0.3723}, {"price"=>468.09, "amount"=>0.1268}, {"price"=>468.07, "amount"=>0.02}, {"price"=>468.03, "amount"=>0.0025}, {"price"=>468.02, "amount"=>0.01}, {"price"=>468.0, "amount"=>0.0896}, {"price"=>467.97, "amount"=>0.9827}, {"price"=>467.83, "amount"=>0.01}, {"price"=>467.81, "amount"=>0.01}, {"price"=>467.8, "amount"=>0.04}, {"price"=>467.78, "amount"=>0.0146}, {"price"=>467.77, "amount"=>0.0016}, {"price"=>467.76, "amount"=>0.01}, {"price"=>467.75, "amount"=>0.01}, {"price"=>467.74, "amount"=>0.01}, {"price"=>467.73, "amount"=>0.4237}, {"price"=>467.72, "amount"=>0.01}], "asks"=>[{"price"=>468.22, "amount"=>0.7}, {"price"=>468.26, "amount"=>0.7}, {"price"=>468.28, "amount"=>0.5952}, {"price"=>468.56, "amount"=>0.0027}, {"price"=>468.57, "amount"=>0.9921}, {"price"=>468.58, "amount"=>0.06}, {"price"=>468.59, "amount"=>0.3599}, {"price"=>468.6, "amount"=>30.57797087}, {"price"=>468.61, "amount"=>0.01}, {"price"=>468.62, "amount"=>0.003}, {"price"=>468.63, "amount"=>0.005}, {"price"=>468.64, "amount"=>0.03}, {"price"=>468.67, "amount"=>0.0031}, {"price"=>468.68, "amount"=>0.3966}, {"price"=>468.7, "amount"=>0.05}, {"price"=>468.71, "amount"=>0.1}, {"price"=>468.74, "amount"=>0.01}, {"price"=>468.75, "amount"=>0.0021}, {"price"=>468.76, "amount"=>0.0046}, {"price"=>468.77, "amount"=>0.0023}], "ts"=>1532831776008, "seq"=>100535850, "type"=>"depth.L20.ethusdt"}}
|
32
|
+
#
|
33
|
+
#
|
34
|
+
# @see https://developer.fcoin.com/zh.html#50f4407ea4
|
35
|
+
# @raise [ArgumentError] If the symbol or level does not have.
|
36
|
+
# @raise [InvalidValueError] If symbol or level is invalid.
|
37
|
+
# @param symbol [String or Symbol] Transaction pairs
|
38
|
+
# @param level [String or Symbol] Level of depth chart. level must be included in [L20, L40, full].
|
39
|
+
# @return [Hash or JSON] Returns depth info.
|
40
|
+
def market_depth(symbol:, level:)
|
41
|
+
validator = Fcoin::Validator.new(level: level, method_name: __method__)
|
42
|
+
if skip_validation || validator.valid?
|
43
|
+
get("market/depth/#{level}/#{symbol}", false)
|
44
|
+
else
|
45
|
+
raise InvalidValueError.new validator.messages
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Returns trades info of symbol.
|
50
|
+
#
|
51
|
+
# curl: GET https://api.fcoin.com/v2/market/trades/$symbol
|
52
|
+
#
|
53
|
+
# @example get ethusdt trades info.
|
54
|
+
# client = Fcoin::Client.new
|
55
|
+
# puts client.market_trades(symbol: :ethusdt) #=> {"status"=>0, "data"=>[{"amount"=>0.1811, "ts"=>1532832312857, "id"=>100541250000, "side"=>"buy", "price"=>467.95}]}
|
56
|
+
#
|
57
|
+
#
|
58
|
+
# @see https://developer.fcoin.com/zh.html#6477a1394e
|
59
|
+
# @raise [ArgumentError] If the symbol does not have.
|
60
|
+
# @param symbol [String or Symbol] Transaction pairs
|
61
|
+
# @return [Hash or JSON] Returns trades info.
|
62
|
+
def market_trades(symbol:)
|
63
|
+
get("market/trades/#{symbol}", false)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Returns candles info of symbol specified by resolution.
|
67
|
+
#
|
68
|
+
# curl: GET https://api.fcoin.com/v2/market/candles/$resolution/$symbol
|
69
|
+
#
|
70
|
+
# @example get monthly(MN) ethusdt candles info.
|
71
|
+
# client = Fcoin::Client.new
|
72
|
+
# puts client.market_candles(symbol: :ethusdt, resolution: :D1) #=> {"status"=>0, "data"=>[{"open"=>449.1, "close"=>467.67, "high"=>516.09, "quote_vol"=>1403153842.5110748, "id"=>1530374400, "count"=>6058571, "low"=>418.29, "seq"=>10055429000001, "base_vol"=>3042620.012726224}, {"id"=>1527782400, "seq"=>7385778300000, "high"=>555.13, "low"=>406.11, "open"=>523.97, "close"=>449.04, "count"=>20382481, "base_vol"=>28258854.226292703, "quote_vol"=>13579650310.735054}, {"id"=>1525104000, "seq"=>2847062700000, "high"=>582.99, "low"=>559.66, "open"=>563.23, "close"=>575.77, "count"=>4617, "base_vol"=>4159.317883344, "quote_vol"=>2380070.431548223}]}
|
73
|
+
#
|
74
|
+
#
|
75
|
+
# @see https://developer.fcoin.com/zh.html#candle
|
76
|
+
# @raise [ArgumentError] If the symbol or resolution does not have.
|
77
|
+
# @raise [InvalidValueError] If symbol or resolution is invalid.
|
78
|
+
# @param symbol [String or Symbol] Transaction pairs
|
79
|
+
# @param resolution [String or Symbol] period of candles chart. resolution must be included in [M1, M3, M5, M15, M30, H1, H4, H6, D1, W1, MN].
|
80
|
+
# @return [Hash or JSON] Returns candles info.
|
81
|
+
def market_candles(symbol:, resolution:)
|
82
|
+
validator = Fcoin::Validator.new(resolution: resolution, method_name: __method__)
|
83
|
+
if skip_validation || validator.valid?
|
84
|
+
get("market/candles/#{resolution}/#{symbol}", false)
|
85
|
+
else
|
86
|
+
raise InvalidValueError.new validator.messages
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
require_relative 'utility'
|
2
|
+
require_relative '../validator'
|
3
|
+
|
4
|
+
# Scope Fcoin::API
|
5
|
+
module Fcoin
|
6
|
+
module Endpoint
|
7
|
+
module Orders
|
8
|
+
include Utility
|
9
|
+
# Create limit order.
|
10
|
+
#
|
11
|
+
# curl: POST https://api.fcoin.com/v2/orders
|
12
|
+
#
|
13
|
+
# @note This method can not be invoked without authentication.
|
14
|
+
#
|
15
|
+
# @example Create an order to sell 0.010eth at a price of 1000usdt.
|
16
|
+
# client = Fcoin::Client.new(api_key: ENV['FCOIN_API_KEY'], secret_key: ENV['FCOIN_SECRET_KEY'])
|
17
|
+
# puts client.create_order_limit(symbol: :ethusdt, side: :sell, price: 1000, amount: 0.001) #=> {"status":0,"data":"R0moy92q4Qaf_G*********wwJM2bz_Zyacp-Ek8="}'
|
18
|
+
#
|
19
|
+
#
|
20
|
+
# @see https://developer.fcoin.com/zh.html#4a3e521c3b
|
21
|
+
# @raise [ArgumentError] If the symbol or side or type or price or amount does not have.
|
22
|
+
# @raise [InvalidValueError] If symbol or side or type or price or amount is invalid.
|
23
|
+
# @param symbol [String or Symbol] Transaction of pair
|
24
|
+
# @param side [String or Symbol] Direction of the transaction
|
25
|
+
# @param type [String or Symbol] Order type.
|
26
|
+
# @param price [Float]
|
27
|
+
# @param amount [Float]
|
28
|
+
# @return [Hash or JSON] Returns receipt contains order_id.
|
29
|
+
def create_order_limit(symbol:, side:, price:, amount:)
|
30
|
+
payload = { symbol: symbol, side: side, type: :limit, price: price, amount: amount }
|
31
|
+
validator = Fcoin::Validator.new(payload.merge(method_name: __method__))
|
32
|
+
if skip_validation || validator.valid?
|
33
|
+
valid_payload = sort_payload(payload)
|
34
|
+
post('orders', true, valid_payload)
|
35
|
+
else
|
36
|
+
raise InvalidValueError.new(validator.messages)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Get order list.
|
41
|
+
#
|
42
|
+
# curl: GET https://api.fcoin.com/v2/orders
|
43
|
+
#
|
44
|
+
# @note This method can not be invoked without authentication.
|
45
|
+
#
|
46
|
+
# @example get the canceled order list of ethusdt limit 20 per page.
|
47
|
+
# client = Fcoin::Client.new(api_key: ENV['FCOIN_API_KEY'], secret_key: ENV['FCOIN_SECRET_KEY'])
|
48
|
+
# puts client.order_list(symbol: :ethusdt, states: :canceled, page_before: nil, page_after: nil, per_page: 20) #=> {"status":0,"data":[{"id":"L7rbALEIoI0ymo3uOXBF4gT4BlyTxgHhGoZjvptIv2U=","symbol":"ethusdt","amount":"0.001000000000000000","price":"1000.000000000000000000","created_at":1531714218130,"type":"limit","side":"sell","filled_amount":"0.000000000000000000","executed_value":"0.000000000000000000","fill_fees":"0.000000000000000000","source":"api","state":"canceled"},{"id":"32ZZCBEpPz2J9oFIJ4RMTIbypltjrVD9PAdYxQTHhUE=","symbol":"ethusdt","amount":"0.001000000000000000","price":"1000.000000000000000000","created_at":1531714092732,"type":"limit","side":"sell","filled_amount":"0.000000000000000000","executed_value":"0.000000000000000000","fill_fees":"0.000000000000000000","source":"api","state":"canceled"},{"id":"VotO2IKI2opgyKRd1lhR5bYj9zNZ398IW85gcBNPisU=","symbol":"ethusdt","amount":"0.001000000000000000","price":"1000.000000000000000000","created_at":1531712709955,"type":"limit","side":"sell","filled_amount":"0.000000000000000000","executed_value":"0.000000000000000000","fill_fees":"0.000000000000000000","source":"api","state":"canceled"},{"id":"tYH6LczJxaVe_WhsLOzOk4YM53hK2q169nYn9ReiwGM=","symbol":"ethusdt","amount":"0.001000000000000000","price":"1000.000000000000000000","created_at":1531675732267,"type":"limit","side":"sell","filled_amount":"0.000000000000000000","executed_value":"0.000000000000000000","fill_fees":"0.000000000000000000","source":"web","state":"canceled"},{"id":"U50WtZkmIh_bbuVKoipAMayCIy0A7qk4hBLxpDvKdPk=","symbol":"ethusdt","amount":"0.025800000000000000","price":"491.100000000000000000","created_at":1529665880201,"type":"limit","side":"buy","filled_amount":"0.000000000000000000","executed_value":"0.000000000000000000","fill_fees":"0.000000000000000000","source":"web","state":"canceled"}]}
|
49
|
+
#
|
50
|
+
#
|
51
|
+
# @see https://developer.fcoin.com/zh.html#9094989d10
|
52
|
+
# @raise [ArgumentError] If the symbol or states or per_page does not have.
|
53
|
+
# @raise [InvalidValueError] If symbol or states or per_page is invalid.
|
54
|
+
# @param symbol [String or Symbol] Transaction of pair.
|
55
|
+
# @param states [String or Symbol] Order states. states must be incldued in [submitted, partial_filled, canceled, partial_canceled, filled, pending_cancel]
|
56
|
+
# @param page_before [Integer] Query order before page number.
|
57
|
+
# @param page_after [Integer] Query order after page number.
|
58
|
+
# @param per_page [Integer] Order quantity per page. default is 20.
|
59
|
+
# @return [Hash or JSON] Returns order list.
|
60
|
+
def order_list(symbol:, states:, page_before: nil, page_after: nil, per_page: 20)
|
61
|
+
params = { symbol: symbol, states: states.to_s, before: page_before, after: page_after, limit: per_page }
|
62
|
+
validator = Fcoin::Validator.new(params.merge(method_name: __method__))
|
63
|
+
if skip_validation || validator.valid?
|
64
|
+
valid_params = sort_params(params)
|
65
|
+
get('orders', true, valid_params)
|
66
|
+
else
|
67
|
+
raise InvalidValueError.new(validator.messages)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Query order.
|
72
|
+
#
|
73
|
+
# curl: GET https://api.fcoin.com/v2/orders/$order_id
|
74
|
+
#
|
75
|
+
# @note This method can not be invoked without authentication.
|
76
|
+
#
|
77
|
+
# @example query order specified by order_id.
|
78
|
+
# client = Fcoin::Client.new(api_key: ENV['FCOIN_API_KEY'], secret_key: ENV['FCOIN_SECRET_KEY'])
|
79
|
+
# puts client.reference_order(order_id: "L7rbALEIoI0ymo3uOXBF4gT4Bl********jvptIv2U=") #=> {"status":0,"data":{"id":"L7rbALEIoI0ymo3uOXBF4gT4BlyTxgHhGoZjvptIv2U=","symbol":"ethusdt","amount":"0.001000000000000000","price":"1000.000000000000000000","created_at":1531714218130,"type":"limit","side":"sell","filled_amount":"0.000000000000000000","executed_value":"0.000000000000000000","fill_fees":"0.000000000000000000","source":"api","state":"canceled"}}
|
80
|
+
#
|
81
|
+
#
|
82
|
+
# @see https://developer.fcoin.com/zh.html#5faf03be01
|
83
|
+
# @raise [ArgumentError] If the order_id does not have.
|
84
|
+
# @param order_id [String]
|
85
|
+
# @return [Hash or JSON] Returns order specified by order_id.
|
86
|
+
def reference_order(order_id:)
|
87
|
+
get("orders/#{order_id}")
|
88
|
+
end
|
89
|
+
alias :order :reference_order
|
90
|
+
|
91
|
+
# Cancel order.
|
92
|
+
#
|
93
|
+
# curl: POST https://api.fcoin.com/v2/orders/$order_id/submit-cancel
|
94
|
+
#
|
95
|
+
# @note This method can not be invoked without authentication.
|
96
|
+
#
|
97
|
+
# @example cancel order specified by order_id.
|
98
|
+
# client = Fcoin::Client.new(api_key: ENV['FCOIN_API_KEY'], secret_key: ENV['FCOIN_SECRET_KEY'])
|
99
|
+
# puts client.cancel_order(order_id: "nMEC_VrW0LYlP4iCcWzmdL50jFrvNWZoaQxvZSjeUSA=") #=> {"status":0}
|
100
|
+
#
|
101
|
+
#
|
102
|
+
# @see https://developer.fcoin.com/zh.html#299126e3bf
|
103
|
+
# @raise [ArgumentError] If the order_id does not have.
|
104
|
+
# @param order_id [String]
|
105
|
+
# @return [Hash or JSON]
|
106
|
+
def cancel_order(order_id:)
|
107
|
+
post("orders/#{order_id}/submit-cancel")
|
108
|
+
end
|
109
|
+
|
110
|
+
# Query the transaction record for the specified by order_id.
|
111
|
+
#
|
112
|
+
# curl: GET https://api.fcoin.com/v2/orders/$order_id/match-results
|
113
|
+
#
|
114
|
+
# @note This method can not be invoked without authentication.
|
115
|
+
#
|
116
|
+
# @example Query the transaction record for the specified by order_id.
|
117
|
+
# client = Fcoin::Client.new(api_key: ENV['FCOIN_API_KEY'], secret_key: ENV['FCOIN_SECRET_KEY'])
|
118
|
+
# puts client.order_match_results(order_id: "kW3cRiXIGHG-cHNdter*********qfoMzbeHEQcqp4=") #=> {"status":0,"data":[{"price": "1000","fill_fees": "0.00010000000000000","filled_amount": "0.00500000000000000","side": "buy","type": "limit","created_at": 1531734385085}]}
|
119
|
+
#
|
120
|
+
#
|
121
|
+
# @see https://developer.fcoin.com/zh.html#152112dfd6
|
122
|
+
# @raise [ArgumentError] If the order_id does not have.
|
123
|
+
# @param order_id [String]
|
124
|
+
# @return [Hash or JSON] Returns transaction record for the specified by order_id.
|
125
|
+
def order_match_results(order_id:)
|
126
|
+
get("orders/#{order_id}/match-results")
|
127
|
+
end
|
128
|
+
alias :order_transaction :order_match_results
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
# TODO: After checking the operation, go to the public
|
133
|
+
#
|
134
|
+
# Create market order.
|
135
|
+
#
|
136
|
+
# curl: POST https://api.fcoin.com/v2/orders
|
137
|
+
#
|
138
|
+
# @note This method can not be invoked without authentication.
|
139
|
+
#
|
140
|
+
# @example Create an order to sell 0.010eth at a price of 1000usdt.
|
141
|
+
# client = Fcoin::Client.new(api_key: ENV['FCOIN_API_KEY'], secret_key: ENV['FCOIN_SECRET_KEY'])
|
142
|
+
# puts client.create_order_market(symbol: :ethusdt, side: :buy, total: 1)
|
143
|
+
#
|
144
|
+
#
|
145
|
+
# @see https://developer.fcoin.com/zh.html#4a3e521c3b
|
146
|
+
# @raise [ArgumentError] If the symbol or side or type or price or amount does not have.
|
147
|
+
# @raise [InvalidValueError] If symbol or side or type or price or amount is invalid.
|
148
|
+
# @param symbol [String or Symbol] Transaction of pair
|
149
|
+
# @param side [String or Symbol] Direction of the transaction
|
150
|
+
# @param total [Float]
|
151
|
+
# @param amount [Float]
|
152
|
+
# @return [Hash or JSON] Returns receipt contains order_id.
|
153
|
+
def create_order_market(symbol:, side:, total: nil, amount: nil)
|
154
|
+
base_payload = { symbol: symbol, side: side, type: :market }
|
155
|
+
payload = case side.to_sym
|
156
|
+
when :sell
|
157
|
+
base_payload.merge(amount: amount)
|
158
|
+
when :buy
|
159
|
+
base_payload.merge(amount: total)
|
160
|
+
end
|
161
|
+
validator = Fcoin::Validator.new(payload.merge(method_name: __method__))
|
162
|
+
if skip_validation || validator.valid?
|
163
|
+
valid_payload = sort_payload(payload)
|
164
|
+
post('orders', true, valid_payload)
|
165
|
+
else
|
166
|
+
raise InvalidValueError.new(validator.messages)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# Scope Fcoin::API
|
2
|
+
module Fcoin
|
3
|
+
module Endpoint
|
4
|
+
module Public
|
5
|
+
# Get server time
|
6
|
+
#
|
7
|
+
# curl: GET https://api.fcoin.com/v2/public/server-time
|
8
|
+
#
|
9
|
+
# @example get server time
|
10
|
+
# client = Fcoin::Client.new
|
11
|
+
# puts client.public_server_time #=> {"status":0,"data":1531562028166}
|
12
|
+
#
|
13
|
+
#
|
14
|
+
# @see https://developer.fcoin.com/zh.html#8aa898cda7
|
15
|
+
# @return [Hash or JSON]
|
16
|
+
def public_server_time
|
17
|
+
get('public/server-time', false)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Display available currency
|
21
|
+
#
|
22
|
+
# curl: GET https://api.fcoin.com/v2/public/currencies
|
23
|
+
#
|
24
|
+
# @example Display available currency
|
25
|
+
# client = Fcoin::Client.new
|
26
|
+
# puts cient.public_currencies
|
27
|
+
#
|
28
|
+
#
|
29
|
+
# @see https://developer.fcoin.com/zh.html#0fd2e492e6
|
30
|
+
# @return [Hash or JSON]
|
31
|
+
def public_currencies
|
32
|
+
get('public/currencies', false)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Query available transaction pairs
|
36
|
+
#
|
37
|
+
# curl: GET https://api.fcoin.com/v2/public/symbols
|
38
|
+
#
|
39
|
+
# @example Query available transaction pairs
|
40
|
+
# client = Fcoin::Client.new
|
41
|
+
# puts client.public_symbols
|
42
|
+
#
|
43
|
+
#
|
44
|
+
# @see https://developer.fcoin.com/zh.html#a266e284f4
|
45
|
+
# @return [Hash or JSON]
|
46
|
+
def public_symbols
|
47
|
+
get('public/symbols', false)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative 'endpoint/public'
|
2
|
+
require_relative 'endpoint/market'
|
3
|
+
require_relative 'endpoint/accounts'
|
4
|
+
require_relative 'endpoint/orders'
|
5
|
+
|
6
|
+
module Fcoin
|
7
|
+
module Endpoint
|
8
|
+
include Public
|
9
|
+
include Market
|
10
|
+
include Accounts
|
11
|
+
include Orders
|
12
|
+
end
|
13
|
+
end
|
data/lib/fcoin/error.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require_relative '../formatter'
|
3
|
+
|
4
|
+
module FaradayMiddleware
|
5
|
+
class FcoinFormatter < Faraday::Middleware
|
6
|
+
# Format response_env by using Fcoin::Formatter
|
7
|
+
def call(request_env)
|
8
|
+
@app.call(request_env).on_complete do |response_env|
|
9
|
+
body = JSON.parse(response_env.body)
|
10
|
+
formatter = Fcoin::Formatter.new(body)
|
11
|
+
response_env.body = formatter.formatted_body
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Faraday::Response.register_middleware(fcoin_formatter: FcoinFormatter)
|
17
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'base_formatter'
|
2
|
+
|
3
|
+
module Fcoin
|
4
|
+
class DepthFormatter < BaseFormatter
|
5
|
+
|
6
|
+
attr_accessor :body
|
7
|
+
|
8
|
+
def initialize(body)
|
9
|
+
self.body = body
|
10
|
+
end
|
11
|
+
|
12
|
+
# Format response body for JSON
|
13
|
+
#
|
14
|
+
# @return [Hash]
|
15
|
+
def formatted_body
|
16
|
+
self.body['data']['bids'] = adjusted('bids')
|
17
|
+
self.body['data']['asks'] = adjusted('asks')
|
18
|
+
body
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def adjusted(type)
|
24
|
+
orders = body['data'][type].dup
|
25
|
+
orders.in_groups_of(2).map do |order|
|
26
|
+
{
|
27
|
+
"price" => order[0],
|
28
|
+
"amount" => order[1]
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|