-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.0.13: Add order update v2 subscription
- Loading branch information
Showing
12 changed files
with
205 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import logging | ||
from huobi import SubscriptionClient | ||
from huobi.constant.test import * | ||
|
||
logger = logging.getLogger("huobi-client") | ||
logger.setLevel(level=logging.INFO) | ||
handler = logging.StreamHandler() | ||
handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) | ||
logger.addHandler(handler) | ||
|
||
sub_client = SubscriptionClient(api_key=g_api_key, secret_key=g_secret_key) | ||
|
||
|
||
def callback(orders_update_event: 'OrderUpdateV2Event'): | ||
print("---- orders update : ----") | ||
orders_update_event.print_object() | ||
print() | ||
|
||
|
||
def error(e: 'HuobiApiException'): | ||
print(e.error_code + e.error_message) | ||
|
||
|
||
sub_client.subscribe_orders_update_event("hthusd", callback, error) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ class OutputKey: | |
KeyTick = "tick" | ||
KeyChannelCh = "ch" | ||
KeyChannelRep = "rep" | ||
KeyAction = "action" | ||
|
||
|
||
|
||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from huobi.model import OrderType, OrderState, OrderUpdateEventType | ||
|
||
|
||
class OrdersUpdate: | ||
|
||
def __init__(self): | ||
self.eventType = OrderUpdateEventType.INVALID | ||
self.symbol = "" | ||
self.orderId = 0 | ||
self.clientOrderId = "" | ||
self.type = OrderType.INVALID | ||
self.orderStatus = OrderState.INVALID | ||
self.orderPrice = "" | ||
self.orderSize = "" | ||
self.orderCreateTime = 0 | ||
self.tradeId = 0 | ||
self.tradePrice = "" | ||
self.tradeVolume = "" | ||
self.tradeTime = 0 | ||
self.aggressor = False | ||
self.remainAmt = "" | ||
self.lastActTime = 0 | ||
|
||
@staticmethod | ||
def json_parse(json_data): | ||
obj = OrdersUpdate() | ||
obj.eventType = json_data.get_string("eventType") | ||
obj.symbol = json_data.get_string("symbol") | ||
obj.orderId = json_data.get_int("orderId") | ||
obj.clientOrderId = json_data.get_string("clientOrderId") | ||
obj.orderStatus = json_data.get_string("orderStatus") | ||
|
||
if obj.eventType == OrderUpdateEventType.CREATION: | ||
obj.type = json_data.get_string_or_default("type", OrderType.INVALID) | ||
obj.orderPrice = json_data.get_string_or_default("orderPrice", "") | ||
obj.orderSize = json_data.get_string_or_default("orderSize", "") | ||
obj.orderCreateTime = json_data.get_int_or_default("orderCreateTime", 0) | ||
|
||
if obj.eventType == OrderUpdateEventType.TRADE: | ||
obj.tradeId = json_data.get_int_or_default("tradeId", 0) | ||
obj.tradePrice = json_data.get_string_or_default("tradePrice", "") | ||
obj.tradeVolume = json_data.get_string_or_default("tradeVolume", "") | ||
obj.tradeTime = json_data.get_int_or_default("tradeTime", 0) | ||
obj.aggressor = json_data.get_boolean("aggressor", False) | ||
obj.remainAmt = json_data.get_string_or_default("remainAmt", "") | ||
|
||
if obj.eventType == OrderUpdateEventType.TRADE: | ||
obj.lastActTime = json_data.get_int_or_default("lastActTime", 0) | ||
|
||
return obj | ||
|
||
def print_object(self, format_data=""): | ||
from huobi.base.printobject import PrintBasic | ||
PrintBasic.print_basic(self.eventType, format_data + "Event Type") | ||
PrintBasic.print_basic(self.symbol, format_data + "Symbol") | ||
PrintBasic.print_basic(self.orderId, format_data + "Order Id") | ||
PrintBasic.print_basic(self.clientOrderId, format_data + "Client Order Id") | ||
PrintBasic.print_basic(self.orderStatus, format_data + "order Status") | ||
|
||
if self.eventType == OrderUpdateEventType.CREATION: | ||
PrintBasic.print_basic(self.type, format_data + "Type") | ||
PrintBasic.print_basic(self.orderPrice, format_data + "order Price") | ||
PrintBasic.print_basic(self.orderSize, format_data + "order Size") | ||
PrintBasic.print_basic(self.orderCreateTime, format_data + "Order Create Time") | ||
|
||
if self.eventType == OrderUpdateEventType.TRADE: | ||
PrintBasic.print_basic(self.tradeId, format_data + "Trade Id") | ||
PrintBasic.print_basic(self.tradePrice, format_data + "Trade Price") | ||
PrintBasic.print_basic(self.tradeVolume, format_data + "Trade Volume") | ||
PrintBasic.print_basic(self.tradeTime, format_data + "Trade Time") | ||
PrintBasic.print_basic(self.aggressor, format_data + "is aggressor") | ||
PrintBasic.print_basic(self.remainAmt, format_data + "Remain Amount") | ||
|
||
if self.eventType == OrderUpdateEventType.CANCELLATION: | ||
PrintBasic.print_basic(self.lastActTime, format_data + "Last Activity Time") |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from huobi.constant.result import OutputKey | ||
from huobi.impl.utils.channelparser import ChannelParser | ||
from huobi.model import Mbp | ||
from huobi.model.ordersupdate import OrdersUpdate | ||
|
||
|
||
class OrdersUpdateEvent: | ||
""" | ||
The order update received by subscription of order update. | ||
""" | ||
|
||
def __init__(self): | ||
self.action = "" | ||
self.code = 200 | ||
self.ch = "" | ||
self.data = OrdersUpdate() | ||
|
||
@staticmethod | ||
def json_parse(json_wrapper): | ||
action = json_wrapper.get_string(OutputKey.KeyAction) | ||
ch = json_wrapper.get_string(OutputKey.KeyChannelCh) | ||
data = json_wrapper.get_object(OutputKey.KeyData) | ||
|
||
order_update_v2_event = OrdersUpdateEvent() | ||
order_update_v2_event.action = action | ||
order_update_v2_event.ch = ch | ||
order_update_v2_event.data = OrdersUpdate.json_parse(data) | ||
return order_update_v2_event | ||
|
||
def print_object(self, format_data=""): | ||
from huobi.base.printobject import PrintBasic | ||
PrintBasic.print_basic(self.ch, format_data + "Channel") | ||
self.data.print_object() |
This file contains 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
This file contains 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
This file contains 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