coinsetter 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/.rvmrc +53 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/coinsetter.gemspec +29 -0
- data/lib/coinsetter/client_session.rb +29 -0
- data/lib/coinsetter/client_sessions.rb +15 -0
- data/lib/coinsetter/collection.rb +57 -0
- data/lib/coinsetter/configuration.rb +9 -0
- data/lib/coinsetter/customer/account.rb +9 -0
- data/lib/coinsetter/customer/accounts.rb +41 -0
- data/lib/coinsetter/helper.rb +24 -0
- data/lib/coinsetter/model.rb +27 -0
- data/lib/coinsetter/net.rb +23 -0
- data/lib/coinsetter/order.rb +20 -0
- data/lib/coinsetter/orders.rb +13 -0
- data/lib/coinsetter/version.rb +3 -0
- data/lib/coinsetter.rb +101 -0
- data/spec/spec_helper.rb +1 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1fe68bc71133c3d15fafc53413833482ae536480
|
4
|
+
data.tar.gz: 3ca776bc4aa124e4b2280a42f90da8b14a22a022
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 36b04912f2e2780b084f7400b3db2be70e627c154e03e07fd8caee57bfb7742c75ce1980fc509f3b9a7acf28b235b6d980030ac5c662911db26bc54f900b3559
|
7
|
+
data.tar.gz: e8f373a3166a59780f4ee7e7ff5cbe1ff3ddd3b0a8648b56af8dd053cf1cddf0aeb4c554195cf8b7fb82516886f0c9a80022b10585d79a00ee098b210f839691
|
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
.idea
|
24
|
+
*.DS_Store
|
25
|
+
|
data/.rvmrc
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 2.1.2@coinsetter" > .rvmrc
|
9
|
+
environment_id="ruby-2.1.2@coinsetter"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.25.29 (stable)" # 1.10.1 seems like a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | __rvm_awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
|
27
|
+
do
|
28
|
+
if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
|
29
|
+
then \. "${__hook}" || true
|
30
|
+
fi
|
31
|
+
done
|
32
|
+
unset __hook
|
33
|
+
if (( ${rvm_use_flag:=1} >= 2 )) # display only when forced
|
34
|
+
then
|
35
|
+
if [[ $- == *i* ]] # check for interactive shells
|
36
|
+
then printf "%b" "Using: $(tput setaf 2 2>/dev/null)$GEM_HOME$(tput sgr0 2>/dev/null)
|
37
|
+
" # show the user the ruby and gemset they are using in green
|
38
|
+
else printf "%b" "Using: $GEM_HOME
|
39
|
+
" # don't use colors in non-interactive shells
|
40
|
+
fi
|
41
|
+
fi
|
42
|
+
else
|
43
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
44
|
+
rvm --create "$environment_id" || {
|
45
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
46
|
+
return 1
|
47
|
+
}
|
48
|
+
fi
|
49
|
+
|
50
|
+
# If you use bundler, this might be useful to you:
|
51
|
+
# if [[ -s Gemfile ]] && {
|
52
|
+
# ! builtin command -v bundle >/dev/null ||
|
53
|
+
# builtin command -v bundle | GREP_OPTIONS=""
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
gemspec
|
3
|
+
ruby '2.1.2'
|
4
|
+
|
5
|
+
gem "activemodel", ">= 4.1"
|
6
|
+
gem "activesupport", ">= 4.1"
|
7
|
+
gem "rest_client", "1.7.3"
|
8
|
+
|
9
|
+
group :development do
|
10
|
+
gem "pry"
|
11
|
+
gem "rspec", ">= 0"
|
12
|
+
gem "rdoc", "~> 4.1"
|
13
|
+
gem "bundler", "~> 1.6.2"
|
14
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Luis Galaviz
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Coinsetter
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'coinsetter'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install coinsetter
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/coinsetter/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/coinsetter.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'coinsetter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "coinsetter"
|
8
|
+
spec.version = Coinsetter::VERSION
|
9
|
+
spec.authors = ["Luis Galaviz"]
|
10
|
+
spec.email = ["galaviz.lm@gmail.com"]
|
11
|
+
spec.summary = %q{Simple API connection to Coinsetter.}
|
12
|
+
spec.description = %q{Simple API connection to Coinsetter.}
|
13
|
+
spec.homepage = "https://github.com/MGalv/coinsetter"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
|
26
|
+
spec.add_runtime_dependency('activemodel', ['>= 4.1'])
|
27
|
+
spec.add_runtime_dependency('activesupport', ['>= 4.1'])
|
28
|
+
spec.add_runtime_dependency('rest_client', ['= 1.7.3'])
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Coinsetter
|
2
|
+
class ClientSession < Coinsetter::Model
|
3
|
+
attr_accessor :uuid, :user_name, :customer_uuid
|
4
|
+
|
5
|
+
def destroy!
|
6
|
+
parse call("LOGOUT")
|
7
|
+
end
|
8
|
+
|
9
|
+
def heartbeat
|
10
|
+
parse call("HEARTBEAT")
|
11
|
+
end
|
12
|
+
|
13
|
+
def path
|
14
|
+
"clientSession/#{uuid}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(action='HEARTBEAT')
|
18
|
+
Coinsetter::Net.put(
|
19
|
+
path,
|
20
|
+
{action: action},
|
21
|
+
{"coinsetter-client-session-id" => uuid}
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse(string)
|
26
|
+
Coinsetter::Helper.parse_message! string
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Coinsetter
|
2
|
+
class ClientSessions < Coinsetter::Collection
|
3
|
+
|
4
|
+
def example
|
5
|
+
JSON.generate({
|
6
|
+
uuid: "38363173-e6fd-4f3a-8146-9ba50da2b1e3",
|
7
|
+
message: "OK",
|
8
|
+
requestStatus: "SUCCESS",
|
9
|
+
userName: "johnqsmith",
|
10
|
+
customerUuid: "b20ba985-827d-42f7-a355-37e699ac964b",
|
11
|
+
customerStatus: "ACTIVE"
|
12
|
+
})
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Coinsetter
|
2
|
+
class Collection
|
3
|
+
attr_accessor :module, :name, :model, :path, :response
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
self.module = self.class.name.singularize.underscore
|
7
|
+
split_module = self.module.split('/')
|
8
|
+
split_module.shift
|
9
|
+
self.name = split_module.join('/')
|
10
|
+
self.model = self.module.camelize.constantize
|
11
|
+
last = split_module.pop
|
12
|
+
self.path = split_module.join('/') + last.camelize(:lower)
|
13
|
+
end
|
14
|
+
|
15
|
+
def create(options={}, route=path)
|
16
|
+
if Coinsetter.configured?
|
17
|
+
self.response = Coinsetter::Net.post(route, options)
|
18
|
+
else
|
19
|
+
self.response = example
|
20
|
+
end
|
21
|
+
|
22
|
+
parse
|
23
|
+
end
|
24
|
+
|
25
|
+
def list(route=path, options={})
|
26
|
+
if Coinsetter.configured?
|
27
|
+
self.response = Coinsetter::Net.get(route, options)
|
28
|
+
else
|
29
|
+
self.response = example
|
30
|
+
end
|
31
|
+
|
32
|
+
parse_collection
|
33
|
+
end
|
34
|
+
|
35
|
+
def get(id, route=path, options={})
|
36
|
+
self.response = Coinsetter::Net.get("#{route}/#{id}", options)
|
37
|
+
parse
|
38
|
+
end
|
39
|
+
|
40
|
+
def example
|
41
|
+
JSON.generate({error: "Something went wrong."})
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def parse
|
46
|
+
@parsed ||= if response["requestStatus"] == "SUCCESS"
|
47
|
+
Coinsetter::Helper.parse_object! response, model
|
48
|
+
else
|
49
|
+
Coinsetter::Helper.parse_message! response
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def parse_collection
|
54
|
+
@collection ||= Coinsetter::Helper.parse_objects! response, model
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module Coinsetter
|
2
|
+
module Customer
|
3
|
+
class Account < ::Coinsetter::Model
|
4
|
+
attr_accessor :account_uuid, :customer_uuid, :account_number, :name, :description, :btc_balance
|
5
|
+
attr_accessor :usd_balance, :account_class, :active_status, :approved_margin_ratio, :create_date
|
6
|
+
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Coinsetter
|
2
|
+
module Customer
|
3
|
+
class Accounts < Coinsetter::Collection
|
4
|
+
|
5
|
+
def example
|
6
|
+
JSON.generate({
|
7
|
+
accountList:
|
8
|
+
[
|
9
|
+
{
|
10
|
+
accountUuid: "50af62c2-7221-49a1-85a8-dd34c6e0dd70",
|
11
|
+
customerUuid: "b20ba985-827d-42f7-a355-37e699ac964b",
|
12
|
+
accountNumber: "CST0000001",
|
13
|
+
name: "My Bitcoin account",
|
14
|
+
description: "For primary trading",
|
15
|
+
btcBalance: 0E-8,
|
16
|
+
usdBalance: 11.2,
|
17
|
+
accountClass: "TEST",
|
18
|
+
activeStatus: "ACTIVE",
|
19
|
+
approvedMarginRatio: 1.0000,
|
20
|
+
createDate: "18/05/2013 10:10:25.000",
|
21
|
+
},
|
22
|
+
{
|
23
|
+
accountUuid: "b03a8e48-6ce4-4b5a-a8f5-ea6af8f288da",
|
24
|
+
customerUuid: "b20ba985-827d-42f7-a355-37e699ac964b",
|
25
|
+
accountNumber: "CSV0000002",
|
26
|
+
name: "My Bitcoin account.2",
|
27
|
+
description: "For primary trading",
|
28
|
+
btcBalance: 0E-8,
|
29
|
+
usdBalance: 11.2,
|
30
|
+
accountClass: "VIRTUAL",
|
31
|
+
activeStatus: "ACTIVE",
|
32
|
+
approvedMarginRatio: 1.0000,
|
33
|
+
createDate: "18/05/2013 10:10:25.000",
|
34
|
+
}
|
35
|
+
]
|
36
|
+
}
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Coinsetter
|
2
|
+
module Helper
|
3
|
+
def self.parse_objects!(string, klass)
|
4
|
+
string = "{\"empty\":[]}" if string == ""
|
5
|
+
|
6
|
+
objects = JSON.parse(string).first.last
|
7
|
+
objects.collect do |t_json|
|
8
|
+
parse_object!(t_json, klass)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.parse_object!(object, klass)
|
13
|
+
object = JSON.parse(object) if object.is_a? String
|
14
|
+
|
15
|
+
klass.new(object)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.parse_message!(string)
|
19
|
+
string = "[]" if string == ""
|
20
|
+
|
21
|
+
JSON.parse(string)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Coinsetter
|
2
|
+
class Model
|
3
|
+
attr_accessor :error, :message
|
4
|
+
|
5
|
+
include ActiveModel::Validations
|
6
|
+
include ActiveModel::Conversion
|
7
|
+
extend ActiveModel::Naming
|
8
|
+
|
9
|
+
def initialize(attributes = {})
|
10
|
+
self.attributes = attributes
|
11
|
+
end
|
12
|
+
|
13
|
+
def attributes=(attributes = {})
|
14
|
+
attributes.each do |name, value|
|
15
|
+
begin
|
16
|
+
send("#{name.underscore}=", value)
|
17
|
+
rescue NoMethodError => e
|
18
|
+
puts "Unable to assign #{name.underscore} with value #{value}. No such method."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def attributes
|
24
|
+
Hash[instance_variables.map { |name| [name, instance_variable_get(name)] }]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Bitstamp
|
2
|
+
module Net
|
3
|
+
def self.uri(path)
|
4
|
+
return "#{Bitstamp.uri}#{path}"
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.get(path, headers={})
|
8
|
+
RestClient.get(uri(path), headers)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.post(path, args={}, headers={})
|
12
|
+
RestClient.post(uri(path), args, headers)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.put(path, args={}, headers={})
|
16
|
+
RestClient.put(uri(path), args, headers)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.delete(path, headers={})
|
20
|
+
RestClient.delete(uri(path), headers)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Coinsetter
|
2
|
+
class Order < Coinsetter::Model
|
3
|
+
attr_accessor :uuid, :account_uuid, :cost_basis, :customer_uuid, :filled_quantity, :open_quantity
|
4
|
+
attr_accessor :order_number, :order_ype, :stage, :requested_uantity, :requested_price, :side
|
5
|
+
attr_accessor :routing_method, :create_date, :symbol
|
6
|
+
|
7
|
+
def destroy!(client_session_uuid)
|
8
|
+
call = Coinsetter::Net.delete(path, {"coinsetter-client-session-id" => client_session_uuid})
|
9
|
+
parse call
|
10
|
+
end
|
11
|
+
|
12
|
+
def path
|
13
|
+
"order/#{uuid}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse(string)
|
17
|
+
Coinsetter::Helper.parse_message! string
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/coinsetter.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require "coinsetter/version"
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'active_support'
|
5
|
+
require 'active_support/core_ext'
|
6
|
+
require 'active_support/inflector'
|
7
|
+
require 'active_model'
|
8
|
+
require 'rest_client'
|
9
|
+
|
10
|
+
require "coinsetter/configuration"
|
11
|
+
require "coinsetter/net"
|
12
|
+
require "coinsetter/helper"
|
13
|
+
require "coinsetter/model"
|
14
|
+
require "coinsetter/collection"
|
15
|
+
require "coinsetter/customer/accounts"
|
16
|
+
require "coinsetter/customer/account"
|
17
|
+
require "coinsetter/client_sessions"
|
18
|
+
require "coinsetter/client_session"
|
19
|
+
require "coinsetter/orders"
|
20
|
+
require "coinsetter/order"
|
21
|
+
require "coinsetter/order"
|
22
|
+
|
23
|
+
String.send(:include, ActiveSupport::Inflector)
|
24
|
+
|
25
|
+
module Coinsetter
|
26
|
+
class << self
|
27
|
+
attr_writer :configuration
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.configuration
|
31
|
+
@configuration ||= Configuration.new
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.configure
|
35
|
+
yield(configuration)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.configured?
|
39
|
+
configuration.username && configuration.password && configuration.ip_address
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.with_session
|
43
|
+
session = Coinsetter::ClientSessions.new
|
44
|
+
client_session = session.create(credentials)
|
45
|
+
|
46
|
+
if client_session.kind_of? Coinsetter::ClientSession
|
47
|
+
yield client_session if block_given?
|
48
|
+
end
|
49
|
+
|
50
|
+
client_session.destroy!
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.orders
|
54
|
+
@@orders ||= Coinsetter::Orders.new
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.add_order(side='BUY', options={})
|
58
|
+
with_session do |client_session|
|
59
|
+
params = default_options.merge(options)
|
60
|
+
params.merge!(side: side,
|
61
|
+
customerUuid: client_session.customer_uuid)
|
62
|
+
orders.create(params)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Required Order Params
|
67
|
+
# requestedQuantity, requestedPrice, accountUuid
|
68
|
+
def self.buy_order(amount, price, account_uuid, options={})
|
69
|
+
add_order('BUY', options.merge(required_params(amount, price, account_uuid)))
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.sell_order(amount, price, account_uuid, options={})
|
73
|
+
add_order('BUY', options.merge(required_params(amount, price, account_uuid)))
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.default_options
|
77
|
+
{
|
78
|
+
symbol: "BTCUSD",
|
79
|
+
orderType: ("LIMIT"),
|
80
|
+
routingMethod: 2
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.required_params(amount, price, account_uuid)
|
85
|
+
{
|
86
|
+
requestedQuantity: amount,
|
87
|
+
requestedPrice: price,
|
88
|
+
accountUuid: account_uuid
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def self.credentials
|
95
|
+
{
|
96
|
+
username: configuration.username,
|
97
|
+
ipAddress: configuration.ip_address,
|
98
|
+
password: configuration.password
|
99
|
+
}
|
100
|
+
end
|
101
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'coinsetter'
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coinsetter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luis Galaviz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activemodel
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.1'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activesupport
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.1'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.1'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rest_client
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.7.3
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.7.3
|
111
|
+
description: Simple API connection to Coinsetter.
|
112
|
+
email:
|
113
|
+
- galaviz.lm@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rvmrc"
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- coinsetter.gemspec
|
125
|
+
- lib/coinsetter.rb
|
126
|
+
- lib/coinsetter/client_session.rb
|
127
|
+
- lib/coinsetter/client_sessions.rb
|
128
|
+
- lib/coinsetter/collection.rb
|
129
|
+
- lib/coinsetter/configuration.rb
|
130
|
+
- lib/coinsetter/customer/account.rb
|
131
|
+
- lib/coinsetter/customer/accounts.rb
|
132
|
+
- lib/coinsetter/helper.rb
|
133
|
+
- lib/coinsetter/model.rb
|
134
|
+
- lib/coinsetter/net.rb
|
135
|
+
- lib/coinsetter/order.rb
|
136
|
+
- lib/coinsetter/orders.rb
|
137
|
+
- lib/coinsetter/version.rb
|
138
|
+
- spec/spec_helper.rb
|
139
|
+
homepage: https://github.com/MGalv/coinsetter
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata: {}
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 2.2.2
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: Simple API connection to Coinsetter.
|
163
|
+
test_files:
|
164
|
+
- spec/spec_helper.rb
|