|
|
@@ -34,7 +34,6 @@ def on_message_trade(_ws, message):
|
|
|
trade_data.append(trade)
|
|
|
check_and_train_model()
|
|
|
predict_market_direction()
|
|
|
- show_message()
|
|
|
|
|
|
|
|
|
def on_message_depth(_ws, message):
|
|
|
@@ -50,7 +49,6 @@ def on_message_depth(_ws, message):
|
|
|
})
|
|
|
check_and_train_model()
|
|
|
predict_market_direction()
|
|
|
- show_message()
|
|
|
|
|
|
|
|
|
def extract_features(order_book, trade):
|
|
|
@@ -140,10 +138,11 @@ def predict_market_direction():
|
|
|
feature_vector = np.array([list(features.values())])
|
|
|
prediction = model.predict(feature_vector)
|
|
|
logger.info("Predicted Market Direction: %s", "Up" if prediction[0] == 1 else "Down")
|
|
|
+ show_message(prediction[0])
|
|
|
|
|
|
|
|
|
# 将消息推送到外部,看看图长什么样
|
|
|
-def show_message():
|
|
|
+def show_message(market_direction):
|
|
|
global order_book_snapshots, trade_data
|
|
|
|
|
|
if len(order_book_snapshots) > 0 and len(trade_data) > 0:
|
|
|
@@ -152,8 +151,8 @@ def show_message():
|
|
|
latest_trade = trade_data[-1]
|
|
|
|
|
|
# 提取asks和bids数据
|
|
|
- asks = [[float(price), float(qty)] for price, qty in latest_order_book['asks']]
|
|
|
- bids = [[float(price), float(qty)] for price, qty in latest_order_book['bids']]
|
|
|
+ asks = [[float(price), 1 if market_direction == 1 else 0] for price, qty in latest_order_book['asks']]
|
|
|
+ bids = [[float(price), 1 if market_direction == 0 else 0] for price, qty in latest_order_book['bids']]
|
|
|
|
|
|
# 排序asks和bids数据
|
|
|
asks_sorted = sorted(asks, key=lambda x: x[0])
|