LUCIT-Systems-and-Development / unicorn-fy

A Python SDK by LUCIT to convert received raw data from crypto exchange API endpoints into well-formed python dictionaries.
https://unicorn-fy.docs.lucit.tech
MIT License
54 stars 20 forks source link

userdata #22

Closed StarBalll closed 2 years ago

StarBalll commented 3 years ago

def binance_futures_websocket

->>

line 577

        elif stream_data['e'] == 'ORDER_TRADE_UPDATE':
            stream_data = {'data': stream_data}
        elif stream_data['e'] == 'ACCOUNT_UPDATE':
            stream_data = {'data': stream_data}

line elif stream_data['data']['e'] == 'executionReport': #next

       elif stream_data['data']['e'] == 'ORDER_TRADE_UPDATE':
            print('这里是发现了订单推送')
            unicorn_fied_data = {'stream_type': 'ORDER_TRADE_UPDATE',
                                 'event_type': stream_data['data']['e'],
                                 'event_time': stream_data['data']['E'],
                                 'symbol': stream_data['data']['o']['s'], # 交易对
                                 'client_order_id': stream_data['data']['o']['c'], # 订单编号
                                 'side': stream_data['data']['o']['S'], # 有用,订单方向
                                 'order_type': stream_data['data']['o']['o'], # 订单类型
                                 'time_in_force': stream_data['data']['o']['f'], # 有效方式
                                 'order_quantity': stream_data['data']['o']['q'], # 订单原始数量
                                 'order_price': stream_data['data']['o']['p'],# 原始价格
                                 'order_avg_price': stream_data['data']['o']['ap'],# 平均价格
                                 'order_tj_price': stream_data['data']['o']['sp'],# 条件订单触发价格,对追踪止损单无效
                                 'current_execution_type': stream_data['data']['o']['x'],# 本次事件的具体执行类型
                                 'current_order_status': stream_data['data']['o']['X'], # 订单的当前状态
                                 'order_id': stream_data['data']['o']['i'],# 订单ID
                                 'last_executed_quantity': stream_data['data']['o']['l'],# 订单末次成交量
                                 'cumulative_filled_quantity': stream_data['data']['o']['z'],# 订单累计已成交量
                                 'last_executed_price': stream_data['data']['o']['L'],# 订单末次成交价格
                                 # 'commission_amount': stream_data['data']['o']['n'],# 手续费数量
                                 # 'commission_asset': stream_data['data']['o']['N'],# 手续费资产类型
                                 'transaction_time': stream_data['data']['o']['T'],# 成交时间
                                 'trade_id': stream_data['data']['o']['t'], # 成交ID
                                 'net_pay': stream_data['data']['o']['b'], # 买单净值
                                 'net_selling_order_value': stream_data['data']['o']['a'],# 卖单净值
                                 'is_trade_maker_side': stream_data['data']['o']['m'], # 该成交是作为挂单成交吗
                                 'reduceOnly': stream_data['data']['o']['R'],# 是否是只减仓单
                                 'trigger_price_type': stream_data['data']['o']['wt'], # 触发价类型
                                 'order_price_type': stream_data['data']['o']['ot'],# 原始定单类型
                                 'positionSide': stream_data['data']['o']['ps'],
                                 # 'cumulative_quote_asset_transacted_quantity': stream_data['data']['cp'],
                                 # 'cumulative_quote_asset_transacted_quantity': stream_data['data']['AP'],
                                 # 'cumulative_quote_asset_transacted_quantity': stream_data['data']['cr'],
                                 'order_profit_loss': stream_data['data']['o']['rp']} #该交易实现盈亏
oliver-zehentleitner commented 3 years ago

Hello! Some description what you want would be cool!

StarBalll commented 3 years ago

https://binance-docs.github.io/apidocs/futures/en/#event-order-update

This is futures

Push analysis of order information

`{

"e":"ORDER_TRADE_UPDATE", // Event Type "E":1568879465651, // Event Time "T":1568879465650, // Transaction Time "o":{
"s":"BTCUSDT", // Symbol "c":"TEST", // Client Order Id // special client order id: // starts with "autoclose-": liquidation order // "adl_autoclose": ADL auto close order "S":"SELL", // Side "o":"TRAILING_STOP_MARKET", // Order Type "f":"GTC", // Time in Force "q":"0.001", // Original Quantity "p":"0", // Original Price "ap":"0", // Average Price "sp":"7103.04", // Stop Price. Please ignore with TRAILING_STOP_MARKET order "x":"NEW", // Execution Type "X":"NEW", // Order Status "i":8886774, // Order Id "l":"0", // Order Last Filled Quantity "z":"0", // Order Filled Accumulated Quantity "L":"0", // Last Filled Price "N":"USDT", // Commission Asset, will not push if no commission "n":"0", // Commission, will not push if no commission "T":1568879465651, // Order Trade Time "t":0, // Trade Id "b":"0", // Bids Notional "a":"9.91", // Ask Notional "m":false, // Is this trade the maker side? "R":false, // Is this reduce only "wt":"CONTRACT_PRICE", // Stop Price Working Type "ot":"TRAILING_STOP_MARKET", // Original Order Type "ps":"LONG", // Position Side "cp":false, // If Close-All, pushed with conditional order "AP":"7476.89", // Activation Price, only puhed with TRAILING_STOP_MARKET order "cr":"5.0", // Callback Rate, only puhed with TRAILING_STOP_MARKET order "rp":"0" // Realized Profit of the trade }

}`

oliver-zehentleitner commented 3 years ago

If you have the code ready, do you want to make a pull request? This will add you to contributors list :)

oliver-zehentleitner commented 3 years ago

and one example of received raw data of this event for the test unit would be nice too! thanks you!

StarBalll commented 3 years ago

我提交的方式对么...

https://binance-docs.github.io/apidocs/futures/en/#event-balance-and-position-update

"e": "ACCOUNT_UPDATE", // Event Type

oliver-zehentleitner commented 3 years ago

its not hard to do that. just create a fork, edit the fork and when its ready click pull request.

Here is a step by step description: https://www.dataschool.io/how-to-contribute-on-github/