Last active
March 27, 2020 20:08
-
-
Save pinhopro/029ec005747fca8b925483ec69764a15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import requests | |
import time | |
import datetime | |
import argparse | |
import unicodecsv as csv | |
def get_trades(currency="BRL", since=0, trade_list=[]): | |
headers = { | |
'user-agent': 'blinktrade_tools/0.1', | |
'Content-Type': 'application/json', | |
} | |
url = 'https://bitcambioapi.blinktrade.com/api/v1/%s/trades?since=%s' % ( currency, since) | |
return requests.get(url, verify=True, headers=headers).json() | |
def main(): | |
parser = argparse.ArgumentParser(description="Get trades application") | |
parser.add_argument('-s', "--since", | |
action="store", | |
dest="since", | |
help='since tid', | |
default=0, | |
type=int) | |
parser.add_argument('-o', "--output", | |
action="store", | |
dest="output_filename", | |
help='Output filename', type=str) | |
arguments = parser.parse_args() | |
trades = get_trades("BRL", arguments.since) | |
if arguments.output_filename: | |
f = open( arguments.output_filename, 'wt') | |
try: | |
headers = ['tid', 'trade_dt', 'side', 'price', 'amount'] | |
writer = csv.DictWriter(f, fieldnames=headers) | |
writer.writerow(dict( (n,n) for n in headers)) | |
for t in trades: | |
t['trade_dt'] = datetime.datetime.fromtimestamp( t['date'] ).strftime('%Y-%m-%d %H:%M:%S') | |
del t['date'] | |
writer.writerow(t) | |
finally: | |
f.close() | |
return | |
for t in trades: | |
t['trade_dt'] = datetime.datetime.fromtimestamp( t['date'] ).strftime('%Y-%m-%d %H:%M:%S') | |
print t['tid'] , ',' , t['trade_dt'], ',' , t['side'], ',' , t['price'], ',' , t['amount'] | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment