Skip to content

Commit

Permalink
#update job/ yapf
Browse files Browse the repository at this point in the history
  • Loading branch information
yutiansut committed Jan 14, 2019
1 parent ab6c1d2 commit 059a78d
Show file tree
Hide file tree
Showing 6 changed files with 1,803 additions and 561 deletions.
6 changes: 2 additions & 4 deletions QUANTAXIS/QASU/save_account.py
Expand Up @@ -23,7 +23,6 @@
# SOFTWARE.

from QUANTAXIS.QAUtil import DATABASE

"""对于账户的增删改查(QAACCOUNT/QAUSER/QAPORTFOLIO)
"""

Expand All @@ -41,7 +40,6 @@ def save_account(message, collection=DATABASE.account):
collection.insert(message)



def update_account(mes, collection=DATABASE.account):
"""update the account with account message
Expand All @@ -55,7 +53,7 @@ def update_account(mes, collection=DATABASE.account):
collection.find_one_and_update({'account_cookie': mes['account_cookie']})


def save_riskanalysis(message,collection=DATABASE.risk):
def save_riskanalysis(message, collection=DATABASE.risk):
#print(message)

collection.insert(message)
collection.insert(message)
5 changes: 1 addition & 4 deletions QUANTAXIS/QASU/save_backtest.py
Expand Up @@ -26,12 +26,9 @@
import os

from QUANTAXIS.QAUtil import QA_util_log_expection


"""适用于老代码的回测
现在已经废弃
"""

"""
def QA_SU_save_account_message(message, client):
coll = client.quantaxis.backtest_history
Expand Down Expand Up @@ -84,4 +81,4 @@ def QA_SU_save_pnl_to_csv(detail, cookie):
csvwriter_1.writerow(detail.columns)
for item in detail:
csvwriter_1.writerow(item)
"""
"""
71 changes: 54 additions & 17 deletions QUANTAXIS/QASU/save_binance.py
Expand Up @@ -22,33 +22,70 @@ def QA_SU_save_binance(frequency):
symbol_list = QA_fetch_binance_symbols()
col = QASETTING.client.binance[frequency]
col.create_index(
[("symbol", pymongo.ASCENDING), ("start_time", pymongo.ASCENDING)], unique=True)

end = datetime.datetime.now(tzutc()) + relativedelta(days=-1, hour=0, minute=0, second=0, microsecond=0)
[("symbol",
pymongo.ASCENDING),
("start_time",
pymongo.ASCENDING)],
unique=True
)

end = datetime.datetime.now(tzutc()) + relativedelta(
days=-1,
hour=0,
minute=0,
second=0,
microsecond=0
)

for index, symbol_info in enumerate(symbol_list):
QA_util_log_info('The {} of Total {}'.format
(symbol_info['symbol'], len(symbol_list)))
QA_util_log_info('DOWNLOAD PROGRESS {} '.format(str(
float(index / len(symbol_list) * 100))[0:4] + '%')
)
QA_util_log_info(
'The {} of Total {}'.format(
symbol_info['symbol'],
len(symbol_list)
)
)
QA_util_log_info(
'DOWNLOAD PROGRESS {} '
.format(str(float(index / len(symbol_list) * 100))[0:4] + '%')
)
ref = col.find({"symbol": symbol_info['symbol']}).sort("start_time", -1)

if ref.count() > 0:
start_stamp = ref.next()['close_time'] / 1000
start_time = datetime.datetime.fromtimestamp(start_stamp)
QA_util_log_info('UPDATE_SYMBOL {} Trying updating {} from {} to {}'.format(
frequency, symbol_info['symbol'], start_time, end))
QA_util_log_info(
'UPDATE_SYMBOL {} Trying updating {} from {} to {}'.format(
frequency,
symbol_info['symbol'],
start_time,
end
)
)
else:
start_time = BINANCE_MIN_DATE
QA_util_log_info('NEW_SYMBOL {} Trying downloading {} from {} to {}'.format(
frequency, symbol_info['symbol'], start_time, end))

data = QA_fetch_binance_kline(symbol_info['symbol'],
time.mktime(start_time.utctimetuple()), time.mktime(end.utctimetuple()), frequency)
QA_util_log_info(
'NEW_SYMBOL {} Trying downloading {} from {} to {}'.format(
frequency,
symbol_info['symbol'],
start_time,
end
)
)

data = QA_fetch_binance_kline(
symbol_info['symbol'],
time.mktime(start_time.utctimetuple()),
time.mktime(end.utctimetuple()),
frequency
)
if data is None:
QA_util_log_info('SYMBOL {} from {} to {} has no data'.format(
symbol_info['symbol'], start_time, end))
QA_util_log_info(
'SYMBOL {} from {} to {} has no data'.format(
symbol_info['symbol'],
start_time,
end
)
)
continue
col.insert_many(data)

Expand Down
41 changes: 34 additions & 7 deletions QUANTAXIS/QASU/save_orderhandler.py
Expand Up @@ -41,16 +41,27 @@ def QA_SU_save_order(orderlist, client=DATABASE):

collection = client.order
collection.create_index(
[('account_cookie', ASCENDING), ('realorder_id', ASCENDING)], unique=True)
[('account_cookie',
ASCENDING),
('realorder_id',
ASCENDING)],
unique=True
)
try:

orderlist = QA_util_to_json_from_pandas(orderlist.reset_index())

for item in orderlist:
if item:
#item['date']= QA_util_get_order_day()
collection.update_one({'account_cookie': item.get('account_cookie'), 'realorder_id': item.get('realorder_id')},
{'$set': item}, upsert=True)
collection.update_one(
{
'account_cookie': item.get('account_cookie'),
'realorder_id': item.get('realorder_id')
},
{'$set': item},
upsert=True
)
except Exception as e:
print(e)
pass
Expand All @@ -71,7 +82,12 @@ def QA_SU_save_deal(dealist, client=DATABASE):
collection = client.deal

collection.create_index(
[('account_cookie', ASCENDING), ('trade_id', ASCENDING)], unique=True)
[('account_cookie',
ASCENDING),
('trade_id',
ASCENDING)],
unique=True
)
try:
dealist = QA_util_to_json_from_pandas(dealist.reset_index())
collection.insert_many(dealist, ordered=False)
Expand All @@ -91,11 +107,22 @@ def QA_SU_save_order_queue(order_queue, client=DATABASE):
"""
collection = client.order_queue
collection.create_index(
[('account_cookie', ASCENDING), ('order_id', ASCENDING)], unique=True)
[('account_cookie',
ASCENDING),
('order_id',
ASCENDING)],
unique=True
)
for order in order_queue.values():
order_json = order.to_dict()
try:
collection.update_one({'account_cookie': order_json.get('account_cookie'), 'order_id': order_json.get('order_id')},
{'$set': order_json}, upsert=True)
collection.update_one(
{
'account_cookie': order_json.get('account_cookie'),
'order_id': order_json.get('order_id')
},
{'$set': order_json},
upsert=True
)
except Exception as e:
print(e)

0 comments on commit 059a78d

Please sign in to comment.