def handle_order(self, client, message):
     #
     #     {
     #         accountId: '2832c5c6-ac7a-493e-bc16-ebca06c73670',
     #         sequence: 41,
     #         delta: {
     #             id: 'b91eff76-10eb-4382-834a-b753b770283e',
     #             marketSymbol: 'BTC-USDT',
     #             direction: 'BUY',
     #             type: 'LIMIT',
     #             quantity: '0.01000000',
     #             limit: '3000.00000000',
     #             timeInForce: 'GOOD_TIL_CANCELLED',
     #             fillQuantity: '0.00000000',
     #             commission: '0.00000000',
     #             proceeds: '0.00000000',
     #             status: 'OPEN',
     #             createdAt: '2020-10-07T12:51:43.16Z',
     #             updatedAt: '2020-10-07T12:51:43.16Z'
     #         }
     #     }
     #
     delta = self.safe_value(message, 'delta', {})
     parsed = self.parse_order(delta)
     if self.orders is None:
         limit = self.safe_integer(self.options, 'ordersLimit', 1000)
         self.orders = ArrayCacheBySymbolById(limit)
     orders = self.orders
     orders.append(parsed)
     messageHash = 'order'
     client.resolve(self.orders, messageHash)
示例#2
0
 def handle_order(self, client, order):
     # [45287766631,
     #     'ETHUST',
     #     -0.07,
     #     -0.07,
     #     'EXCHANGE LIMIT',
     #     'CANCELED',
     #     210,
     #     0,
     #     '2020-05-16T13:17:46Z',
     #     0,
     #     0,
     #     0]
     id = self.safe_string(order, 0)
     marketId = self.safe_string(order, 1)
     symbol = self.safe_symbol(marketId)
     amount = self.safe_float(order, 2)
     remaining = self.safe_float(order, 3)
     side = 'buy'
     if amount < 0:
         amount = abs(amount)
         remaining = abs(remaining)
         side = 'sell'
     type = self.safe_string(order, 4)
     if type.find('LIMIT') > -1:
         type = 'limit'
     elif type.find('MARKET') > -1:
         type = 'market'
     status = self.parse_ws_order_status(self.safe_string(order, 5))
     price = self.safe_float(order, 6)
     rawDatetime = self.safe_string(order, 8)
     timestamp = self.parse8601(rawDatetime)
     parsed = {
         'info': order,
         'id': id,
         'clientOrderId': None,
         'timestamp': timestamp,
         'datetime': self.iso8601(timestamp),
         'lastTradeTimestamp': None,
         'symbol': symbol,
         'type': type,
         'side': side,
         'price': price,
         'stopPrice': None,
         'average': None,
         'amount': amount,
         'remaining': remaining,
         'filled': amount - remaining,
         'status': status,
         'fee': None,
         'cost': None,
         'trades': None,
     }
     if self.orders is None:
         limit = self.safe_integer(self.options, 'ordersLimit', 1000)
         self.orders = ArrayCacheBySymbolById(limit)
     orders = self.orders
     orders.append(parsed)
     client.resolve(parsed, id)
     return parsed
示例#3
0
 def handle_order(self, client, message, order, market=None):
     parsed = self.parse_ws_order(order)
     if self.orders is None:
         limit = self.safe_integer(self.options, 'ordersLimit', 1000)
         self.orders = ArrayCacheBySymbolById(limit)
     orders = self.orders
     orders.append(parsed)
     return parsed
示例#4
0
 def handle_trade(self, client, message):
     type = self.safe_string(message, 'type')
     data = self.safe_value(message, 'data')
     marketId = self.safe_string(data, 'm')
     messageHash = type + ':' + marketId
     trade = self.parse_ws_trade(data)
     keys = list(self.trades.keys())
     length = len(keys)
     if length == 0:
         limit = self.safe_integer(self.options, 'tradesLimit')
         self.trades = ArrayCacheBySymbolById(limit)
     trades = self.trades
     trades.append(trade)
     client.resolve(trades, messageHash)
示例#5
0
 def handle_order(self, client, message):
     method = self.safe_string(message, 'method')
     params = self.safe_value(message, 'params')
     order = self.safe_value(params, 1)
     marketId = self.safe_string_lower(order, 'market')
     market = self.safe_market(marketId, None, '_')
     parsed = self.parse_order(order, market)
     if self.orders is None:
         limit = self.safe_integer(self.options, 'ordersLimit', 1000)
         self.orders = ArrayCacheBySymbolById(limit)
     orders = self.orders
     orders.append(parsed)
     symbolSpecificMessageHash = method + ':' + marketId
     client.resolve(orders, method)
     client.resolve(orders, symbolSpecificMessageHash)
示例#6
0
 def handle_my_trade(self, client, message):
     #
     # future
     #
     #     {
     #         "channel": "fills",
     #         "type": "update"
     #         "data": {
     #             "fee": 78.05799225,
     #             "feeRate": 0.0014,
     #             "future": "BTC-PERP",
     #             "id": 7828307,
     #             "liquidity": "taker",
     #             "market": "BTC-PERP",
     #             "orderId": 38065410,
     #             "price": 3723.75,
     #             "side": "buy",
     #             "size": 14.973,
     #             "time": "2019-05-07T16:40:58.358438+00:00",
     #             "tradeId": 19129310,
     #             "type": "order"
     #         },
     #     }
     #
     # spot
     #
     #     {
     #         channel: 'fills',
     #         type: 'update',
     #         data: {
     #             baseCurrency: 'ETH',
     #             quoteCurrency: 'USD',
     #             feeCurrency: 'USD',
     #             fee: 0.0023439654,
     #             feeRate: 0.000665,
     #             future: null,
     #             id: 182349460,
     #             liquidity: 'taker'
     #             market: 'ETH/USD',
     #             orderId: 8049570214,
     #             price: 391.64,
     #             side: 'sell',
     #             size: 0.009,
     #             time: '2020-08-22T15:42:42.646980+00:00',
     #             tradeId: 90614141,
     #             type: 'order',
     #         }
     #     }
     #
     messageHash = self.safe_string(message, 'channel')
     data = self.safe_value(message, 'data', {})
     trade = self.parse_trade(data)
     market = self.market(trade['symbol'])
     if self.myTrades is None:
         limit = self.safe_integer(self.options, 'tradesLimit', 1000)
         self.myTrades = ArrayCacheBySymbolById(limit)
     tradesCache = self.myTrades
     tradesCache.append(trade)
     client.resolve(tradesCache, messageHash)
     symbolMessageHash = messageHash + ':' + market['id']
     client.resolve(tradesCache, symbolMessageHash)
示例#7
0
 def handle_order(self, client, message):
     #
     # futures
     #
     #     {
     #         channel: 'orders',
     #         type: 'update',
     #         data: {
     #             id: 8047498974,
     #             clientId: null,
     #             market: 'ETH-PERP',
     #             type: 'limit',
     #             side: 'buy',
     #             price: 300,
     #             size: 0.1,
     #             status: 'closed',
     #             filledSize: 0,
     #             remainingSize: 0,
     #             reduceOnly: False,
     #             liquidation: False,
     #             avgFillPrice: null,
     #             postOnly: False,
     #             ioc: False,
     #             createdAt: '2020-08-22T14:35:07.861545+00:00'
     #         }
     #     }
     #
     # spot
     #
     #     {
     #         channel: 'orders',
     #         type: 'update',
     #         data: {
     #             id: 8048834542,
     #             clientId: null,
     #             market: 'ETH/USD',
     #             type: 'limit',
     #             side: 'buy',
     #             price: 300,
     #             size: 0.1,
     #             status: 'new',
     #             filledSize: 0,
     #             remainingSize: 0.1,
     #             reduceOnly: False,
     #             liquidation: False,
     #             avgFillPrice: null,
     #             postOnly: False,
     #             ioc: False,
     #             createdAt: '2020-08-22T15:17:32.184123+00:00'
     #         }
     #     }
     #
     messageHash = self.safe_string(message, 'channel')
     data = self.safe_value(message, 'data')
     order = self.parse_order(data)
     market = self.market(order['symbol'])
     if self.orders is None:
         limit = self.safe_integer(self.options, 'ordersLimit', 1000)
         self.orders = ArrayCacheBySymbolById(limit)
     orders = self.orders
     orders.append(order)
     client.resolve(orders, messageHash)
     symbolMessageHash = messageHash + ':' + market['id']
     client.resolve(orders, symbolMessageHash)
示例#8
0
 def handle_order(self, client, message):
     # {
     #   "type": "orders",
     #   "data": {
     #     "m": "DIL-ETH",
     #     "i": "8f75dd30-f12d-11ea-b63c-df3381b4b5b4",
     #     "w": "0x0AB991497116f7F5532a4c2f4f7B1784488628e1",
     #     "t": 1599498857138,
     #     "T": 1599498857092,
     #     "x": "fill",
     #     "X": "filled",
     #     "u": 67695627,
     #     "o": "limit",
     #     "S": "buy",
     #     "q": "0.15000000",
     #     "z": "0.15000000",
     #     "Z": "0.01486286",
     #     "v": "0.09908573",
     #     "p": "1.00000000",
     #     "f": "gtc",
     #     "V": "2",
     #     "F": [
     #       {
     #         "i": "5cdc6d14-bc35-3279-ab5e-40d654ca1523",
     #         "p": "0.09908577",
     #         "q": "0.15000000",
     #         "Q": "0.01486286",
     #         "t": 1599498857092,
     #         "s": "sell",
     #         "u": 6600,
     #         "f": "0.00030000",
     #         "a": "DIL",
     #         "g": "0.00856977",
     #         "l": "maker",
     #         "S": "pending"
     #       }
     #     ]
     #   }
     # }
     type = self.safe_string(message, 'type')
     order = self.safe_value(message, 'data')
     marketId = self.safe_string(order, 'm')
     symbol = self.safe_symbol(marketId)
     timestamp = self.safe_integer(order, 't')
     fills = self.safe_value(order, 'F')
     trades = []
     for i in range(0, len(fills)):
         trades.append(self.parse_ws_trade(fills[i]))
     id = self.safe_string(order, 'i')
     side = self.safe_string(order, 's')
     orderType = self.safe_string(order, 'o')
     amount = self.safe_float(order, 'q')
     filled = self.safe_float(order, 'z')
     remaining = None
     if (amount is not None) and (filled is not None):
         remaining = amount - filled
     average = self.safe_float(order, 'v')
     price = self.safe_float(order, 'price', average)  # for market orders
     cost = None
     if (amount is not None) and (price is not None):
         cost = amount * price
     rawStatus = self.safe_string(order, 'X')
     status = self.parse_order_status(rawStatus)
     fee = {
         'currency': None,
         'cost': None,
     }
     lastTrade = None
     for i in range(0, len(trades)):
         lastTrade = trades[i]
         fee['currency'] = lastTrade['fee']['currency']
         fee['cost'] = self.sum(fee['cost'], lastTrade['fee']['cost'])
     lastTradeTimestamp = self.safe_integer(lastTrade, 'timestamp')
     parsedOrder = {
         'info': message,
         'id': id,
         'clientOrderId': None,
         'timestamp': timestamp,
         'datetime': self.iso8601(timestamp),
         'lastTradeTimestamp': lastTradeTimestamp,
         'symbol': symbol,
         'type': orderType,
         'side': side,
         'price': price,
         'stopPrice': None,
         'amount': amount,
         'cost': cost,
         'average': average,
         'filled': filled,
         'remaining': remaining,
         'status': status,
         'fee': fee,
         'trades': trades,
     }
     if self.orders is None:
         limit = self.safe_integer(self.options, 'ordersLimit', 1000)
         self.orders = ArrayCacheBySymbolById(limit)
     orders = self.orders
     orders.append(parsedOrder)
     symbolSpecificMessageHash = type + ':' + marketId
     client.resolve(orders, symbolSpecificMessageHash)
     client.resolve(orders, type)
示例#9
0
 def handle_order(self, client, message):
     #
     #     {
     #         "e": "executionReport",        # Event type
     #         "E": 1499405658658,            # Event time
     #         "s": "ETHBTC",                 # Symbol
     #         "c": "mUvoqJxFIILMdfAW5iGSOW",  # Client order ID
     #         "S": "BUY",                    # Side
     #         "o": "LIMIT",                  # Order type
     #         "f": "GTC",                    # Time in force
     #         "q": "1.00000000",             # Order quantity
     #         "p": "0.10264410",             # Order price
     #         "P": "0.00000000",             # Stop price
     #         "F": "0.00000000",             # Iceberg quantity
     #         "g": -1,                       # OrderListId
     #         "C": null,                     # Original client order ID; This is the ID of the order being canceled
     #         "x": "NEW",                    # Current execution type
     #         "X": "NEW",                    # Current order status
     #         "r": "NONE",                   # Order reject reason; will be an error code.
     #         "i": 4293153,                  # Order ID
     #         "l": "0.00000000",             # Last executed quantity
     #         "z": "0.00000000",             # Cumulative filled quantity
     #         "L": "0.00000000",             # Last executed price
     #         "n": "0",                      # Commission amount
     #         "N": null,                     # Commission asset
     #         "T": 1499405658657,            # Transaction time
     #         "t": -1,                       # Trade ID
     #         "I": 8641984,                  # Ignore
     #         "w": True,                     # Is the order on the book?
     #         "m": False,                    # Is self trade the maker side?
     #         "M": False,                    # Ignore
     #         "O": 1499405658657,            # Order creation time
     #         "Z": "0.00000000",             # Cumulative quote asset transacted quantity
     #         "Y": "0.00000000"              # Last quote asset transacted quantity(i.e. lastPrice * lastQty),
     #         "Q": "0.00000000"              # Quote Order Qty
     #     }
     #
     messageHash = self.safe_string(message, 'e')
     orderId = self.safe_string(message, 'i')
     marketId = self.safe_string(message, 's')
     symbol = self.safe_symbol(marketId)
     timestamp = self.safe_integer(message, 'O')
     lastTradeTimestamp = self.safe_string(message, 'T')
     feeAmount = self.safe_float(message, 'n')
     feeCurrency = self.safe_currency_code(self.safe_string(message, 'N'))
     fee = {
         'cost': feeAmount,
         'currency': feeCurrency,
     }
     price = self.safe_float(message, 'p')
     amount = self.safe_float(message, 'q')
     side = self.safe_string_lower(message, 'S')
     type = self.safe_string_lower(message, 'o')
     filled = self.safe_float(message, 'z')
     cumulativeQuote = self.safe_float(message, 'Z')
     remaining = amount
     average = None
     cost = None
     if filled is not None:
         if price is not None:
             cost = filled * price
         if amount is not None:
             remaining = max(amount - filled, 0)
         if (cumulativeQuote is not None) and (filled > 0):
             average = cumulativeQuote / filled
     rawStatus = self.safe_string(message, 'X')
     status = self.parse_order_status(rawStatus)
     trades = None
     clientOrderId = self.safe_string(message, 'c')
     stopPrice = self.safe_float(message, 'P')
     parsed = {
         'info': message,
         'symbol': symbol,
         'id': orderId,
         'clientOrderId': clientOrderId,
         'timestamp': timestamp,
         'datetime': self.iso8601(timestamp),
         'lastTradeTimestamp': lastTradeTimestamp,
         'type': type,
         'side': side,
         'price': price,
         'stopPrice': stopPrice,
         'amount': amount,
         'cost': cost,
         'average': average,
         'filled': filled,
         'remaining': remaining,
         'status': status,
         'fee': fee,
         'trades': trades,
     }
     if self.orders is None:
         limit = self.safe_integer(self.options, 'ordersLimit', 1000)
         self.orders = ArrayCacheBySymbolById(limit)
     orders = self.orders
     orders.append(parsed)
     client.resolve(self.orders, messageHash)
示例#10
0
 def handle_my_trades(self, client, message):
     #
     #     {
     #         "table":"execution",
     #         "action":"insert",
     #         "data":[
     #             {
     #                 "execID":"0193e879-cb6f-2891-d099-2c4eb40fee21",
     #                 "orderID":"00000000-0000-0000-0000-000000000000",
     #                 "clOrdID":"",
     #                 "clOrdLinkID":"",
     #                 "account":2,
     #                 "symbol":"XBTUSD",
     #                 "side":"Sell",
     #                 "lastQty":1,
     #                 "lastPx":1134.37,
     #                 "underlyingLastPx":null,
     #                 "lastMkt":"XBME",
     #                 "lastLiquidityInd":"RemovedLiquidity",
     #                 "simpleOrderQty":null,
     #                 "orderQty":1,
     #                 "price":1134.37,
     #                 "displayQty":null,
     #                 "stopPx":null,
     #                 "pegOffsetValue":null,
     #                 "pegPriceType":"",
     #                 "currency":"USD",
     #                 "settlCurrency":"XBt",
     #                 "execType":"Trade",
     #                 "ordType":"Limit",
     #                 "timeInForce":"ImmediateOrCancel",
     #                 "execInst":"",
     #                 "contingencyType":"",
     #                 "exDestination":"XBME",
     #                 "ordStatus":"Filled",
     #                 "triggered":"",
     #                 "workingIndicator":false,
     #                 "ordRejReason":"",
     #                 "simpleLeavesQty":0,
     #                 "leavesQty":0,
     #                 "simpleCumQty":0.001,
     #                 "cumQty":1,
     #                 "avgPx":1134.37,
     #                 "commission":0.00075,
     #                 "tradePublishIndicator":"DoNotPublishTrade",
     #                 "multiLegReportingType":"SingleSecurity",
     #                 "text":"Liquidation",
     #                 "trdMatchID":"7f4ab7f6-0006-3234-76f4-ae1385aad00f",
     #                 "execCost":88155,
     #                 "execComm":66,
     #                 "homeNotional":-0.00088155,
     #                 "foreignNotional":1,
     #                 "transactTime":"2017-04-04T22:07:46.035Z",
     #                 "timestamp":"2017-04-04T22:07:46.035Z"
     #             }
     #         ]
     #     }
     #
     messageHash = self.safe_string(message, 'table')
     data = self.safe_value(message, 'data', [])
     dataByExecType = self.group_by(data, 'execType')
     rawTrades = self.safe_value(dataByExecType, 'Trade', [])
     trades = self.parse_trades(rawTrades)
     if self.myTrades is None:
         limit = self.safe_integer(self.options, 'tradesLimit', 1000)
         self.myTrades = ArrayCacheBySymbolById(limit)
     stored = self.myTrades
     for j in range(0, len(trades)):
         stored.append(trades[j])
     numTrades = len(trades)
     if numTrades > 0:
         client.resolve(stored, messageHash)
示例#11
0
cache.append(1)

assert equals(cache, [1])

# ----------------------------------------------------------------------------

cache = ArrayCache(1)

cache.append(1)
cache.append(2)

assert equals(cache, [2])

# ----------------------------------------------------------------------------

cache = ArrayCacheBySymbolById()

object1 = {'symbol': 'BTC/USDT', 'id': 'abcdef', 'i': 1}
object2 = {'symbol': 'ETH/USDT', 'id': 'qwerty', 'i': 2}
object3 = {'symbol': 'BTC/USDT', 'id': 'abcdef', 'i': 3}

cache.append(object1)
cache.append(object2)
cache.append(object3)  # should update index 0

assert equals(cache, [object3, object2])

maxLength = 5

cache = ArrayCacheBySymbolById(maxLength)