Skip to content

Commit

Permalink
for trade add tradeId
Browse files Browse the repository at this point in the history
  • Loading branch information
devin-y committed Nov 2, 2019
1 parent 5d01be3 commit adf952c
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 33 deletions.
1 change: 1 addition & 0 deletions example/restful/getmarkettrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
if len(trades):
for trade in trades:
trade.print_object()
print()



Expand Down
3 changes: 2 additions & 1 deletion example/restful/getmatchresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

request_client = RequestClient(api_key=g_api_key, secret_key=g_secret_key)

match_list = request_client.get_match_result(symbol="eosusdt")
#match_list = request_client.get_match_result(symbol="eosusdt")
match_list = request_client.get_match_result(symbol="stketh", start_date="2019-10-30", from_id=8167494327, size=20, direct=QueryDirection.PREV)
PrintMix.print_data(match_list)


19 changes: 4 additions & 15 deletions huobi/impl/restapirequestimpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,7 @@ def parse(json_wrapper):
trade_list = list()

for item in data_array.get_items():
local_trade = Trade()
local_trade.price = item.get_float("price")
local_trade.amount = item.get_float("amount")
local_trade.trade_id = item.get_int("id")
local_trade.unique_trade_id = item.get_int("trade-id")
local_trade.timestamp = convert_cst_in_millisecond_to_utc(item.get_int("ts"))
local_trade.direction = item.get_string("direction")
local_trade = Trade.json_parse(item)
trade_list.append(local_trade)

return trade_list
Expand All @@ -152,13 +146,7 @@ def parse(json_wrapper):
for item in data_array.get_items():
data_array_in = item.get_array("data")
for item_in in data_array_in.get_items():
local_trade = Trade()
local_trade.price = item_in.get_float("price")
local_trade.amount = item_in.get_float("amount")
local_trade.trade_id = item_in.get_int("id")
local_trade.unique_trade_id = item_in.get_int("trade-id")
local_trade.timestamp = convert_cst_in_millisecond_to_utc(item_in.get_int("ts"))
local_trade.direction = item_in.get_string("direction")
local_trade = Trade.json_parse(item_in)
trade_list.append(local_trade)
return trade_list

Expand Down Expand Up @@ -680,7 +668,7 @@ def parse(json_wrapper):
request.json_parser = parse
return request

def get_match_results(self, symbol, order_type=None, start_date=None, end_date=None, size=None, from_id=None):
def get_match_results(self, symbol, order_type=None, start_date=None, end_date=None, size=None, from_id=None, direct=None):
check_symbol(symbol)
start_date = format_date(start_date, "start_date")
end_date = format_date(end_date, "end_date")
Expand All @@ -692,6 +680,7 @@ def get_match_results(self, symbol, order_type=None, start_date=None, end_date=N
builder.put_url("end-date", end_date)
builder.put_url("from", from_id)
builder.put_url("size", size)
builder.put_url("direct", direct)
request = self.__create_request_by_get_with_signature("/v1/order/matchresults", builder)

def parse(json_wrapper):
Expand Down
8 changes: 1 addition & 7 deletions huobi/impl/websocketrequestimpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,7 @@ def json_parse(json_wrapper):
data_array = tick.get_array("data")
trade_list = list()
for item in data_array.get_items():
trade = Trade()
trade.amount = item.get_float("amount")
trade.price = item.get_float("price")
trade.trade_id = item.get_string("id")
trade.unique_trade_id = item.get_int("trade-id")
trade.direction = item.get_string("direction")
trade.timestamp = convert_cst_in_millisecond_to_utc(item.get_int("ts"))
trade = Trade.json_parse(item)
trade_list.append(trade)
trade_event.trade_list = trade_list
return trade_event
Expand Down
2 changes: 1 addition & 1 deletion huobi/model/trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def json_parse(json_data):
trade.amount = json_data.get_float("amount")
trade.price = json_data.get_float("price")
trade.trade_id = json_data.get_string("id")
trade.unique_trade_id = json_data.get_string("trade-id")
trade.unique_trade_id = json_data.get_int_or_default("trade-id", json_data.get_int_or_default("tradeId", 0))
trade.direction = json_data.get_string("direction")
trade.timestamp = convert_cst_in_millisecond_to_utc(json_data.get_int("ts"))
return trade
Expand Down
8 changes: 1 addition & 7 deletions huobi/model/traderequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ def json_parse(json_wrapper):
tick = json_wrapper.get_array(OutputKey.KeyData)
trade_list = list()
for item in tick.get_items():
trade = Trade()
trade.amount = item.get_float("amount")
trade.price = item.get_float("price")
trade.trade_id = item.get_string("id")
trade.unique_trade_id = item.get_string("tradeId") # others return trade-id, here return tradeId
trade.direction = item.get_string("direction")
trade.timestamp = convert_cst_in_millisecond_to_utc(item.get_int("ts"))
trade = Trade.json_parse(item) # others return trade-id, here return tradeId
trade_list.append(trade)
trade_event.trade_list = trade_list
return trade_event
Expand Down
5 changes: 3 additions & 2 deletions huobi/requstclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ def get_match_results_by_order_id(self, order_id: 'int') -> list:
def get_match_result(self, symbol: 'str', order_type: 'OrderSide' = None, start_date: 'str' = None,
end_date: 'str' = None,
size: 'int' = None,
from_id: 'int' = None):
from_id: 'int' = None,
direct:'str'=None):
"""
Search for the trade records of an account.
Expand All @@ -395,7 +396,7 @@ def get_match_result(self, symbol: 'str', order_type: 'OrderSide' = None, start_
:param from_id: Search order id to begin with. (optional).
:return:
"""
return call_sync(self.request_impl.get_match_results(symbol, order_type, start_date, end_date, size, from_id))
return call_sync(self.request_impl.get_match_results(symbol, order_type, start_date, end_date, size, from_id, direct))

def withdraw(self, address: 'str', amount: 'float', currency: 'str', fee: 'float' = None,
address_tag: 'str' = None) -> int:
Expand Down

0 comments on commit adf952c

Please sign in to comment.