Bitcoin Forum
November 10, 2024, 06:30:52 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1] 2 »  All
  Print  
Author Topic: [0.2 BTC] Python coder, need solve issue  (Read 2148 times)
lucif (OP)
Sr. Member
****
Offline Offline

Activity: 462
Merit: 250


Clown prophet


View Profile
April 23, 2013, 02:49:01 PM
 #1

This one needs to be solved. 0.2 BTC bounty. PM on completion.

https://bitcointalk.org/index.php?topic=6019.msg1920814#msg1920814

https://github.com/slush0/sierrachartfeed/issues/7
lucif (OP)
Sr. Member
****
Offline Offline

Activity: 462
Merit: 250


Clown prophet


View Profile
April 23, 2013, 03:08:59 PM
 #2

https://github.com/slush0/sierrachartfeed/issues/7

Here https://github.com/slush0/sierrachartfeed/blob/master/sierrachartfeed.py

Data should be in guaranted order from earliest to latest before updating SC feed
Viceroy
Hero Member
*****
Offline Offline

Activity: 924
Merit: 501


View Profile
April 23, 2013, 03:10:46 PM
 #3

Data should be in guaranted order from earliest to latest before updating SC feed

interpret what you said.

data should be in order (check)
from earliest to latest (so first trade is first, last trade comes last based on time trade happened?)

before updating sc feed... what does this mean?

Viceroy
Hero Member
*****
Offline Offline

Activity: 924
Merit: 501


View Profile
April 23, 2013, 03:11:12 PM
 #4

And you need in python, why? cannot perl work?
(solution should be ... you just go to different website address for data pull, no?)

Step 1, I read API for Mt Gox Data
http://bitcoincharts.com/about/markets-api/

http://api.bitcoincharts.com/v1/markets.json

MUHUHAHAHAHAHA!

lucif (OP)
Sr. Member
****
Offline Offline

Activity: 462
Merit: 250


Clown prophet


View Profile
April 23, 2013, 03:14:23 PM
 #5

You can completely rewrite all https://github.com/slush0/sierrachartfeed in perl if you like
lucif (OP)
Sr. Member
****
Offline Offline

Activity: 462
Merit: 250


Clown prophet


View Profile
April 23, 2013, 03:17:21 PM
 #6

Okay, I forked this feed
https://github.com/pentarh/sierrachartfeed

Submit patch to this repository and if it works - you get 0.2 BTC.

I repeat, in function def bitcoincharts_history, data should be in guaranted ascending order BEFORE updating scid.
Odalv
Legendary
*
Offline Offline

Activity: 1414
Merit: 1000



View Profile
April 23, 2013, 03:27:28 PM
 #7

def bitcoincharts_history(symbol, from_timestamp, volume_precision, log=False):
    url = '%s?start=%s&end=99999999999999&symbol=%s' % (BITCOINCHARTS_TRADES_URL, from_timestamp, symbol)
    #print url
    req = urllib2.Request(url)
    for line in urllib2.urlopen(req).read().split('\n').reverse():
Odalv
Legendary
*
Offline Offline

Activity: 1414
Merit: 1000



View Profile
April 23, 2013, 03:39:54 PM
Last edit: April 23, 2013, 05:00:23 PM by Odalv
 #8

def bitcoincharts_history(symbol, from_timestamp, volume_precision, log=False):
    url = '%s?start=%s&end=99999999999999&symbol=%s' % (BITCOINCHARTS_TRADES_URL, from_timestamp, symbol)
    #print url
    req = urllib2.Request(url)
    for line in urllib2.urlopen(req).read().split('\n').reverse():
[EDIT]for line in urllib2.urlopen(req).read().split('\n').sort():

or if does not work try add ( ... )

for line in (urllib2.urlopen(req).read().split('\n')).reverse():
lucif (OP)
Sr. Member
****
Offline Offline

Activity: 462
Merit: 250


Clown prophet


View Profile
April 23, 2013, 03:44:24 PM
 #9

None is right. Lucif got 0.2 bounty. Hehe.

Quote
--- a/sierrachartfeed.py
+++ b/sierrachartfeed.py
@@ -29,7 +29,9 @@ def bitcoincharts_history(symbol, from_timestamp, volume_precision, log=False):
     url = '%s?start=%s&end=99999999999999&symbol=%s' % (BITCOINCHARTS_TRADES_URL, from_timestamp, symbol)
     #print url
     req = urllib2.Request(url)
-    for line in urllib2.urlopen(req).read().split('\n'):
+    list1 = urllib2.urlopen(req).read().split('\n')
+    list1.sort()
+    for line in list1:
         if not line:
             continue
        
Viceroy
Hero Member
*****
Offline Offline

Activity: 924
Merit: 501


View Profile
April 23, 2013, 03:48:02 PM
 #10

Viceroy should get something for pointing Lucif to sort function  Smiley

lucif (OP)
Sr. Member
****
Offline Offline

Activity: 462
Merit: 250


Clown prophet


View Profile
April 23, 2013, 03:58:02 PM
 #11

Okay, I update sierrachart... Lazy programmers. Everything I should do with myself =)

A bit crappy solution, but it works.

https://github.com/pentarh/sierrachartfeed
lucif (OP)
Sr. Member
****
Offline Offline

Activity: 462
Merit: 250


Clown prophet


View Profile
April 23, 2013, 03:58:41 PM
 #12

Viceroy should get something for pointing Lucif to sort function  Smiley
Okay, okay. Give me address. You earned 0.1 BTC.
Viceroy
Hero Member
*****
Offline Offline

Activity: 924
Merit: 501


View Profile
April 23, 2013, 04:17:55 PM
 #13

Never earned a tip before, thanks!  ;-)


144RtpxYKbigosiqTyXNwzwtH6Z7s96xUx


(lock thread else hungry coders will come ask for more)
deepceleron
Legendary
*
Offline Offline

Activity: 1512
Merit: 1036



View Profile WWW
April 23, 2013, 06:56:06 PM
Last edit: April 23, 2013, 07:45:04 PM by deepceleron
 #14

The solution is not as simple.

The old chart API is simply mapped to the new API URL, which is why it doesn't work the same. The old API URL should have been killed to let you know why it doesn't work.

Was:
Code:
http://bitcoincharts.com/t/trades.csv?start=from_timestamp&end=99999999999999&symbol=mtgoxUSD

Now:
Code:
http://api.bitcoincharts.com/v1/trades.csv?start=1366740861&end=1366740980&symbol=mtgoxUSD

Requesting the "whole" history with a range 0-99999999999999 previously would retrieve all 187MB of trade data (just for mtgox) in chronological order (basically effecting a DDOS when people used this). A "restart" of sierrachartfeed would request data starting at the "last seen" timestamp to 99999999999999.

Now a maximum of 20000 trades will be returned, in reverse chronological order (newest to oldest). Requesting an end time of 999999999999 will always return the last 20000 trades (about a day's worth).

The solution is to download chunks of time ranges. You cannot request by trade number, only by a date range. This presents a challenge, because not only must you request appropriate time ranges, reassemble and sort them all into chronological order before writing to SCID, but also you must not request data in a way that may exceed 20000 trades (or you must refine if you do), and you must deal with duplicate results if your method gets them. You also cannot assume that if you get all 20000 possible and the last trade you received was time 1366740001 that you can continue another request at 1366740000 - more trades may have that same time.

Anyway, getting the data requires intelligence to request and retrieve an appropriate amount of data, then you must put all 187M back in order, and get it as current as possible before handing off to the live stream. I would have already billed .2 BTC equivalent for my time checking this out.
Viceroy
Hero Member
*****
Offline Offline

Activity: 924
Merit: 501


View Profile
April 23, 2013, 06:57:37 PM
 #15

* Viceroy opens eyes wide and turns to look while pushing open hand with palm up toward lucif while grinning and reluctantly agreeing with poster
lucif (OP)
Sr. Member
****
Offline Offline

Activity: 462
Merit: 250


Clown prophet


View Profile
April 23, 2013, 07:01:42 PM
 #16

hehe. congrats
deepceleron
Legendary
*
Offline Offline

Activity: 1512
Merit: 1036



View Profile WWW
April 23, 2013, 07:28:09 PM
 #17

It looks like the easiest way would be to get the entire history CSV files here first:

http://api.bitcoincharts.com/v1/csv/

These are updated daily (but might not be permanent). These could be saved to the hard drive in the py directory, and could be resumed or updated using http range requests if download is interrupted or if bridge is started later (only the tail should grow bytes). Only newly-seen trades need be written to the SCIDs while this is downloading. Then the history API could work forward from there in small re-sorted time chunks to catch up SCID from the last timestamp to current, throwing a "retry a smaller chunk" error if this gets >19000 trades.
Viceroy
Hero Member
*****
Offline Offline

Activity: 924
Merit: 501


View Profile
April 23, 2013, 07:43:51 PM
 #18

* Viceroy bows to lucif for his graciousness saying
"Thank you for the tip, sir!"
deepceleron
Legendary
*
Offline Offline

Activity: 1512
Merit: 1036



View Profile WWW
April 23, 2013, 08:03:18 PM
Last edit: April 23, 2013, 08:24:02 PM by deepceleron
 #19

Also, a big oops in the "accepted" code above, you can't just sort data, otherwise trades that happen the same second are sorted (randomized) based on the trade amount. Also, you are sorting again and again for EVERY line that is read.

Raw data format:
Code:
1366740776,136.120010000000,0.010000000000
1366740774,136.120010000000,0.200000000000
1366740773,136.690000000000,0.843387830000
1366740773,136.600000000000,0.914900000000
1366740771,136.111650000000,0.020000000000
1366740770,136.100010000000,0.072978190000
1366740770,136.100010000000,0.020000000000
1366740770,136.120000000000,0.020000000000
1366740769,136.120000000000,0.020000000000
1366740769,136.120000000000,0.020000000000
1366740769,136.100010000000,0.020000000000
1366740769,136.600000000000,0.085100000000
1366740769,136.100010000000,0.020000000000
1366740768,136.100010000000,0.020000000000

fucked up data after that code:
>>> print list1
Code:
['1366740768,136.100010000000,0.020000000000',
'1366740769,136.100010000000,0.020000000000',
'1366740769,136.100010000000,0.020000000000',
'1366740769,136.120000000000,0.020000000000',
'1366740769,136.120000000000,0.020000000000',
'1366740769,136.600000000000,0.085100000000',
'1366740770,136.100010000000,0.020000000000',
'1366740770,136.100010000000,0.072978190000',
'1366740770,136.120000000000,0.020000000000',
'1366740771,136.111650000000,0.020000000000',
'1366740773,136.600000000000,0.914900000000',
'1366740773,136.690000000000,0.843387830000',
'1366740774,136.120010000000,0.200000000000',
'1366740776,136.120010000000,0.010000000000']

Reversing the data is correct, after the whole chunk has been read.

list.reverse()

    Reverse the elements of the list, in place.

xeverse
Full Member
***
Offline Offline

Activity: 124
Merit: 100



View Profile
April 23, 2013, 08:06:06 PM
Last edit: April 23, 2013, 08:26:20 PM by Xenius
 #20

Now a maximum of 20000 trades will be returned
The api description says 2000.. With 15 min delay, which is going to be a challenge to work around or maybe not..
Pages: [1] 2 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!