vexapion 0.4.1 → 0.4.2
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 +4 -4
- data/.gitignore +16 -0
- data/Gemfile +4 -0
- data/README.md +100 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/vexapion/connect/http_client.rb +3 -2
- data/lib/vexapion/test/bf-trade.rb +176 -0
- data/lib/vexapion/test/bf.rb +156 -0
- data/lib/vexapion/test/cc-trade.rb +83 -0
- data/lib/vexapion/test/cc.rb +226 -0
- data/lib/vexapion/test/polo-trade.rb +126 -0
- data/lib/vexapion/test/polo.rb +103 -0
- data/lib/vexapion/test/z-trade.rb +64 -0
- data/lib/vexapion/test/z.rb +40 -0
- data/lib/vexapion/version.rb +1 -1
- data/vexapion.gemspec +24 -0
- metadata +20 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3703610cf7c688c5373f38d1c69a6f2b216d8c04
|
|
4
|
+
data.tar.gz: cbce0849226a1511bf8b0dc9c464d693ef997123
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '068a52b12973da5aa98c8b1ef07a15126c2a5865b8ee8fe196bd99fbe41c04a3cf4cfd8832845641dec2a1d16d88f393bf28ed4947bd198983a4d35bb7ee30e8'
|
|
7
|
+
data.tar.gz: 3ea2023c4575e7d47c2c3e5b1a210ea8a5fd8dbe05c6e33bb7aea4b891a580085940b1acc213daa1b56e0eb981f118a5de10235aff062bae05d203d87b46f0d5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Vexapion
|
|
2
|
+
|
|
3
|
+
Vexapionは、仮想(暗号)通貨取引所のAPIを簡単に使えるようにしたAPIラッパーです。
|
|
4
|
+
|
|
5
|
+
現在ほぼ問題なく利用可能なのはCoincheck, Zaifのみです。
|
|
6
|
+
|
|
7
|
+
Bitflyer, Poloniexも一応利用可能ですが、マージン取引、特殊取引などに関連する関数はテストされていません。
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Add this line to your application's Gemfile:
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
gem 'vexapion'
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
And then execute:
|
|
19
|
+
|
|
20
|
+
$ bundle
|
|
21
|
+
|
|
22
|
+
Or install it yourself as:
|
|
23
|
+
|
|
24
|
+
$ gem install vexapion
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
例:zaifの場合
|
|
29
|
+
|
|
30
|
+
クラスファイルを読み込みます。
|
|
31
|
+
```ruby
|
|
32
|
+
require 'vexapion/zaif'
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
クラスの初期化をします。
|
|
36
|
+
```ruby
|
|
37
|
+
zapi = Vexapion::Zaif.new(APIkey, secretkey)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
扱いたいペアを指定します
|
|
41
|
+
```ruby
|
|
42
|
+
pair = 'btc_jpy'
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
tickerを取得します
|
|
46
|
+
```ruby
|
|
47
|
+
tick = zapi.ticker(pair)
|
|
48
|
+
ask = tick['ask']
|
|
49
|
+
bid = tick['bid']
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
(すぐ売買に利用可能な)残高を取得します
|
|
54
|
+
```ruby
|
|
55
|
+
res = zapi.balance
|
|
56
|
+
balance = res['return']['funds']
|
|
57
|
+
jpy_available = balance['jpy']
|
|
58
|
+
btc_available = balance['btc']
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
売買します
|
|
64
|
+
```ruby
|
|
65
|
+
zapi.sell(pair, rate, amount)
|
|
66
|
+
zapi.buy(pair, rate, amount)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
等のように使います。
|
|
70
|
+
|
|
71
|
+
各取引所クラスでメソッド名が異なるため、各取引所のAPIドキュメントをご覧ください。
|
|
72
|
+
|
|
73
|
+
また、各メソッドの返り値はAPIから返って来たものをHash化しただけになりますので、詳しくは http://vexapion.fuyuton.net にある各取引所のAPIドキュメントをご覧ください。
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
例外。
|
|
77
|
+
各メソッドはHTTPを使って取引所と通信をします。そのため接続できなかった場合などにエラーが返ってくることがあります。
|
|
78
|
+
|
|
79
|
+
Vexapionには、4つの例外があります。
|
|
80
|
+
|
|
81
|
+
Vexapion::RetryException は、サーバー側にエラーが発生し、接続が出来ないまたは、リクエストが通ったかどうか定かでない状態になったときに発生します。
|
|
82
|
+
|
|
83
|
+
(当初Vexapion側で自動的に再接続処理をする予定で付けていた名残でRetryExceptionという名前になっています。将来的に変更される可能性があります)
|
|
84
|
+
|
|
85
|
+
Vexapion::Warning は、場合によってはアプリ側で無視出来るかもしれないエラーになります。
|
|
86
|
+
|
|
87
|
+
Vexapion::Error は、アプリ側またはVexapion自体の修正が必要なエラーになります。
|
|
88
|
+
|
|
89
|
+
Vexapion::Fatal は、Vexapion自体の修正が必要なエラーになると思います。
|
|
90
|
+
|
|
91
|
+
## Development
|
|
92
|
+
|
|
93
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
94
|
+
|
|
95
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
96
|
+
|
|
97
|
+
## Contributing
|
|
98
|
+
|
|
99
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fuyuton/vexapion.
|
|
100
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "vexapion"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
|
@@ -101,16 +101,17 @@ module Vexapion
|
|
|
101
101
|
end #of response
|
|
102
102
|
|
|
103
103
|
def handle_http_error(response)
|
|
104
|
+
server_error, client_error = [500, 502, 503, 504], [400, 401, 403, 404]
|
|
104
105
|
http_status_code = response.code.to_i
|
|
105
106
|
message = "#{response.message} #{response.body}"
|
|
106
107
|
|
|
107
108
|
#2.server error
|
|
108
109
|
case http_status_code
|
|
109
|
-
when
|
|
110
|
+
when *server_error
|
|
110
111
|
fail RetryException.new(http_status_code, message)
|
|
111
112
|
|
|
112
113
|
#3.client error
|
|
113
|
-
when
|
|
114
|
+
when *client_error
|
|
114
115
|
fail Error.new(http_status_code, message)
|
|
115
116
|
|
|
116
117
|
#4. other
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
require 'vexapion/bitflyer'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
|
|
4
|
+
@pair = 'BTC_JPY'
|
|
5
|
+
pair2 = 'BTC_JPY'
|
|
6
|
+
|
|
7
|
+
key_file = "key/bf.yml"
|
|
8
|
+
file = File.read(key_file)
|
|
9
|
+
key = YAML.load(file)
|
|
10
|
+
|
|
11
|
+
@api = Vexapion::Bitflyer.new(key['access-key'], key['secret-key'])
|
|
12
|
+
|
|
13
|
+
public = true
|
|
14
|
+
priv = true
|
|
15
|
+
|
|
16
|
+
res = @api.ticker(@pair)
|
|
17
|
+
ask = res['best_ask']
|
|
18
|
+
bid = res['best_bid']
|
|
19
|
+
|
|
20
|
+
@type = 'LIMIT'
|
|
21
|
+
side = 'SELL'
|
|
22
|
+
price = 140000
|
|
23
|
+
amount = 0.001
|
|
24
|
+
|
|
25
|
+
#puts "@api.send_child_order(@pair, @type, side, price, size)"
|
|
26
|
+
#res = @api.send_child_order(@pair, @type, side, price, amount)
|
|
27
|
+
#coaid = res['child_order_acceptance_id']
|
|
28
|
+
#p coaid
|
|
29
|
+
|
|
30
|
+
#sleep 5
|
|
31
|
+
|
|
32
|
+
#puts "cancel"
|
|
33
|
+
#res = @api.cancel_child_order_acceptance_id(@pair, coaid)
|
|
34
|
+
#p res
|
|
35
|
+
|
|
36
|
+
#puts 'order'
|
|
37
|
+
#puts @api.send_child_order(@pair, @type, side, price, amount)
|
|
38
|
+
#sleep 3
|
|
39
|
+
#puts 'get_orders'
|
|
40
|
+
#res = @api.get_child_orders(@pair)
|
|
41
|
+
#puts res
|
|
42
|
+
#oid = res[0]['child_order_id']
|
|
43
|
+
#puts oid
|
|
44
|
+
#puts "cancel"
|
|
45
|
+
#res = @api.cancel_all_child_order(@pair)
|
|
46
|
+
#res = @api.cancel_child_order_id(@pair, oid)
|
|
47
|
+
#puts res
|
|
48
|
+
|
|
49
|
+
def buy(price, size)
|
|
50
|
+
puts "@api.send_child_order(@pair, @type, 'BUY', price, size)"
|
|
51
|
+
res = @api.send_child_order(@pair, @type, 'BUY', price.to_i, size.to_f)
|
|
52
|
+
puts res
|
|
53
|
+
res['child_order_acceptance_id']
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def sell(price, size)
|
|
57
|
+
puts "@api.send_child_order(@pair, @type, 'SELL', price, size)"
|
|
58
|
+
res = @api.send_child_order(@pair, @type, 'SELL', price.to_i, size.to_f)
|
|
59
|
+
puts res
|
|
60
|
+
res['child_order_acceptance_id']
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def tick
|
|
64
|
+
res = @api.ticker(@pair)
|
|
65
|
+
ask = res['best_ask'].to_i
|
|
66
|
+
bid = res['best_bid'].to_i
|
|
67
|
+
{ ask: ask, bid: bid }
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def balance
|
|
71
|
+
res = @api.get_balance
|
|
72
|
+
lst = Hash.new
|
|
73
|
+
ret = Hash.new
|
|
74
|
+
res.each do |asset|
|
|
75
|
+
name = asset['currency_code']
|
|
76
|
+
amount = asset['amount']
|
|
77
|
+
available = asset['available']
|
|
78
|
+
lst[name] = {
|
|
79
|
+
amount: amount,
|
|
80
|
+
available: available
|
|
81
|
+
}
|
|
82
|
+
ret.update lst
|
|
83
|
+
end
|
|
84
|
+
ret
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
#------------------------------------------------------------------
|
|
88
|
+
#残高取得
|
|
89
|
+
res = balance
|
|
90
|
+
jpy_avail = res['JPY']['available']
|
|
91
|
+
btc_avail = res['BTC']['available']
|
|
92
|
+
|
|
93
|
+
#売る
|
|
94
|
+
puts '\n\nsell'
|
|
95
|
+
amount = 0.001
|
|
96
|
+
rate = tick[:ask] + 5000
|
|
97
|
+
res = sell(rate, amount)
|
|
98
|
+
sleep 4
|
|
99
|
+
|
|
100
|
+
#注文リスト表示
|
|
101
|
+
puts "\n@api.get_child_orders(@pair)"
|
|
102
|
+
res = @api.get_child_orders(@pair, "ACTIVE")
|
|
103
|
+
puts res
|
|
104
|
+
order_id = res[0]['child_order_id']
|
|
105
|
+
puts "\n\n#{order_id}"
|
|
106
|
+
|
|
107
|
+
sleep 10
|
|
108
|
+
#キャンセル
|
|
109
|
+
puts "\n@api.cancel_child_order(#{@pair}, #{order_id})"
|
|
110
|
+
puts @api.cancel_child_order(@pair, order_id)
|
|
111
|
+
sleep 3
|
|
112
|
+
|
|
113
|
+
#売る
|
|
114
|
+
|
|
115
|
+
res = sell(rate, amount)
|
|
116
|
+
puts res
|
|
117
|
+
acceptance_id = res
|
|
118
|
+
|
|
119
|
+
sleep 4
|
|
120
|
+
#きゃんせる
|
|
121
|
+
puts "\n@api.cancel_child_order_acceptance_id(@pair, acceptance_id)"
|
|
122
|
+
puts @api.cancel_child_order_specify_acceptance_id(@pair, acceptance_id)
|
|
123
|
+
|
|
124
|
+
#売る
|
|
125
|
+
|
|
126
|
+
sell(rate, amount)
|
|
127
|
+
|
|
128
|
+
sleep 4
|
|
129
|
+
#きゃんせる
|
|
130
|
+
puts "\n@api.cancel_all_child_order(@pair)"
|
|
131
|
+
puts @api.cancel_all_child_order(@pair)
|
|
132
|
+
|
|
133
|
+
#売る
|
|
134
|
+
rate = tick[:bid]
|
|
135
|
+
sell(rate, amount)
|
|
136
|
+
|
|
137
|
+
#買い戻す
|
|
138
|
+
rate = tick[:ask]
|
|
139
|
+
buy(rate, amount)
|
|
140
|
+
#------------------------------------------------------------------
|
|
141
|
+
# parent order ??
|
|
142
|
+
|
|
143
|
+
#puts "@api.send_parent_order(params)"
|
|
144
|
+
#puts @api.send_parent_order(params)
|
|
145
|
+
|
|
146
|
+
#puts "@api.get_parent_orders(@pair)"
|
|
147
|
+
#puts @api.get_parent_orders(@pair)
|
|
148
|
+
|
|
149
|
+
#puts "@api.get_parent_order(parent_order_id)"
|
|
150
|
+
#puts @api.get_parent_order(parent_order_id)
|
|
151
|
+
|
|
152
|
+
#puts "@api.get_parent_order(acceptance_id)"
|
|
153
|
+
#puts @api.get_parent_order(acceptance_id)
|
|
154
|
+
|
|
155
|
+
#puts "@api.cancel_parent_order_id(@pair, order_id)"
|
|
156
|
+
#puts @api.cancel_parent_order_id(@pair, order_id)
|
|
157
|
+
|
|
158
|
+
#puts "@api.cancel_parent_order_acceptance_id(@pair, acceptance_id)"
|
|
159
|
+
#puts @api.cancel_parent_order_acceptance_id(@pair, acceptance_id)
|
|
160
|
+
|
|
161
|
+
#-------------------------------------------------------------------
|
|
162
|
+
|
|
163
|
+
#puts "\n\n@api.get_chats(date)"
|
|
164
|
+
#puts @api.get_chats(date)
|
|
165
|
+
|
|
166
|
+
#-------------------------------------------------------------------
|
|
167
|
+
|
|
168
|
+
# 払出
|
|
169
|
+
#puts "@api.sendcoin(currency, amount, address, fee, code)"
|
|
170
|
+
#puts @api.sendcoin(currency, amount, address, fee, code)
|
|
171
|
+
|
|
172
|
+
#puts "@api.withdraw(currency, id, amount, code)"
|
|
173
|
+
#puts @api.withdraw(currency, id, amount, code)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
puts "\n\nEnd of #{__FILE__} test\n\n"
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
require 'vexapion/bitflyer'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
|
|
4
|
+
pair1 = 'BTC_JPY'
|
|
5
|
+
pair2 = 'BTC_JPY'
|
|
6
|
+
|
|
7
|
+
key_file = "key/bf.yml"
|
|
8
|
+
file = File.read(key_file)
|
|
9
|
+
key = YAML.load(file)
|
|
10
|
+
|
|
11
|
+
api = Vexapion::Bitflyer.new(key['access-key'], key['secret-key'])
|
|
12
|
+
#api = Vexapion::Bitflyer.new
|
|
13
|
+
|
|
14
|
+
public = true
|
|
15
|
+
priv = true
|
|
16
|
+
|
|
17
|
+
res = api.ticker(pair1)
|
|
18
|
+
#puts res
|
|
19
|
+
ask = res['best_ask']
|
|
20
|
+
bid = res['best_bid']
|
|
21
|
+
|
|
22
|
+
type = 'LIMIT'
|
|
23
|
+
side = 'sell'
|
|
24
|
+
price = 140000
|
|
25
|
+
amount = 0.001
|
|
26
|
+
#puts "api.send_child_order(pair1, type, side, price, size)"
|
|
27
|
+
#res = api.send_child_order(pair1, type, side, price, amount)
|
|
28
|
+
#coaid = res['child_order_acceptance_id']
|
|
29
|
+
#p coaid
|
|
30
|
+
|
|
31
|
+
#sleep 5
|
|
32
|
+
|
|
33
|
+
#puts "cancel"
|
|
34
|
+
#res = api.cancel_child_order_acceptance_id(pair1, coaid)
|
|
35
|
+
#p res
|
|
36
|
+
|
|
37
|
+
#puts 'order'
|
|
38
|
+
#puts api.send_child_order(pair1, type, side, price, amount)
|
|
39
|
+
#sleep 3
|
|
40
|
+
#puts 'get_orders'
|
|
41
|
+
#res = api.get_child_orders(pair1)
|
|
42
|
+
#puts res
|
|
43
|
+
#oid = res[0]['child_order_id']
|
|
44
|
+
#puts oid
|
|
45
|
+
#puts "cancel"
|
|
46
|
+
#res = api.cancel_all_child_order(pair1)
|
|
47
|
+
#res = api.cancel_child_order_id(pair1, oid)
|
|
48
|
+
#puts res
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if public == true
|
|
52
|
+
puts "\n\napi.board(#{pair1})"
|
|
53
|
+
puts api.board(pair1)
|
|
54
|
+
|
|
55
|
+
puts "\n\napi.ticker(#{pair1})"
|
|
56
|
+
puts api.ticker(pair1)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
puts "\n\napi.get_public_executions(pair1, count=100, before=0, after=0)"
|
|
60
|
+
puts api.get_public_executions(pair1, count=100, before=0, after=0)
|
|
61
|
+
|
|
62
|
+
#puts "\n\napi.get_chats(date)"
|
|
63
|
+
#puts api.get_chats(date)
|
|
64
|
+
|
|
65
|
+
puts "\m\bapi.get_health"
|
|
66
|
+
puts api.get_health
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
if priv == true
|
|
71
|
+
puts "\napi.get_permissions"
|
|
72
|
+
puts JSON.pretty_generate(api.get_permissions)
|
|
73
|
+
|
|
74
|
+
puts "api.get_balance"
|
|
75
|
+
res = api.get_balance
|
|
76
|
+
puts JSON.pretty_generate(res)
|
|
77
|
+
|
|
78
|
+
puts "api.get_collateral"
|
|
79
|
+
puts api.get_collateral
|
|
80
|
+
|
|
81
|
+
puts "api.get_addresses"
|
|
82
|
+
puts api.get_addresses
|
|
83
|
+
|
|
84
|
+
puts "api.executions(pair1, count=100, before=0, after=0)"
|
|
85
|
+
puts api.executions(pair1, count=100, before=0, after=0)
|
|
86
|
+
|
|
87
|
+
puts "api.get_coin_ins(count=100, before=0, after=0)"
|
|
88
|
+
puts api.get_coin_ins(count=100, before=0, after=0)
|
|
89
|
+
|
|
90
|
+
#puts "api.sendcoin(currency, amount, address, fee=0.0, code='')"
|
|
91
|
+
#puts api.sendcoin(currency, amount, address, fee=0.0, code='')
|
|
92
|
+
|
|
93
|
+
puts "api.get_coin_outs(count=100, before=0, after=0)"
|
|
94
|
+
puts api.get_coin_outs(count=100, before=0, after=0)
|
|
95
|
+
|
|
96
|
+
#puts "api.get_coin_outs_id(id)"
|
|
97
|
+
#puts api.get_coin_outs_id(id)
|
|
98
|
+
|
|
99
|
+
puts "api.get_bank_accounts"
|
|
100
|
+
puts api.get_bank_accounts
|
|
101
|
+
|
|
102
|
+
puts "api.get_deposits(count=100, before=0, after=0)"
|
|
103
|
+
puts api.get_deposits(count=100, before=0, after=0)
|
|
104
|
+
|
|
105
|
+
#puts "api.withdraw(currency, id, amount, code='')"
|
|
106
|
+
#puts api.withdraw(currency, id, amount, code='')
|
|
107
|
+
|
|
108
|
+
puts "api.get_withdrawals(count=100, before=0, after=0)"
|
|
109
|
+
puts api.get_withdrawals(count=100, before=0, after=0)
|
|
110
|
+
#-------------------------------------------------------------------
|
|
111
|
+
puts "api.get_executions(pair1, count=100, before=0, after=0, child_order_id='', child_order_acceptance_id='')"
|
|
112
|
+
puts api.get_executions(pair1, count=100, before=0, after=0, child_order_id='', child_order_acceptance_id='')
|
|
113
|
+
|
|
114
|
+
puts "api.get_positions"
|
|
115
|
+
puts api.get_positions
|
|
116
|
+
#-------------------------------------------------------------------
|
|
117
|
+
|
|
118
|
+
#puts "api.send_child_order(pair1, type, side, price, size)"
|
|
119
|
+
#puts api.send_child_order(pair1, type, side, price, size)
|
|
120
|
+
|
|
121
|
+
#puts "api.cancel_child_order(pair1, order_id='')"
|
|
122
|
+
#puts api.cancel_child_order(pair1, order_id='')
|
|
123
|
+
|
|
124
|
+
#puts "api.cancel_child_order_id(pair1, order_id)"
|
|
125
|
+
#puts api.cancel_child_order_id(pair1, order_id)
|
|
126
|
+
|
|
127
|
+
#puts "api.cancel_child_order_acceptance_id(pair1, acceptance_id)"
|
|
128
|
+
#puts api.cancel_child_order_acceptance_id(pair1, acceptance_id)
|
|
129
|
+
|
|
130
|
+
#puts "api.send_parent_order(params)"
|
|
131
|
+
#puts api.send_parent_order(params)
|
|
132
|
+
|
|
133
|
+
#puts "api.cancel_parent_order_id(pair1, order_id)"
|
|
134
|
+
#puts api.cancel_parent_order_id(pair1, order_id)
|
|
135
|
+
|
|
136
|
+
#puts "api.cancel_parent_order_acceptance_id(pair1, acceptance_id)"
|
|
137
|
+
#puts api.cancel_parent_order_acceptance_id(pair1, acceptance_id)
|
|
138
|
+
|
|
139
|
+
#puts "api.cancel_all_child_order(pair1)"
|
|
140
|
+
#puts api.cancel_all_child_order(pair1)
|
|
141
|
+
|
|
142
|
+
#puts "api.get_child_orders(pair1, count=100, before=0, after=0, state='', pid='')"
|
|
143
|
+
#puts api.get_child_orders(pair1, count=100, before=0, after=0, state='', pid='')
|
|
144
|
+
|
|
145
|
+
#puts "api.get_parent_orders(pair1, count=100, before=0, after=0, state='')"
|
|
146
|
+
#puts api.get_parent_orders(pair1, count=100, before=0, after=0, state='')
|
|
147
|
+
|
|
148
|
+
#puts "api.get_parent_order(parent_order_id)"
|
|
149
|
+
#puts api.get_parent_order(parent_order_id)
|
|
150
|
+
|
|
151
|
+
#puts "api.get_parent_order(acceptance_id)"
|
|
152
|
+
#puts api.get_parent_order(acceptance_id)
|
|
153
|
+
|
|
154
|
+
end #of private
|
|
155
|
+
|
|
156
|
+
puts "\n\nEnd of #{__FILE__} test\n\n"
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require 'vexapion/coincheck'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
|
|
4
|
+
pair = 'btc_jpy'
|
|
5
|
+
|
|
6
|
+
key_file = "key/cc.yml"
|
|
7
|
+
keydata = File.read(key_file)
|
|
8
|
+
key = YAML.load(keydata)
|
|
9
|
+
|
|
10
|
+
api = Vexapion::Coincheck.new(key['access-key'], key['secret-key'])
|
|
11
|
+
begin
|
|
12
|
+
|
|
13
|
+
bal = api.leverage_balance
|
|
14
|
+
puts bal
|
|
15
|
+
amount = bal['margin']['jpy'].to_i
|
|
16
|
+
puts "move to_leverage #{amount}JPY"
|
|
17
|
+
res = api.to_leverage(cur, amount)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
#------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
cur = 'JPY'
|
|
23
|
+
|
|
24
|
+
#レバレッジ買い
|
|
25
|
+
rate = api.ticker['ask']
|
|
26
|
+
amount = 0.01
|
|
27
|
+
puts "api.order_leverage(pair, 'buy', rate, amount)"
|
|
28
|
+
leve = api.order_leverage(pair, 'buy', rate, amount)
|
|
29
|
+
puts leve
|
|
30
|
+
sleep 30
|
|
31
|
+
|
|
32
|
+
#ポジ解消
|
|
33
|
+
puts "api.position('open')"
|
|
34
|
+
res = api.position('open')
|
|
35
|
+
#puts res
|
|
36
|
+
while res['data'] != []
|
|
37
|
+
res['data'].each do |pos|
|
|
38
|
+
#pos = res['data'][0]
|
|
39
|
+
pos_id = pos['id'].to_i
|
|
40
|
+
pos_rate = pos['open_rate'].to_i
|
|
41
|
+
pos_side = pos['side']
|
|
42
|
+
amount = pos['amount'].to_f
|
|
43
|
+
puts " #{pos_id} #{pos_rate} #{pos_side} #{amount} "
|
|
44
|
+
|
|
45
|
+
sleep 1
|
|
46
|
+
tick = api.ticker
|
|
47
|
+
ask = tick['ask'].to_i
|
|
48
|
+
bid = tick['bid'].to_i
|
|
49
|
+
|
|
50
|
+
if pos_side.downcase == 'buy'
|
|
51
|
+
posi = 'long'
|
|
52
|
+
#bidが買ったときより高ければ
|
|
53
|
+
if pos_rate < bid
|
|
54
|
+
puts "(#{posi}, #{pos_id}, #{amount}) #{ask} #{bid}"
|
|
55
|
+
puts api.close_position_market_order(pair, posi, pos_id, amount)
|
|
56
|
+
end
|
|
57
|
+
#askが買ったときより安ければ
|
|
58
|
+
if ask < pos_rate
|
|
59
|
+
puts "(#{posi}, #{pos_id}, #{amount}) #{ask} #{bid}"
|
|
60
|
+
puts api.close_position_market_order(pair, posi, pos_id, amount)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
if pos_side.downcase == 'sell'
|
|
64
|
+
posi = 'short'
|
|
65
|
+
#bidが売ったときより安ければ
|
|
66
|
+
if bid < pos_rate
|
|
67
|
+
puts "(#{posi}, #{pos_id}, #{amount}) #{ask} #{bid}"
|
|
68
|
+
puts api.close_position_market_order(pair, posi, pos_id, amount)
|
|
69
|
+
end
|
|
70
|
+
#askが売ったときより高ければ
|
|
71
|
+
if pos_rate < ask
|
|
72
|
+
puts "(#{posi}, #{pos_id}, #{amount}) #{ask} #{bid}"
|
|
73
|
+
puts api.close_position_market_order(pair, posi, pos_id, amount)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
res = api.position('open')
|
|
78
|
+
end #while
|
|
79
|
+
|
|
80
|
+
rescue Vexapion::HTTPError=> e
|
|
81
|
+
puts e.to_s
|
|
82
|
+
end
|
|
83
|
+
puts "\n\nEnd of #{__FILE__} test.\n\n"
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
require 'vexapion/coincheck'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
|
|
4
|
+
public = false
|
|
5
|
+
priv = true
|
|
6
|
+
|
|
7
|
+
pair = 'btc_jpy'
|
|
8
|
+
|
|
9
|
+
key_file = "key/cc.yml"
|
|
10
|
+
keydata = File.read(key_file)
|
|
11
|
+
key = YAML.load(keydata)
|
|
12
|
+
|
|
13
|
+
api = Vexapion::Coincheck.new(key['access-key'], key['secret-key'])
|
|
14
|
+
begin
|
|
15
|
+
|
|
16
|
+
if public == true
|
|
17
|
+
|
|
18
|
+
puts "api.ticker"
|
|
19
|
+
puts api.ticker
|
|
20
|
+
|
|
21
|
+
puts "api.trades"
|
|
22
|
+
puts api.trades
|
|
23
|
+
|
|
24
|
+
puts "api.order_books"
|
|
25
|
+
puts api.order_books
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
if priv == true
|
|
30
|
+
|
|
31
|
+
puts "api.balance"
|
|
32
|
+
res = api.balance
|
|
33
|
+
p res
|
|
34
|
+
#------------------------------------------------------
|
|
35
|
+
ask = api.ticker['ask'].to_i
|
|
36
|
+
puts ask
|
|
37
|
+
rate = (ask * 1.2).to_i
|
|
38
|
+
amount = (1100.0 / rate).to_f.round(3)
|
|
39
|
+
puts amount
|
|
40
|
+
#現物売り
|
|
41
|
+
#puts "api.order(#{pair}, 'sell', #{rate}, #{amount})"
|
|
42
|
+
#s = api.order(pair, 'sell', rate, amount)
|
|
43
|
+
#puts s
|
|
44
|
+
|
|
45
|
+
#sleep 10
|
|
46
|
+
#オーダー中のリスト
|
|
47
|
+
puts "api.opens"
|
|
48
|
+
res = api.opens
|
|
49
|
+
puts res
|
|
50
|
+
|
|
51
|
+
#orders = res['orders'][0]
|
|
52
|
+
#puts orders
|
|
53
|
+
#id = orders['id']
|
|
54
|
+
#puts "api.cancel(#{id})"
|
|
55
|
+
#puts api.cancel(id)
|
|
56
|
+
|
|
57
|
+
#sleep 10
|
|
58
|
+
|
|
59
|
+
#------------------------------------------------------
|
|
60
|
+
rate = api.ticker['bid'].to_i
|
|
61
|
+
amount = (1100.0 / rate).round(3) - 2
|
|
62
|
+
|
|
63
|
+
#現物売り
|
|
64
|
+
#puts "api.order(#{pair}, 'sell', #{rate}, #{amount})"
|
|
65
|
+
#s = api.order(pair, 'sell', rate, amount)
|
|
66
|
+
#puts s
|
|
67
|
+
|
|
68
|
+
#sleep 10
|
|
69
|
+
|
|
70
|
+
#現物買い
|
|
71
|
+
#rate = api.ticker['ask'].to_i
|
|
72
|
+
#amount = api.balance['jpy'].to_i
|
|
73
|
+
#puts "api.order(#{pair}, 'buy', #{rate}, #{amount})"
|
|
74
|
+
#b = api.order(pair, 'buy', rate, amount)
|
|
75
|
+
#puts b
|
|
76
|
+
|
|
77
|
+
#------------------------------------------------------
|
|
78
|
+
|
|
79
|
+
#sleep 10
|
|
80
|
+
rate = api.ticker['bid'].to_i
|
|
81
|
+
amount = (1100 / rate).round(3)
|
|
82
|
+
#現物成行売り
|
|
83
|
+
#puts "api.market_sell(#{pair}, #{amount})"
|
|
84
|
+
#puts api.market_sell(pair, amount)
|
|
85
|
+
|
|
86
|
+
#sleep 10
|
|
87
|
+
#amount_jpy = api.balance['jpy'].round - 100
|
|
88
|
+
#現物成行買い
|
|
89
|
+
#puts "api.market_buy(#{pair}, #{amount_jpy})"
|
|
90
|
+
#puts api.market_buy(pair, amount_jpy)
|
|
91
|
+
|
|
92
|
+
#------------------------------------------------------
|
|
93
|
+
|
|
94
|
+
cur = 'JPY'
|
|
95
|
+
#amount = 1000
|
|
96
|
+
#puts "api.to_leverage(#{cur}, #{amount})"
|
|
97
|
+
#res = api.to_leverage(cur, amount)
|
|
98
|
+
#p res
|
|
99
|
+
#------------------------------------------------------
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
#レバレッジ買い
|
|
103
|
+
rate = api.ticker['ask']
|
|
104
|
+
amount = 0.01
|
|
105
|
+
#puts "api.order_leverage(pair, 'buy', rate, amount)"
|
|
106
|
+
#leve = api.order_leverage(pair, 'buy', rate, amount)
|
|
107
|
+
#puts leve
|
|
108
|
+
#sleep 30
|
|
109
|
+
|
|
110
|
+
#puts "api.position('open')"
|
|
111
|
+
#res = api.position
|
|
112
|
+
#puts res
|
|
113
|
+
#res['data'].each do |pos|
|
|
114
|
+
# #pos = res['data'][0]
|
|
115
|
+
# pos_id = pos['id']
|
|
116
|
+
# pos_rate = pos['open_rate']
|
|
117
|
+
# pos_side = pos['side']
|
|
118
|
+
# amount = pos['amount']
|
|
119
|
+
|
|
120
|
+
# sleep 10
|
|
121
|
+
# tick = api.ticker
|
|
122
|
+
# ask = tick['ask']
|
|
123
|
+
# bid = tick['bid']
|
|
124
|
+
# if pos_side.downcase == 'buy'
|
|
125
|
+
# posi = 'long'
|
|
126
|
+
#bidが買ったときより高ければ レバレッジ返済
|
|
127
|
+
#if pos_rate * 1.005 <= bid
|
|
128
|
+
# puts "api.close_position_market_order(
|
|
129
|
+
# pair, #{posi}, #{pos_id}, #{amount})"
|
|
130
|
+
# puts api.close_position_market_order(pair, posi, pos_id, amount)
|
|
131
|
+
#end
|
|
132
|
+
#else
|
|
133
|
+
#posi = 'short'
|
|
134
|
+
|
|
135
|
+
#askが売ったときより安ければ レバレッジ返済
|
|
136
|
+
#if ask <= pos_rate * 0.995
|
|
137
|
+
# puts "api.close_position_market_order(
|
|
138
|
+
# pair, #{posi}, #{pos_id}, #{amount})"
|
|
139
|
+
# puts api.close_position_market_order(pair, posi, pos_id, amount)
|
|
140
|
+
#end
|
|
141
|
+
#end
|
|
142
|
+
|
|
143
|
+
#レバレッジ返済
|
|
144
|
+
#puts "api.close_position_market_order(pair, long, #{pos_id}, #{amount})"
|
|
145
|
+
#puts api.close_position_market_order(pair, 'long', pos_id, amount)
|
|
146
|
+
|
|
147
|
+
#end
|
|
148
|
+
#レバレッジ成行買い
|
|
149
|
+
#amount = 0.005
|
|
150
|
+
#puts "api.market_order_leverage(pair, 'buy', amount, stop_loss_rate = '')"
|
|
151
|
+
#leve = api.market_order_leverage(pair, 'buy', amount, stop_loss_rate = '')
|
|
152
|
+
#puts leve
|
|
153
|
+
#sleep 10
|
|
154
|
+
|
|
155
|
+
puts "api.leverage_balance"
|
|
156
|
+
puts api.leverage_balance
|
|
157
|
+
|
|
158
|
+
#レバレッジ成行売り
|
|
159
|
+
#position_id = leve['id']
|
|
160
|
+
#amount = leve['amount']
|
|
161
|
+
#puts "api.close_position_market_order(pair, 'long', position_id, amount)"
|
|
162
|
+
#puts api.close_position_market_order(pair, 'long', position_id, amount)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
#sleep 5
|
|
166
|
+
#bal = api.leverage_balance
|
|
167
|
+
#puts bal
|
|
168
|
+
#amount = bal['margin']['jpy']
|
|
169
|
+
#puts "api.from_leverage(#{cur}, #{amount})"
|
|
170
|
+
#res = api.from_leverage(cur, amount)
|
|
171
|
+
#p res
|
|
172
|
+
|
|
173
|
+
#------------------------------------------------------
|
|
174
|
+
|
|
175
|
+
puts "api.transactions"
|
|
176
|
+
puts api.transactions
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
#puts "api.send_money(address, amount)"
|
|
180
|
+
#puts api.send_money(address, amount)
|
|
181
|
+
|
|
182
|
+
puts "api.send_history(currency = 'BTC')"
|
|
183
|
+
puts api.send_history(currency = 'BTC')
|
|
184
|
+
|
|
185
|
+
puts "api.deposit_history(currency = 'BTC')"
|
|
186
|
+
puts api.deposit_history(currency = 'BTC')
|
|
187
|
+
|
|
188
|
+
#puts "api.deposit_accelerate(id)"
|
|
189
|
+
#puts api.deposit_accelerate(id)
|
|
190
|
+
|
|
191
|
+
puts "api.accounts"
|
|
192
|
+
puts api.accounts
|
|
193
|
+
|
|
194
|
+
puts "api.bank_accounts"
|
|
195
|
+
puts api.bank_accounts
|
|
196
|
+
|
|
197
|
+
#puts "api.regist_bank_account(bank, branch, type, number_str, name)"
|
|
198
|
+
#puts api.regist_bank_account(bank, branch, type, number_str, name)
|
|
199
|
+
|
|
200
|
+
#puts "api.delete_bank_account(id)"
|
|
201
|
+
#puts api.delete_bank_account(id)
|
|
202
|
+
|
|
203
|
+
puts "api.bank_withdraw_history"
|
|
204
|
+
puts api.bank_withdraw_history
|
|
205
|
+
|
|
206
|
+
#puts "api.bank_withdraw(id, amount, currency = 'JPY', is_fast = false)"
|
|
207
|
+
#puts api.bank_withdraw(id, amount, currency = 'JPY', is_fast = false)
|
|
208
|
+
|
|
209
|
+
#puts "api.cancel_bank_withdraw(id)"
|
|
210
|
+
#puts api.cancel_bank_withdraw(id)
|
|
211
|
+
|
|
212
|
+
#puts "api.borrow(amount, currency)"
|
|
213
|
+
#puts api.borrow(amount, currency)
|
|
214
|
+
|
|
215
|
+
puts "api.borrow_list"
|
|
216
|
+
puts api.borrow_list
|
|
217
|
+
|
|
218
|
+
#puts "api.repayment(id)"
|
|
219
|
+
#puts api.repayment(id)
|
|
220
|
+
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
rescue Vexapion::HTTPError=> e
|
|
224
|
+
puts e.to_s
|
|
225
|
+
end
|
|
226
|
+
puts "\n\nEnd of #{__FILE__} test.\n\n"
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
require 'vexapion/poloniex'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
key_file = "key/polo.yml"
|
|
6
|
+
file = File.read(key_file)
|
|
7
|
+
key = YAML.load(file)
|
|
8
|
+
api = Vexapion::Poloniex.new(key['access-key'], key['secret-key'])
|
|
9
|
+
|
|
10
|
+
pair = 'USDT_LTC'
|
|
11
|
+
|
|
12
|
+
mkt = 'BTC'
|
|
13
|
+
asset = 'LTC'
|
|
14
|
+
pair = "#{mkt}_#{asset}"
|
|
15
|
+
|
|
16
|
+
puts "api.ticker"
|
|
17
|
+
res = api.ticker
|
|
18
|
+
ask = res[pair]['lowestAsk'].to_f
|
|
19
|
+
bid = res[pair]['highestBid'].to_f
|
|
20
|
+
puts "ask: %10.8f bid:%10.8f"%[ask, bid]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
res = api.complete_balances
|
|
24
|
+
mkt_amount = res[mkt]['available'].to_f
|
|
25
|
+
asset_amount = res[asset]['available'].to_f
|
|
26
|
+
puts "%s: %12.8f %s: %12.8f"%[mkt, mkt_amount, asset, asset_amount]
|
|
27
|
+
|
|
28
|
+
amount = 0.05
|
|
29
|
+
|
|
30
|
+
puts "api.sell(#{pair}, #{ask+10}, #{amount})"
|
|
31
|
+
res = api.sell(pair, ask+10, amount)
|
|
32
|
+
puts res
|
|
33
|
+
order_number = res['orderNumber']
|
|
34
|
+
sleep 0.5
|
|
35
|
+
|
|
36
|
+
puts "api.move_order(#{order_number}, #{ask})"
|
|
37
|
+
res = api.move_order(order_number, ask)
|
|
38
|
+
puts res
|
|
39
|
+
order_number = res['orderNumber']
|
|
40
|
+
puts order_number
|
|
41
|
+
sleep 0.5
|
|
42
|
+
|
|
43
|
+
puts "api.cancel_order(#{order_number})"
|
|
44
|
+
puts api.cancel_order(order_number)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
res = api.ticker
|
|
48
|
+
ask = res[pair]['lowestAsk'].to_f
|
|
49
|
+
bid = res[pair]['highestBid'].to_f
|
|
50
|
+
puts "ask: %10.8f bid:%10.8f"%[ask, bid]
|
|
51
|
+
|
|
52
|
+
puts "api.sell(#{pair}, #{bid}, #{amount})"
|
|
53
|
+
res = api.sell(pair, bid, amount)
|
|
54
|
+
puts res
|
|
55
|
+
order_number = res['order_number']
|
|
56
|
+
sleep 3
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
res = api.available_account_balances
|
|
60
|
+
amount = (res['exchange'][mkt].to_f / ask).round(3)
|
|
61
|
+
puts "api.buy(#{pair}, #{ask}, #{amount})"
|
|
62
|
+
res = api.buy(pair, ask, amount)
|
|
63
|
+
puts res
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
mkt = 'BTC'
|
|
67
|
+
asset = 'STR'
|
|
68
|
+
pair = "#{mkt}_#{asset}"
|
|
69
|
+
|
|
70
|
+
res = api.ticker
|
|
71
|
+
ask = res[pair]['lowestAsk'].to_f
|
|
72
|
+
bid = res[pair]['highestBid'].to_f
|
|
73
|
+
puts "ask: %10.8f bid:%10.8f"%[ask, bid]
|
|
74
|
+
amount = 1000
|
|
75
|
+
buy_rate = bid
|
|
76
|
+
|
|
77
|
+
puts 'api.margin_sell(#{pair}, #{buy_rate}, #{amount})'
|
|
78
|
+
res = api.margin_sell(pair, buy_rate, amount)
|
|
79
|
+
puts res
|
|
80
|
+
sleep 15
|
|
81
|
+
|
|
82
|
+
res = api.complete_balances
|
|
83
|
+
mkt_amount = res[mkt]['available'].to_f
|
|
84
|
+
asset_amount = res[asset]['available'].to_f
|
|
85
|
+
puts "%s: %12.8f %s: %12.8f"%[mkt, mkt_amount, asset, asset_amount]
|
|
86
|
+
|
|
87
|
+
res = api.ticker
|
|
88
|
+
ask = res[pair]['lowestAsk'].to_f
|
|
89
|
+
bid = res[pair]['highestBid'].to_f
|
|
90
|
+
puts "ask: %10.8f bid:%10.8f"%[ask, bid]
|
|
91
|
+
|
|
92
|
+
#flag = true
|
|
93
|
+
#while flag
|
|
94
|
+
#if ask <= buy_rate * 0.998
|
|
95
|
+
puts 'api.margin_buy(#{pair}, #{ask}, #{amount})'
|
|
96
|
+
res = api.margin_buy(pair, ask, amount)
|
|
97
|
+
puts res
|
|
98
|
+
flag = false
|
|
99
|
+
|
|
100
|
+
#end
|
|
101
|
+
sleep 1
|
|
102
|
+
res = api.ticker
|
|
103
|
+
ask = res[pair]['lowestAsk'].to_f
|
|
104
|
+
bid = res[pair]['highestBid'].to_f
|
|
105
|
+
|
|
106
|
+
#end
|
|
107
|
+
puts 'api.margin_account_summary'
|
|
108
|
+
puts api.margin_account_summary
|
|
109
|
+
|
|
110
|
+
puts 'api.available_account_balances'
|
|
111
|
+
puts api.available_account_balances
|
|
112
|
+
|
|
113
|
+
currency = 'LTC'
|
|
114
|
+
amount = 1
|
|
115
|
+
from_account = 'Margin'
|
|
116
|
+
to_account = 'Exchange'
|
|
117
|
+
puts "api.transfer_balance(#{currency}, #{amount},
|
|
118
|
+
#{from_account.downcase}, #{to_account.downcase})"
|
|
119
|
+
puts api.transfer_balance(currency, amount,
|
|
120
|
+
from_account.downcase, to_account.downcase)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
#puts "api.withdraw(currency, amount, address)"
|
|
125
|
+
#puts api.withdraw(currency, amount, address)
|
|
126
|
+
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
require 'vexapion/poloniex'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
|
|
4
|
+
key_file = "key/polo.yml"
|
|
5
|
+
file = File.read(key_file)
|
|
6
|
+
key = YAML.load(file)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
api = Vexapion::Poloniex.new(key['access-key'], key['secret-key'])
|
|
10
|
+
#pair = 'ltc_usdt'.upcase
|
|
11
|
+
pair = 'usdt_ltc'
|
|
12
|
+
|
|
13
|
+
public = true
|
|
14
|
+
priv = true
|
|
15
|
+
|
|
16
|
+
#puts "api.ticker"
|
|
17
|
+
#puts api.ticker
|
|
18
|
+
|
|
19
|
+
if public == true
|
|
20
|
+
puts "api.volume_24hours"
|
|
21
|
+
puts api.volume_24hours
|
|
22
|
+
|
|
23
|
+
puts "api.ticker"
|
|
24
|
+
puts api.ticker
|
|
25
|
+
|
|
26
|
+
depth = 25
|
|
27
|
+
puts "api.orderbook(pair, depth)"
|
|
28
|
+
puts api.orderbook(pair, depth)
|
|
29
|
+
|
|
30
|
+
puts "api.market_trade_history(pair)"
|
|
31
|
+
puts api.market_trade_history(pair)
|
|
32
|
+
|
|
33
|
+
puts "api.fee_info"
|
|
34
|
+
puts api.fee_info
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
#puts api.balances
|
|
38
|
+
#puts api.balances
|
|
39
|
+
|
|
40
|
+
if priv == true
|
|
41
|
+
puts api.balances
|
|
42
|
+
puts api.balances
|
|
43
|
+
|
|
44
|
+
puts api.complete_balances
|
|
45
|
+
puts api.complete_balances
|
|
46
|
+
|
|
47
|
+
puts api.open_orders(pair)
|
|
48
|
+
puts api.open_orders(pair)
|
|
49
|
+
|
|
50
|
+
end_time = Time.now.to_i
|
|
51
|
+
start = end_time - 60 * 60 * 24 * 30
|
|
52
|
+
puts "api.trade_history(pair, start, end_time)"
|
|
53
|
+
puts api.trade_history(pair, start, end_time)
|
|
54
|
+
|
|
55
|
+
#puts "api.sell(pair, rate, amount)"
|
|
56
|
+
#puts api.sell(pair, rate, amount)
|
|
57
|
+
|
|
58
|
+
#puts "api.buy(pair, rate, amount)"
|
|
59
|
+
#puts api.buy(pair, rate, amount)
|
|
60
|
+
|
|
61
|
+
#puts "api.cancel_order(order_number)"
|
|
62
|
+
#puts api.cancel_order(order_number)
|
|
63
|
+
|
|
64
|
+
#puts "api.move_order(order_number, rate)"
|
|
65
|
+
#puts api.move_order(order_number, rate)
|
|
66
|
+
|
|
67
|
+
currency = 'btc'
|
|
68
|
+
|
|
69
|
+
#puts "api.withdraw(currency, amount, address)"
|
|
70
|
+
#puts api.withdraw(currency, amount, address)
|
|
71
|
+
|
|
72
|
+
puts "api.available_account_balances"
|
|
73
|
+
puts api.available_account_balances
|
|
74
|
+
|
|
75
|
+
puts "api.tradable_balances"
|
|
76
|
+
puts api.tradable_balances
|
|
77
|
+
|
|
78
|
+
#puts "api.transfer_balance(currency, amount, from_account, to_account)"
|
|
79
|
+
#puts api.transfer_balance(currency, amount, from_account, to_account)
|
|
80
|
+
|
|
81
|
+
puts "api.margin_account_summary"
|
|
82
|
+
puts api.margin_account_summary
|
|
83
|
+
|
|
84
|
+
#puts "api.margin_buy(pair, rate, amount)"
|
|
85
|
+
#puts api.margin_buy(pair, rate, amount)
|
|
86
|
+
|
|
87
|
+
#puts "api.margin_sell(currency_pair, rate, amount)"
|
|
88
|
+
#puts api.margin_sell(currency_pair, rate, amount)
|
|
89
|
+
|
|
90
|
+
puts "api.deposit_addresses"
|
|
91
|
+
puts api.deposit_addresses
|
|
92
|
+
|
|
93
|
+
currency = 'dash'
|
|
94
|
+
#puts "api.generate_new_address(currency)"
|
|
95
|
+
#puts api.generate_new_address(currency)
|
|
96
|
+
|
|
97
|
+
count = 5
|
|
98
|
+
puts "api.deposits_withdrawals(start, end_time, count)"
|
|
99
|
+
puts api.deposits_withdrawals(start, end_time, count)
|
|
100
|
+
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require 'vexapion'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
|
|
4
|
+
@pair = 'xem_jpy'
|
|
5
|
+
|
|
6
|
+
key_file = "key/zaif.yml"
|
|
7
|
+
key = YAML.load( File.read(key_file) )
|
|
8
|
+
@api = Vexapion::Zaif.new(key['access-key'], key['secret-key'])
|
|
9
|
+
|
|
10
|
+
def ticker
|
|
11
|
+
res = @api.ticker(@pair)
|
|
12
|
+
ask = res['ask']
|
|
13
|
+
bid = res['bid']
|
|
14
|
+
{ ask: ask, bid: bid }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def balance
|
|
18
|
+
res = @api.get_info2
|
|
19
|
+
funds = res['return']['funds']
|
|
20
|
+
avail = Hash.new
|
|
21
|
+
avail['jpy'] = funds['jpy']
|
|
22
|
+
avail['btc'] = funds['btc']
|
|
23
|
+
avail['xem'] = funds['xem']
|
|
24
|
+
|
|
25
|
+
avail
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
tick = ticker
|
|
29
|
+
avail = balance
|
|
30
|
+
|
|
31
|
+
price = (tick[:ask] * 1.1).round(4)
|
|
32
|
+
puts "price: #{avail}"
|
|
33
|
+
amount = 100
|
|
34
|
+
puts "\nxem_jpy: ask: %6.4f / amount: %6.1f"%[price, amount]
|
|
35
|
+
|
|
36
|
+
puts "@api.trade(#{@pair}, 'ask', #{price.to_f}, #{amount.to_f})"
|
|
37
|
+
res = @api.trade(@pair, 'ask', price.to_f, amount.to_f) #, tick[:bid].to_f)
|
|
38
|
+
puts res
|
|
39
|
+
|
|
40
|
+
res = @api.active_orders(@pair)
|
|
41
|
+
puts ""
|
|
42
|
+
puts res
|
|
43
|
+
id = ''
|
|
44
|
+
res['return'].each do |k, v|
|
|
45
|
+
id = k
|
|
46
|
+
end
|
|
47
|
+
puts id
|
|
48
|
+
sleep 10
|
|
49
|
+
res = @api.cancel_order(id)
|
|
50
|
+
puts res
|
|
51
|
+
|
|
52
|
+
res = @api.trade_history(@pair)
|
|
53
|
+
puts res
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
currency = 'btc'
|
|
57
|
+
res = @api.deposit_history(currency)
|
|
58
|
+
puts res
|
|
59
|
+
res = @api.withdraw_history(currency)
|
|
60
|
+
puts res
|
|
61
|
+
|
|
62
|
+
#res = @api.withdraw(currency, amount, address, fee, message)
|
|
63
|
+
#puts res
|
|
64
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require 'vexapion/zaif'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
|
|
4
|
+
local = true
|
|
5
|
+
public = true
|
|
6
|
+
priv = true
|
|
7
|
+
|
|
8
|
+
pair = 'btc_jpy'
|
|
9
|
+
|
|
10
|
+
key_file = "key/zaif.yml"
|
|
11
|
+
key = YAML.load( File.read(key_file) )
|
|
12
|
+
api = Vexapion::Zaif.new(key['access-key'], key['secret-key'])
|
|
13
|
+
|
|
14
|
+
if local == true
|
|
15
|
+
puts api.available_pair
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
if public == true
|
|
19
|
+
puts api.last_price(pair)
|
|
20
|
+
puts api.ticker(pair)
|
|
21
|
+
puts api.trades(pair)
|
|
22
|
+
puts api.depth(pair)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
if priv == true
|
|
26
|
+
puts api.get_info
|
|
27
|
+
puts api.get_info2
|
|
28
|
+
puts api.get_personal_info
|
|
29
|
+
puts api.active_orders(pair = '')
|
|
30
|
+
#puts api.trade(pair, action, price, amount, limit = '')
|
|
31
|
+
#puts api.cancel_order(id)
|
|
32
|
+
puts api.trade_history(pair)
|
|
33
|
+
|
|
34
|
+
currency = 'btc'
|
|
35
|
+
|
|
36
|
+
#puts api.withdraw(currency, amount, address, fee = nil, message = nil)
|
|
37
|
+
|
|
38
|
+
puts api.deposit_history(currency)
|
|
39
|
+
puts api.withdraw_history(currency)
|
|
40
|
+
end
|
data/lib/vexapion/version.rb
CHANGED
data/vexapion.gemspec
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'vexapion/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "vexapion"
|
|
8
|
+
spec.version = Vexapion::VERSION
|
|
9
|
+
spec.authors = ["fuyuton"]
|
|
10
|
+
spec.email = ["fuyuton@pastelpink.sakura.ne.jp"]
|
|
11
|
+
spec.summary = %q{Virtual currency Exchanger API wrapper}
|
|
12
|
+
spec.description = %q{This is a low layer API wrapper for easy connection to exchanges.}
|
|
13
|
+
spec.homepage = "https://github.com/fuyuton/vexapion"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|unimplement|Gemfile.lock)/}) }
|
|
17
|
+
#spec.files = Dir['{lib}/*.rb', '{lib}/*/*.rb', '{lib}/**/errors/*', '{lib}/**/connect/*']
|
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
20
|
+
spec.require_paths = ["lib"]
|
|
21
|
+
|
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
24
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vexapion
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- fuyuton
|
|
@@ -41,10 +41,18 @@ dependencies:
|
|
|
41
41
|
description: This is a low layer API wrapper for easy connection to exchanges.
|
|
42
42
|
email:
|
|
43
43
|
- fuyuton@pastelpink.sakura.ne.jp
|
|
44
|
-
executables:
|
|
44
|
+
executables:
|
|
45
|
+
- console
|
|
46
|
+
- setup
|
|
45
47
|
extensions: []
|
|
46
48
|
extra_rdoc_files: []
|
|
47
49
|
files:
|
|
50
|
+
- ".gitignore"
|
|
51
|
+
- Gemfile
|
|
52
|
+
- README.md
|
|
53
|
+
- Rakefile
|
|
54
|
+
- bin/console
|
|
55
|
+
- bin/setup
|
|
48
56
|
- lib/vexapion.rb
|
|
49
57
|
- lib/vexapion/base_exchanges.rb
|
|
50
58
|
- lib/vexapion/bitflyer.rb
|
|
@@ -54,13 +62,21 @@ files:
|
|
|
54
62
|
- lib/vexapion/errors/vexapion_errors.rb
|
|
55
63
|
- lib/vexapion/poloniex.rb
|
|
56
64
|
- lib/vexapion/template.rb
|
|
65
|
+
- lib/vexapion/test/bf-trade.rb
|
|
66
|
+
- lib/vexapion/test/bf.rb
|
|
67
|
+
- lib/vexapion/test/cc-trade.rb
|
|
68
|
+
- lib/vexapion/test/cc.rb
|
|
69
|
+
- lib/vexapion/test/polo-trade.rb
|
|
70
|
+
- lib/vexapion/test/polo.rb
|
|
71
|
+
- lib/vexapion/test/z-trade.rb
|
|
72
|
+
- lib/vexapion/test/z.rb
|
|
57
73
|
- lib/vexapion/version.rb
|
|
58
74
|
- lib/vexapion/zaif.rb
|
|
75
|
+
- vexapion.gemspec
|
|
59
76
|
homepage: https://github.com/fuyuton/vexapion
|
|
60
77
|
licenses:
|
|
61
78
|
- MIT
|
|
62
|
-
metadata:
|
|
63
|
-
allowed_push_host: https://rubygems.org
|
|
79
|
+
metadata: {}
|
|
64
80
|
post_install_message:
|
|
65
81
|
rdoc_options: []
|
|
66
82
|
require_paths:
|