rapflag 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -1
- data/Gemfile +2 -0
- data/History.md +5 -0
- data/bin/rapflag +17 -5
- data/fixtures/vcr_cassettes/rapflag.yml +44 -0
- data/lib/rapflag/bitfinex.rb +93 -0
- data/lib/rapflag/config.rb +0 -6
- data/lib/rapflag/history.rb +125 -0
- data/lib/rapflag/poloniex.rb +325 -0
- data/lib/rapflag/version.rb +1 -1
- data/rapflag.gemspec +1 -0
- data/spec/bitfinex_spec.rb +128 -0
- data/spec/poloniex_spec.rb +115 -0
- data/spec/spec_helper.rb +6 -0
- metadata +24 -5
- data/lib/rapflag/fetch.rb +0 -176
- data/spec/rapflag_spec.rb +0 -115
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf77cd7aa17cec03df50282786fae729745f32c9
|
4
|
+
data.tar.gz: 403016b3360c78132875e77fada372c6a7a87f17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc5a72e89543897293f2656d11427a51605c79cd54cf5f6455567bc0c76ac152c6df06dbd1ee5fffee594199385d80aae421796997c29499c94f65bcab25270d
|
7
|
+
data.tar.gz: ad801b4f615cb0d5611eb5c206cad24ebdfeb18d3956a3ea3a77faecf27eb20e84dd36c5abe4bdda5a02705229accc5f2f5bed05c807687ce3db03c457fce860
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/History.md
ADDED
data/bin/rapflag
CHANGED
@@ -3,7 +3,8 @@ dir = File.expand_path(File.dirname(File.dirname(__FILE__)))
|
|
3
3
|
$LOAD_PATH << File.join(dir, 'lib')
|
4
4
|
require 'rapflag/version'
|
5
5
|
require 'rapflag/config'
|
6
|
-
require 'rapflag/
|
6
|
+
require 'rapflag/bitfinex'
|
7
|
+
require 'rapflag/poloniex'
|
7
8
|
require 'trollop'
|
8
9
|
|
9
10
|
begin
|
@@ -13,13 +14,24 @@ end
|
|
13
14
|
|
14
15
|
Opts = Trollop::options do
|
15
16
|
opt :clean, "Create summary of transactions by day"
|
17
|
+
opt :poloniex, "Use Poloniex API instead of Bitfinex API"
|
18
|
+
opt :dump, "Use Poloniex API and dump history into CSV files"
|
16
19
|
end
|
17
20
|
|
18
21
|
RAPFLAG::Wallets.each do |wallet|
|
19
22
|
RAPFLAG::Config['currencies'].each do |currency|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
if Opts[:poloniex]
|
24
|
+
crypto_api = RAPFLAG::Poloniex.new(wallet, currency)
|
25
|
+
else
|
26
|
+
crypto_api = RAPFLAG::Bitfinex.new(wallet, currency)
|
27
|
+
end
|
28
|
+
if Opts[:dump]
|
29
|
+
crypto_api.dump_history
|
30
|
+
exit(0)
|
31
|
+
end
|
32
|
+
crypto_api.fetch_csv_history
|
33
|
+
exit(0) if Opts[:poloniex]
|
34
|
+
crypto_api.create_csv_file
|
35
|
+
crypto_api.create_summary if Opts[:clean]
|
24
36
|
end
|
25
37
|
end
|
@@ -418,4 +418,48 @@ http_interactions:
|
|
418
418
|
string: "[[1489363200000,0.8717,0.8793,0.8793,0.8652,28134.30007514],[1489276800000,0.875,0.8717,0.879,0.85101,243519.87684517],[1489190400000,0.86864,0.87499,0.9,0.86,441408.45443568],[1489104000000,0.8741,0.867,0.9,0.851,923547.49462454],[1489017600000,0.86447,0.8771,0.8849,0.8601,69778.53551027],[1488931200000,0.888,0.87652,0.8999,0.86,253035.27171289],[1488844800000,0.9,0.88859,0.9022,0.871,105261.98010844],[1488758400000,0.89003,0.895,0.90285,0.87633,336521.30762563],[1488672000000,0.89001,0.89003,0.8985,0.89,56086.79270542],[1488585600000,0.87989,0.89,0.902,0.8652,289529.60523622],[1488499200000,0.8902,0.8825,0.893,0.864,540453.19236899],[1488412800000,0.89391,0.89,0.9,0.87,468911.9407224],[1488326400000,0.8944,0.8851,0.8987,0.885,63532.34127196],[1488240000000,0.875,0.8997,0.91,0.87291,566659.07956909],[1488153600000,0.869,0.87012,0.87889,0.8627,144892.27628249],[1488067200000,0.851,0.869,0.878,0.8484,515905.82224763],[1487980800000,0.8499,0.8542,0.8547,0.84,115783.00365869],[1487894400000,0.8398,0.845,0.8548,0.82881,300575.72800591],[1487808000000,0.84181,0.839,0.8488,0.83035,75316.36503842],[1487721600000,0.84979,0.8335,0.8499,0.82,145363.28163461],[1487635200000,0.85,0.8445,0.85067,0.832,251648.99451942],[1487548800000,0.84379,0.85,0.85,0.84,109452.47640138],[1487462400000,0.838,0.84,0.84499,0.83301,28404.95416129],[1487376000000,0.8342,0.838,0.8408,0.832,49996.59123255],[1487289600000,0.8365,0.836,0.85,0.82732,245950.8587662],[1487203200000,0.82361,0.83,0.84,0.81316,202499.34273437],[1487116800000,0.81497,0.8282,0.833,0.81081,84004.02947833],[1487030400000,0.819,0.8154,0.8331,0.81,111489.34342463],[1486944000000,0.8011,0.82,0.82,0.8,69217.8466632],[1486857600000,0.81,0.80969,0.81231,0.79522,7220.41251019],[1486771200000,0.81275,0.8099,0.82,0.7923,75919.80448897],[1486684800000,0.811,0.81275,0.821,0.8,150493.04656476],[1486598400000,0.821,0.8051,0.8356,0.77,790581.93256653],[1486512000000,0.8011,0.825,0.84,0.801,330401.04372136],[1486425600000,0.79991,0.8067,0.86,0.79991,1218174.13114576],[1486339200000,0.8,0.7999,0.809,0.798,51325.36930155],[1486252800000,0.76849,0.7999,0.82,0.7684,372082.94755947],[1486166400000,0.77575,0.7684,0.8,0.76,512423.37251592],[1486080000000,0.76454,0.76049,0.82488,0.7601,1235550.16947156],[1485993600000,0.7739,0.7733,0.7739,0.7511,419485.3975492],[1485907200000,0.74899,0.7748,0.7748,0.7401,416657.92432361],[1485820800000,0.7349,0.74577,0.75,0.7261,392621.81484058],[1485734400000,0.71999,0.735,0.735,0.7117,123839.41033231],[1485648000000,0.7092,0.711,0.72,0.70222,78865.06844947],[1485561600000,0.71999,0.70001,0.72,0.7,66319.72995194],[1485475200000,0.706,0.71001,0.72,0.69768,197504.84706629],[1485388800000,0.67314,0.704,0.71,0.66501,490843.78353094],[1485302400000,0.67,0.665,0.67987,0.665,31460.28781611],[1485216000000,0.67989,0.67,0.69,0.67,63888.06958776],[1485129600000,0.68225,0.68668,0.695,0.675,48922.17674387],[1485043200000,0.699,0.68223,0.699,0.67012,91996.64562027],[1484956800000,0.6855,0.692,0.7021,0.6791,101993.68583522],[1484870400000,0.68669,0.685,0.699,0.68375,100180.56460246],[1484784000000,0.68,0.6867,0.7025,0.6687,649505.00402726],[1484697600000,0.6342,0.68375,0.6945,0.6342,722911.29974448],[1484611200000,0.60124,0.6386,0.6489,0.5863,516186.44196343],[1484524800000,0.59375,0.6,0.60774,0.59251,62811.15764391],[1484438400000,0.5878,0.59375,0.616,0.581,182417.51603181],[1484352000000,0.59732,0.5865,0.60932,0.5861,52557.32057884],[1484265600000,0.613,0.60594,0.6288,0.58554,279881.05444294],[1484179200000,0.56269,0.60932,0.6259,0.5455,906197.16431742],[1484092800000,0.5697,0.57,0.58283,0.5501,993936.66527738],[1484006400000,0.5699,0.5697,0.6,0.565,479940.5750157],[1483920000000,0.5598,0.5687,0.5729,0.55132,329146.4819496],[1483833600000,0.5652,0.5649,0.5689,0.5501,97288.348568],[1483747200000,0.557,0.5652,0.56525,0.53892,454727.74806088],[1483660800000,0.54909,0.5491,0.5689,0.5451,203904.48010302],[1483574400000,0.5539,0.55201,0.573,0.5377,457411.4220489],[1483488000000,0.565,0.5491,0.57891,0.5475,400524.72904162],[1483401600000,0.55998,0.55693,0.577,0.54551,160075.95565879],[1483315200000,0.558,0.5525,0.572,0.5455,133718.06884032],[1483228800000,0.529,0.56006,0.56195,0.5278,128780.22146626],[1483142400000,0.5322,0.5374,0.54599,0.529,44383.44032481],[1483056000000,0.55653,0.531,0.55653,0.52789,290837.34805605],[1482969600000,0.534,0.55161,0.55622,0.518,243542.25886407],[1482883200000,0.50588,0.53287,0.5391,0.505,299748.8471437],[1482796800000,0.49633,0.501,0.51978,0.49591,233956.9223055],[1482710400000,0.50466,0.49801,0.51448,0.4935,108493.8375305],[1482624000000,0.51491,0.49816,0.5219,0.4934,120561.41212536],[1482537600000,0.51364,0.5165,0.51986,0.50513,99061.59607589],[1482451200000,0.513,0.50512,0.5263,0.50512,259476.87918021],[1482364800000,0.5095,0.513,0.5247,0.49,298334.06324882],[1482278400000,0.5267,0.51488,0.5328,0.5048,366376.10430987],[1482192000000,0.5346,0.52671,0.5375,0.52671,187976.15133769],[1482105600000,0.53989,0.5346,0.54663,0.5346,62849.91816306],[1482019200000,0.5404,0.5346,0.5406,0.5346,25173.22122431],[1481932800000,0.53579,0.5347,0.54499,0.5297,262970.48780991],[1481846400000,0.52759,0.536,0.538,0.52759,48598.23482657],[1481760000000,0.525,0.5302,0.53629,0.525,33085.14145397],[1481673600000,0.52601,0.525,0.52929,0.525,31545.13039527],[1481587200000,0.53489,0.526,0.537,0.526,28223.40346435],[1481500800000,0.51901,0.5289,0.538,0.5139,134818.31297537],[1481414400000,0.5152,0.5222,0.5314,0.5106,126160.11540098],[1481328000000,0.5152,0.5154,0.52,0.5151,28107.52209897],[1481241600000,0.53,0.5152,0.53,0.5151,65443.35145207],[1481155200000,0.53091,0.5315,0.538,0.5151,159612.3195684],[1481068800000,0.5389,0.53081,0.5389,0.52731,143493.48529196],[1480982400000,0.5379,0.5323,0.5469,0.52151,122801.79769989],[1480896000000,0.5302,0.536,0.54054,0.52,238666.48276357],[1480809600000,0.54019,0.5301,0.5419,0.52482,253305.10020895],[1480723200000,0.5422,0.5404,0.54575,0.5393,32566.54478732],[1480636800000,0.54856,0.54289,0.55588,0.5393,328308.50173319],[1480550400000,0.54932,0.54898,0.55888,0.5475,120793.16140955],[1480464000000,0.55429,0.5506,0.565,0.541,196113.9666031],[1480377600000,0.5513,0.5523,0.55669,0.54,291150.58974002],[1480291200000,0.5786,0.5513,0.5799,0.546,244352.11972233],[1480204800000,0.5845,0.5805,0.5876,0.574,116085.76061325],[1480118400000,0.58501,0.5845,0.5903,0.5845,56083.08346361],[1480032000000,0.596,0.58501,0.596,0.585,206678.79181774],[1479945600000,0.5729,0.607,0.607,0.57,478162.50230475],[1479859200000,0.56372,0.5703,0.5769,0.56372,77176.06333753],[1479772800000,0.57,0.5665,0.57,0.56354,44021.49357207],[1479686400000,0.56801,0.57,0.57001,0.5606,544549.95485346],[1479600000000,0.5687,0.5674,0.571,0.5657,76298.62119632],[1479513600000,0.57001,0.5687,0.572,0.56525,83950.82206462],[1479427200000,0.5608,0.57489,0.58,0.5559,320910.92958937],[1479340800000,0.5692,0.55785,0.579,0.5553,104317.24740244],[1479254400000,0.5478,0.5705,0.5849,0.535,737573.93477848],[1479168000000,0.55,0.5436,0.55078,0.5386,101507.77262058],[1479081600000,0.55,0.5452,0.5589,0.527,390221.49694999]]"
|
419
419
|
http_version:
|
420
420
|
recorded_at: Mon, 13 Mar 2017 13:10:46 GMT
|
421
|
+
- request:
|
422
|
+
method: get
|
423
|
+
uri: https://api.bitfinex.com/v2/candles/trade:1D:tBFXUSD/hist?start%3A1452812400000
|
424
|
+
body:
|
425
|
+
encoding: US-ASCII
|
426
|
+
string: ''
|
427
|
+
headers:
|
428
|
+
User-Agent:
|
429
|
+
- Faraday v0.9.2
|
430
|
+
response:
|
431
|
+
status:
|
432
|
+
code: 200
|
433
|
+
message:
|
434
|
+
headers:
|
435
|
+
date:
|
436
|
+
- Mon, 03 Apr 2017 11:56:18 GMT
|
437
|
+
content-type:
|
438
|
+
- application/json; charset=utf-8
|
439
|
+
transfer-encoding:
|
440
|
+
- chunked
|
441
|
+
connection:
|
442
|
+
- close
|
443
|
+
set-cookie:
|
444
|
+
- __cfduid=d15eba25375dcd03bbe030a768e8e74f41491220578; expires=Tue, 03-Apr-18
|
445
|
+
11:56:18 GMT; path=/; domain=.bitfinex.com; HttpOnly
|
446
|
+
vary:
|
447
|
+
- Accept-Encoding
|
448
|
+
x-powered-by:
|
449
|
+
- Express
|
450
|
+
etag:
|
451
|
+
- W/"1b8f-Cp2jfkke8UTvAgPtkJ1TsgPj5wE"
|
452
|
+
access-control-allow-origin:
|
453
|
+
- "*"
|
454
|
+
access-control-allow-headers:
|
455
|
+
- X-BFX-APIKEY,X-BFX-PAYLOAD,X-BFX-SIGNATURE,Content-Type,X-CSRF-Token,bfx-token,bfx-signature,bfx-apikey,bfx-nonce
|
456
|
+
server:
|
457
|
+
- cloudflare-nginx
|
458
|
+
cf-ray:
|
459
|
+
- 349bd804af733eb0-ZRH
|
460
|
+
body:
|
461
|
+
encoding: ASCII-8BIT
|
462
|
+
string: "[[1491177600000,0.976,0.9811,0.99,0.97,729966.23114872],[1491091200000,0.973,0.975,0.9799,0.973,61083.50514924],[1491004800000,0.96512,0.973,0.98,0.9635,312641.41056388],[1490918400000,0.971,0.96512,0.9799,0.965,219711.29830056],[1490832000000,0.979,0.96912,0.9825,0.9686,424210.38212123],[1490745600000,0.97031,0.976,0.9815,0.9687,54539.10722358],[1490659200000,0.975,0.97931,0.981,0.967,78696.23581904],[1490572800000,0.972,0.9817,0.9826,0.969,90854.40037865],[1490486400000,0.966,0.972,0.97725,0.96031,137801.05605047],[1490400000000,0.9778,0.97,0.9826,0.9631,218856.68003922],[1490313600000,0.9762,0.96316,0.9828,0.96316,896303.96505809],[1490227200000,0.985,0.9827,0.991,0.97271,481539.53495621],[1490140800000,0.9849,0.9789,0.99,0.9611,644146.38677298],[1490054400000,0.9874,0.9798,0.9878,0.97112,282109.19913051],[1489968000000,0.98,0.97851,0.9898,0.9635,464640.8206998],[1489881600000,0.9551,0.9751,0.99495,0.9551,527263.16799772],[1489795200000,0.989,0.96,0.989,0.951,857166.46079734],[1489708800000,0.96909,0.988,0.99016,0.95041,1831465.54766939],[1489622400000,0.9598,0.968,0.9745,0.93011,707134.11816577],[1489536000000,0.914,0.9481,0.987,0.914,1475989.57955641],[1489449600000,0.8751,0.91,0.932,0.865,901060.94224302],[1489363200000,0.8717,0.8761,0.883,0.8652,376298.09728602],[1489276800000,0.875,0.8717,0.879,0.85101,243519.87684517],[1489190400000,0.86864,0.87499,0.9,0.86,441408.45443568],[1489104000000,0.8741,0.867,0.9,0.851,923547.49462454],[1489017600000,0.86447,0.8771,0.8849,0.8601,69778.53551027],[1488931200000,0.888,0.87652,0.8999,0.86,253035.27171289],[1488844800000,0.9,0.88859,0.9022,0.871,105261.98010844],[1488758400000,0.89003,0.895,0.90285,0.87633,336521.30762563],[1488672000000,0.89001,0.89003,0.8985,0.89,56086.79270542],[1488585600000,0.87989,0.89,0.902,0.8652,289529.60523622],[1488499200000,0.8902,0.8825,0.893,0.864,540453.19236899],[1488412800000,0.89391,0.89,0.9,0.87,468911.9407224],[1488326400000,0.8944,0.8851,0.8987,0.885,63532.34127196],[1488240000000,0.875,0.8997,0.91,0.87291,566659.07956909],[1488153600000,0.869,0.87012,0.87889,0.8627,144892.27628249],[1488067200000,0.851,0.869,0.878,0.8484,515905.82224763],[1487980800000,0.8499,0.8542,0.8547,0.84,115783.00365869],[1487894400000,0.8398,0.845,0.8548,0.82881,300575.72800591],[1487808000000,0.84181,0.839,0.8488,0.83035,75316.36503842],[1487721600000,0.84979,0.8335,0.8499,0.82,145363.28163461],[1487635200000,0.85,0.8445,0.85067,0.832,251648.99451942],[1487548800000,0.84379,0.85,0.85,0.84,109452.47640138],[1487462400000,0.838,0.84,0.84499,0.83301,28404.95416129],[1487376000000,0.8342,0.838,0.8408,0.832,49996.59123255],[1487289600000,0.8365,0.836,0.85,0.82732,245950.8587662],[1487203200000,0.82361,0.83,0.84,0.81316,202499.34273437],[1487116800000,0.81497,0.8282,0.833,0.81081,84004.02947833],[1487030400000,0.819,0.8154,0.8331,0.81,111489.34342463],[1486944000000,0.8011,0.82,0.82,0.8,69217.8466632],[1486857600000,0.81,0.80969,0.81231,0.79522,7220.41251019],[1486771200000,0.81275,0.8099,0.82,0.7923,75919.80448897],[1486684800000,0.811,0.81275,0.821,0.8,150493.04656476],[1486598400000,0.821,0.8051,0.8356,0.77,790581.93256653],[1486512000000,0.8011,0.825,0.84,0.801,330401.04372136],[1486425600000,0.79991,0.8067,0.86,0.79991,1218174.13114576],[1486339200000,0.8,0.7999,0.809,0.798,51325.36930155],[1486252800000,0.76849,0.7999,0.82,0.7684,372082.94755947],[1486166400000,0.77575,0.7684,0.8,0.76,512423.37251592],[1486080000000,0.76454,0.76049,0.82488,0.7601,1235550.16947156],[1485993600000,0.7739,0.7733,0.7739,0.7511,419485.3975492],[1485907200000,0.74899,0.7748,0.7748,0.7401,416657.92432361],[1485820800000,0.7349,0.74577,0.75,0.7261,392621.81484058],[1485734400000,0.71999,0.735,0.735,0.7117,123839.41033231],[1485648000000,0.7092,0.711,0.72,0.70222,78865.06844947],[1485561600000,0.71999,0.70001,0.72,0.7,66319.72995194],[1485475200000,0.706,0.71001,0.72,0.69768,197504.84706629],[1485388800000,0.67314,0.704,0.71,0.66501,490843.78353094],[1485302400000,0.67,0.665,0.67987,0.665,31460.28781611],[1485216000000,0.67989,0.67,0.69,0.67,63888.06958776],[1485129600000,0.68225,0.68668,0.695,0.675,48922.17674387],[1485043200000,0.699,0.68223,0.699,0.67012,91996.64562027],[1484956800000,0.6855,0.692,0.7021,0.6791,101993.68583522],[1484870400000,0.68669,0.685,0.699,0.68375,100180.56460246],[1484784000000,0.68,0.6867,0.7025,0.6687,649505.00402726],[1484697600000,0.6342,0.68375,0.6945,0.6342,722911.29974448],[1484611200000,0.60124,0.6386,0.6489,0.5863,516186.44196343],[1484524800000,0.59375,0.6,0.60774,0.59251,62811.15764391],[1484438400000,0.5878,0.59375,0.616,0.581,182417.51603181],[1484352000000,0.59732,0.5865,0.60932,0.5861,52557.32057884],[1484265600000,0.613,0.60594,0.6288,0.58554,279881.05444294],[1484179200000,0.56269,0.60932,0.6259,0.5455,906197.16431742],[1484092800000,0.5697,0.57,0.58283,0.5501,993936.66527738],[1484006400000,0.5699,0.5697,0.6,0.565,479940.5750157],[1483920000000,0.5598,0.5687,0.5729,0.55132,329146.4819496],[1483833600000,0.5652,0.5649,0.5689,0.5501,97288.348568],[1483747200000,0.557,0.5652,0.56525,0.53892,454727.74806088],[1483660800000,0.54909,0.5491,0.5689,0.5451,203904.48010302],[1483574400000,0.5539,0.55201,0.573,0.5377,457411.4220489],[1483488000000,0.565,0.5491,0.57891,0.5475,400524.72904162],[1483401600000,0.55998,0.55693,0.577,0.54551,160075.95565879],[1483315200000,0.558,0.5525,0.572,0.5455,133718.06884032],[1483228800000,0.529,0.56006,0.56195,0.5278,128780.22146626],[1483142400000,0.5322,0.5374,0.54599,0.529,44383.44032481],[1483056000000,0.55653,0.531,0.55653,0.52789,290837.34805605],[1482969600000,0.534,0.55161,0.55622,0.518,243542.25886407],[1482883200000,0.50588,0.53287,0.5391,0.505,299748.8471437],[1482796800000,0.49633,0.501,0.51978,0.49591,233956.9223055],[1482710400000,0.50466,0.49801,0.51448,0.4935,108493.8375305],[1482624000000,0.51491,0.49816,0.5219,0.4934,120561.41212536],[1482537600000,0.51364,0.5165,0.51986,0.50513,99061.59607589],[1482451200000,0.513,0.50512,0.5263,0.50512,259476.87918021],[1482364800000,0.5095,0.513,0.5247,0.49,298334.06324882],[1482278400000,0.5267,0.51488,0.5328,0.5048,366376.10430987],[1482192000000,0.5346,0.52671,0.5375,0.52671,187976.15133769],[1482105600000,0.53989,0.5346,0.54663,0.5346,62849.91816306],[1482019200000,0.5404,0.5346,0.5406,0.5346,25173.22122431],[1481932800000,0.53579,0.5347,0.54499,0.5297,262970.48780991],[1481846400000,0.52759,0.536,0.538,0.52759,48598.23482657],[1481760000000,0.525,0.5302,0.53629,0.525,33085.14145397],[1481673600000,0.52601,0.525,0.52929,0.525,31545.13039527],[1481587200000,0.53489,0.526,0.537,0.526,28223.40346435],[1481500800000,0.51901,0.5289,0.538,0.5139,134818.31297537],[1481414400000,0.5152,0.5222,0.5314,0.5106,126160.11540098],[1481328000000,0.5152,0.5154,0.52,0.5151,28107.52209897],[1481241600000,0.53,0.5152,0.53,0.5151,65443.35145207],[1481155200000,0.53091,0.5315,0.538,0.5151,159612.3195684],[1481068800000,0.5389,0.53081,0.5389,0.52731,143493.48529196],[1480982400000,0.5379,0.5323,0.5469,0.52151,122801.79769989],[1480896000000,0.5302,0.536,0.54054,0.52,238666.48276357]]"
|
463
|
+
http_version:
|
464
|
+
recorded_at: Mon, 03 Apr 2017 11:56:18 GMT
|
421
465
|
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'csv'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'faraday'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'rapflag/history'
|
6
|
+
|
7
|
+
module RAPFLAG
|
8
|
+
|
9
|
+
class Bitfinex < History
|
10
|
+
@@btc_to_usd = {}
|
11
|
+
@@bfx_to_usd = {}
|
12
|
+
|
13
|
+
def get_usd_exchange(date_time = Time.now, from='BTC')
|
14
|
+
return 1.0 if from == 'USD'
|
15
|
+
key = date_time.strftime(DATE_FORMAT)
|
16
|
+
return @@btc_to_usd[key] if from.eql?('BTC') && @@btc_to_usd.size > 0
|
17
|
+
return @@bfx_to_usd[key] if from.eql?('BFX') && @@bfx_to_usd.size > 0
|
18
|
+
|
19
|
+
ms = (date_time.is_a?(Date) ? date_time.to_time : date_time).to_i*1000
|
20
|
+
ms_next_date = ms + (3*24*3600)*1000
|
21
|
+
# this does not work
|
22
|
+
# url = "https://api.bitfinex.com/v2/candles/trade:1D:t#{from}USD/hist?start:#{ms}?end:#{ms_next_date}"
|
23
|
+
url = "https://api.bitfinex.com/v2/candles/trade:1D:t#{from}USD/hist?start:#{ms}?end:#{ms_next_date}"
|
24
|
+
# therefore we just return the most uptodate
|
25
|
+
url = "https://api.bitfinex.com/v2/candles/trade:1D:t#{from}USD/hist?start:#{ms}"
|
26
|
+
puts "Fetching #{date_time}: #{url} #{@@btc_to_usd.size} BTC #{@@bfx_to_usd.size} BFX" if $VERBOSE
|
27
|
+
response = Faraday.get(url)
|
28
|
+
items = eval(response.body)
|
29
|
+
rates = {}
|
30
|
+
items.each do |item|
|
31
|
+
if item.first.eql?(:error)
|
32
|
+
puts "Fetching returned #{item}. Aborting"
|
33
|
+
exit(1)
|
34
|
+
end
|
35
|
+
# http://docs.bitfinex.com/v2/reference#rest-public-candles
|
36
|
+
# field definitions for [ MTS, OPEN, CLOSE, HIGH, LOW, VOLUME ],
|
37
|
+
# MTS int millisecond time stamp
|
38
|
+
# OPEN float First execution during the time frame
|
39
|
+
# CLOSE float Last execution during the time frame
|
40
|
+
# HIGH integer Highest execution during the time frame
|
41
|
+
# LOW float Lowest execution during the timeframe
|
42
|
+
# VOLUME float Quantity of symbol traded within the timeframe
|
43
|
+
# [[1489363200000,1224.4,1211.2,1238,1206.7,6157.96283895],
|
44
|
+
timestamp = Time.at(item.first/1000).strftime(DATE_FORMAT)
|
45
|
+
rates[timestamp] = item[2]
|
46
|
+
end;
|
47
|
+
from.eql?('BTC') ? @@btc_to_usd = rates.clone : @@bfx_to_usd = rates.clone
|
48
|
+
rates[key] ? rates[key] : nil
|
49
|
+
rescue => err
|
50
|
+
puts "Err #{err}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def fetch_csv_history
|
54
|
+
@history = []
|
55
|
+
check_config
|
56
|
+
client = ::Bitfinex::Client.new
|
57
|
+
timestamp = Time.now.to_i + 1
|
58
|
+
while true
|
59
|
+
begin
|
60
|
+
partial = client.history(@currency, { :limit => 500, :until => timestamp, :wallet => @wallet})
|
61
|
+
break unless partial && partial.size > 0
|
62
|
+
if partial.is_a?(Hash)
|
63
|
+
puts "Got #{partial['error']} while fetching #{@wallet} #{@currency} until #{Time.at(timestamp)}"
|
64
|
+
exit 3
|
65
|
+
end
|
66
|
+
first_time = Time.at(partial.first['timestamp'].to_i).strftime(DATE_TIME_FORMAT)
|
67
|
+
last_time = Time.at(partial.last['timestamp'].to_i).strftime(DATE_TIME_FORMAT)
|
68
|
+
puts "Feched #{partial.size} @history entries #{first_time} -> #{last_time}" if $VERBOSE
|
69
|
+
timestamp = (partial.last['timestamp'].to_i - 1)
|
70
|
+
@history = @history | partial
|
71
|
+
break if partial.size <= 1
|
72
|
+
rescue => error
|
73
|
+
puts "error #{error}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
puts "Feched #{@history.size} history entries" if $VERBOSE
|
77
|
+
end
|
78
|
+
private
|
79
|
+
def check_config
|
80
|
+
Config['websocket_api_endpoint'] ||= 'wss://api.bitfinex.com/ws'
|
81
|
+
['api_key',
|
82
|
+
'secret',
|
83
|
+
].each do |item|
|
84
|
+
raise "Must define #{item} in config.yml" unless Config[item]
|
85
|
+
end
|
86
|
+
::Bitfinex::Client.configure do |conf|
|
87
|
+
conf.api_key = Config['api_key']
|
88
|
+
conf.secret = Config['secret']
|
89
|
+
conf.websocket_api_endpoint = Config['websocket_api_endpoint']
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/lib/rapflag/config.rb
CHANGED
@@ -22,12 +22,6 @@ module RAPFLAG
|
|
22
22
|
end
|
23
23
|
|
24
24
|
Config= YAML.load_file(config_file)
|
25
|
-
Config['websocket_api_endpoint'] ||= 'wss://api.bitfinex.com/ws'
|
26
25
|
Config['currencies'] ||= ['BTC', 'BFX', 'XMR', 'ZEC']
|
27
26
|
Config['currencies'] << 'USD' unless Config['currencies'].index('USD')
|
28
|
-
Bitfinex::Client.configure do |conf|
|
29
|
-
conf.api_key = Config['api_key']
|
30
|
-
conf.secret = Config['secret']
|
31
|
-
conf.websocket_api_endpoint = Config['websocket_api_endpoint']
|
32
|
-
end
|
33
27
|
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'csv'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'faraday'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
module RAPFLAG
|
7
|
+
|
8
|
+
class History
|
9
|
+
attr_reader :history, :wallet, :currency, :btc_to_usd, :bfx_to_usd
|
10
|
+
DATE_FORMAT = '%Y.%m.%d'
|
11
|
+
DATE_TIME_FORMAT = '%Y.%m.%d %H:%M:%S'
|
12
|
+
|
13
|
+
def initialize(wallet = 'trading', currency = 'USD')
|
14
|
+
@wallet = wallet
|
15
|
+
@currency = currency
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_csv_file
|
19
|
+
out_file = "output/#{self.class.to_s.split('::').last.downcase}/#{@currency}_#{@wallet}.csv"
|
20
|
+
FileUtils.makedirs(File.dirname(out_file))
|
21
|
+
CSV.open(out_file,'w',
|
22
|
+
:write_headers=> true,
|
23
|
+
:col_sep => ';',
|
24
|
+
:headers => ['currency',
|
25
|
+
'amount',
|
26
|
+
'balance',
|
27
|
+
'description',
|
28
|
+
'date_time',
|
29
|
+
] #< column header
|
30
|
+
) do |csv|
|
31
|
+
@history.each do | hist_item|
|
32
|
+
csv << [ hist_item['currency'],
|
33
|
+
hist_item['amount'],
|
34
|
+
hist_item['balance'],
|
35
|
+
hist_item['description'],
|
36
|
+
Time.at(hist_item['timestamp'].to_i).strftime(DATE_TIME_FORMAT),
|
37
|
+
]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
sums = {}
|
42
|
+
@history.each do | hist_item|
|
43
|
+
key = /^[^\d]+/.match(hist_item['description'])[0].chomp
|
44
|
+
value = hist_item['amount'].to_f
|
45
|
+
if sums[key]
|
46
|
+
sums[key] += value
|
47
|
+
else
|
48
|
+
sums[key] = value
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
puts
|
53
|
+
puts "Summary for #{@wallet} #{@currency} (#{@history.size} entries}"
|
54
|
+
sums.each do |key, value|
|
55
|
+
puts " #{sprintf('%40s', key)} is #{value}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
Struct.new("Daily", :date, :amount, :balance, :description, :income)
|
60
|
+
|
61
|
+
def create_summary
|
62
|
+
@daily = {}
|
63
|
+
@history.sort{|x,y| x['timestamp'] <=> y['timestamp']}.each do | hist_item|
|
64
|
+
date = Time.at(hist_item['timestamp'].to_i).strftime(DATE_FORMAT)
|
65
|
+
info = Struct::Daily.new(date, hist_item['amount'].to_f, hist_item['balance'].to_f, hist_item['description'])
|
66
|
+
amount = hist_item['amount'].to_f
|
67
|
+
balance = hist_item['balance'].to_f
|
68
|
+
if @daily[date]
|
69
|
+
old_balance = @daily[date]
|
70
|
+
existing = @daily[date]
|
71
|
+
else
|
72
|
+
info.income = 0.0
|
73
|
+
existing = info
|
74
|
+
end
|
75
|
+
if /Wire Withdrawal fee|Trading fees for|Margin Funding Payment on wallet/i.match( hist_item['description'])
|
76
|
+
existing.income += amount
|
77
|
+
end
|
78
|
+
existing.balance = balance if balance != 0.0
|
79
|
+
@daily[date] = existing
|
80
|
+
end
|
81
|
+
out_file = "output/#{self.class.to_s.split('::').last.downcase}/#{@currency}_#{@wallet}_summary.csv"
|
82
|
+
FileUtils.makedirs(File.dirname(out_file))
|
83
|
+
previous_date = nil
|
84
|
+
saved_rate = nil
|
85
|
+
saved_info = nil
|
86
|
+
CSV.open(out_file,'w',
|
87
|
+
:write_headers=> true,
|
88
|
+
:col_sep => ';',
|
89
|
+
:headers => ['currency',
|
90
|
+
'date',
|
91
|
+
'income',
|
92
|
+
'balance',
|
93
|
+
'rate',
|
94
|
+
'balance_in_usd',
|
95
|
+
] #< column header
|
96
|
+
) do |csv|
|
97
|
+
@daily.each do |date, info|
|
98
|
+
strings = date.split('.')
|
99
|
+
fetch_date = Date.new(strings[0].to_i, strings[1].to_i, strings[2].to_i)
|
100
|
+
rate = get_usd_exchange(fetch_date, @currency)
|
101
|
+
(1..(fetch_date - previous_date -1).to_i).each do |j|
|
102
|
+
intermediate = (previous_date + j).strftime('%Y.%m.%d')
|
103
|
+
csv << [@currency,
|
104
|
+
intermediate,
|
105
|
+
saved_info.income,
|
106
|
+
saved_info.balance,
|
107
|
+
saved_rate ? saved_rate : nil,
|
108
|
+
saved_rate ? info.balance * get_usd_exchange(intermediate, @currency) : nil,
|
109
|
+
]
|
110
|
+
end if previous_date
|
111
|
+
csv << [@currency,
|
112
|
+
date,
|
113
|
+
info.income,
|
114
|
+
info.balance,
|
115
|
+
rate ? rate : nil,
|
116
|
+
rate ? info.balance * get_usd_exchange(fetch_date, @currency) : nil,
|
117
|
+
]
|
118
|
+
previous_date = fetch_date
|
119
|
+
saved_info = info
|
120
|
+
saved_rate = nil
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|