本文整理汇总了Python中messenger.Messenger.print_order_error方法的典型用法代码示例。如果您正苦于以下问题:Python Messenger.print_order_error方法的具体用法?Python Messenger.print_order_error怎么用?Python Messenger.print_order_error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类messenger.Messenger
的用法示例。
在下文中一共展示了Messenger.print_order_error方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Trader
# 需要导入模块: from messenger import Messenger [as 别名]
# 或者: from messenger.Messenger import print_order_error [as 别名]
#.........这里部分代码省略.........
:type period: int
:param unit: Ticker interval (one of: 'oneMin', 'fiveMin', 'thirtyMin', 'hour', 'week', 'day', and 'month')
:type unit: str
:return: Array of closing prices
:rtype : list
"""
historical_data = self.Bittrex.get_historical_data(coin_pair, period, unit)
closing_prices = []
for i in historical_data:
closing_prices.append(i["C"])
return closing_prices
def get_order(self, order_uuid, trade_time_limit):
"""
Used to get an order from Bittrex by it's UUID.
First wait until the order is completed before retrieving it.
If the order is not completed within trade_time_limit seconds, cancel it.
:param order_uuid: The order's UUID
:type order_uuid: str
:param trade_time_limit: The time in seconds to wait fot the order before cancelling it
:type trade_time_limit: float
:return: Order object
:rtype : dict
"""
start_time = time.time()
order_data = self.Bittrex.get_order(order_uuid)
while time.time() - start_time <= trade_time_limit and order_data["result"]["IsOpen"]:
time.sleep(10)
order_data = self.Bittrex.get_order(order_uuid)
if order_data["result"]["IsOpen"]:
error_str = self.Messenger.print_order_error(order_uuid, trade_time_limit, order_data["result"]["Exchange"])
logger.error(error_str)
if order_data["result"]["Type"] == "LIMIT_BUY":
self.Bittrex.cancel(order_uuid)
return order_data
return order_data
def calculate_RSI(self, coin_pair, period, unit):
"""
Calculates the Relative Strength Index for a coin_pair
If the returned value is above 75, it's overbought (SELL IT!)
If the returned value is below 25, it's oversold (BUY IT!)
:param coin_pair: String literal for the market (ex: BTC-LTC)
:type coin_pair: str
:param period: Number of periods to query
:type period: int
:param unit: Ticker interval (one of: 'oneMin', 'fiveMin', 'thirtyMin', 'hour', 'week', 'day', and 'month')
:type unit: str
:return: RSI
:rtype : float
"""
closing_prices = self.get_closing_prices(coin_pair, period * 3, unit)
count = 0
change = []
# Calculating price changes
for i in closing_prices:
if count != 0:
change.append(i - closing_prices[count - 1])
count += 1
if count == 15:
break
# Calculating gains and losses
advances = []
declines = []
for i in change:
if i > 0:
advances.append(i)
if i < 0:
declines.append(abs(i))
average_gain = (sum(advances) / 14)
average_loss = (sum(declines) / 14)
new_avg_gain = average_gain
new_avg_loss = average_loss
for _ in closing_prices:
if 14 < count < len(closing_prices):
close = closing_prices[count]
new_change = close - closing_prices[count - 1]
add_loss = 0
add_gain = 0
if new_change > 0:
add_gain = new_change
if new_change < 0:
add_loss = abs(new_change)
new_avg_gain = (new_avg_gain * 13 + add_gain) / 14
new_avg_loss = (new_avg_loss * 13 + add_loss) / 14
count += 1
if new_avg_loss == 0:
return None
rs = new_avg_gain / new_avg_loss
new_rs = 100 - 100 / (1 + rs)
return new_rs