def from_bittrex(cls, json_document): """ {u'OrderUuid': u'262a63f5-b901-4efb-b0fb-b6f2f6d203ea', u'QuantityRemaining': 8500.0, u'IsConditional': False, u'ImmediateOrCancel': False, u'Uuid': None, u'Exchange': u'BTC-GRS', u'OrderType': u'LIMIT_BUY', u'Price': 0.0, u'CommissionPaid': 0.0, u'Opened': u'2017-12-26T20:22:41.07', u'Limit': 8.969e-05, u'Closed': None, u'ConditionTarget': None, u'CancelInitiated': False, u'PricePerUnit': None, u'Condition': u'NONE', u'Quantity': 8500.0} """ pair_id = get_currency_pair_from_bittrex(json_document["Exchange"]) if pair_id is None: msg = "Trade.from_bittrex - unsupported pair_name - {n}".format( n=json_document["Exchange"]) print_to_console(msg, LOG_ALL_ERRORS) log_to_file(msg, "error.log") return None try: timest = parse_time(json_document["Opened"], '%Y-%m-%dT%H:%M:%S.%f') except: timest = parse_time(json_document["Opened"], '%Y-%m-%dT%H:%M:%S') price = json_document["Limit"] volume = Decimal(json_document["Quantity"]) trade_type = DEAL_TYPE.BUY if "SELL" in json_document["OrderType"]: trade_type = DEAL_TYPE.SELL trade_id = json_document["OrderUuid"] executed_volume = volume - Decimal(json_document["QuantityRemaining"]) return Trade(trade_type, EXCHANGE.BITTREX, pair_id, price, volume, timest, timest, execute_time=timest, order_id=trade_id, executed_volume=executed_volume)
def main(c): parser = OptionParser() parser.set_usage(__name__.replace(".", " ") + " [OPTIONS]") parser.add_option( "-t", "--type", dest="type", help= "type of the rule (when - exec after some time and delete, each - execute each time)" ) parser.add_option("-T", "--time", dest="time", help="time: format: *s/m/h/d") parser.add_option( "-a", "--action-type", dest="action", help="the action type of rule (now available only HC_CONSOLE)") parser.add_option( "-A", "--action-value", dest="action_value", help= "the value of action (USE /s instead of spaces) (in case of action type 'HC_CONSOLE' it's command to execute in console)" ) parser.add_option( "-#", "--id", dest="id", help= "use specific id (not required because it will be generated automatically if not defined)" ) parser.add_option("-?", "--?", default=None, action="callback", callback=help, help="show this help message") o, a = parser.parse_args(c.split()) o = o.__dict__ type = o['type'] if str.isnumeric(o['time']): time = int(o['time']) else: time = parse_time(o['time']) a_type = get_action_type(o['action']) a_type_val = o['action_value'] id = o['id'] a = AutoexecRule(force=True) if type == 'each': a.time_each = time elif type == 'when': a.time_when = time else: raise Exception("Invalid rule type (-t/--type=) each|when") if a_type is not None: a.action = a_type else: raise Exception("Invalid action type (-a/--action-type) HC_CONSOLE") mgr = AutoexecRulesManager() a.action_value = a_type_val.replace("/s", " ") if id is not None and str.isnumeric(id): a.id = int(id) else: a.id = len(mgr.get_all_rules()) print( "Creating rule with params: time (each/when)=%s/%s, id=%s, atype=%s, aval=%s" % (a.time_each, a.time_when, a.id, a.action, a.action_value)) mgr.add_rule(a)
exit(0) cfg_file_name = sys.argv[1] config = ConfigParser.RawConfigParser() config.read(cfg_file_name) db_host = config.get("postgres", "db_host") db_port = config.get("postgres", "db_port") db_name = config.get("postgres", "db_name") should_fetch_history_to_db = config.getboolean( "profit_report", "fetch_history_from_exchanges") fetch_from_start = config.getboolean("profit_report", "fetch_from_start") start_time = parse_time(config.get("profit_report", "start_time"), '%Y-%m-%d %H:%M:%S') end_time = parse_time(config.get("profit_report", "end_time"), '%Y-%m-%d %H:%M:%S') if start_time == end_time or end_time <= start_time: print "Wrong time interval provided! {ts0} - {ts1}".format( ts0=start_time, ts1=end_time) assert False pg_conn = init_pg_connection(_db_host=db_host, _db_port=db_port, _db_name=db_name) key_path = config.get("keys", "path_to_api_keys") log_folder = config.get("logging", "logs_folder") load_keys(key_path)