예제 #1
0
 def from_message(item: dict):
     return Order(order_id=item['oid'],
                  timestamp=iso8601_to_unix(item['created_at']),
                  pair=item['book'],
                  is_sell=True if item['side'] == 'sell' else False,
                  price=Wad.from_number(item['price']),
                  amount=Wad.from_number(item['original_amount']))
예제 #2
0
 def from_message(item: list, pair: str) -> Order:
     return Order(order_id=item['orderId'],
                  timestamp=int(item['timestamp']),
                  pair=pair,
                  is_sell=True if item['type'] == 'ask' else False,
                  price=Wad.from_number(float(item["price"])),
                  amount=Wad.from_number(float(item['qty'])))
예제 #3
0
        def place_order_function(new_order_to_be_placed):
            amount = new_order_to_be_placed.pay_amount if new_order_to_be_placed.is_sell else new_order_to_be_placed.buy_amount
            # automatically retrive qty precision
            round_lot = str(self.market_info[self.pair()]["RoundLot"])
            price_increment = str(
                self.market_info[self.pair()]["MinPriceIncrement"])
            price_precision = abs(Decimal(price_increment).as_tuple().exponent)
            order_qty_precision = abs(Decimal(round_lot).as_tuple().exponent)
            rounded_amount = round(Wad.__float__(amount), order_qty_precision)
            rounded_price = round(Wad.__float__(new_order_to_be_placed.price),
                                  price_precision)

            order_id = self.erisx_api.place_order(
                pair=self.pair().upper(),
                is_sell=new_order_to_be_placed.is_sell,
                price=rounded_price,
                amount=rounded_amount)

            # check that order was placed properly
            if len(order_id) > 0:
                placed_order = Order(str(order_id), int(time.time()),
                                     self.pair(),
                                     new_order_to_be_placed.is_sell,
                                     new_order_to_be_placed.price, amount)

                self.orders.append(placed_order)
                return placed_order
            else:
                return None
예제 #4
0
    def from_message(item: list, pair: str, market_info: dict) -> Order:
        decimal_exponent = 18 - int(market_info['quoteCurrency']['decimals'])
        price = Wad.from_number(float(item['price']) * 10 ** decimal_exponent)

        return Order(order_id=item['id'],
                     timestamp=int(dateutil.parser.parse(item['createdAt']).timestamp()),
                     pair=pair,
                     is_sell=True if item['side'] == 'SELL' else False,
                     price=price,
                     amount=Wad.from_number(from_wei(abs(int(float(item['baseAmount']))), 'ether')))
        def place_order_function(new_order_to_be_placed):
            amount = new_order_to_be_placed.pay_amount if new_order_to_be_placed.is_sell else new_order_to_be_placed.buy_amount
            
            # Convert wad to float as Bitso limits amount decimal places to 8, and price to 2
            float_price = round(Wad.__float__(new_order_to_be_placed.price), 2)
            float_amount = round(Wad.__float__(amount), 8)
            
            side = "sell" if new_order_to_be_placed.is_sell == True else "buy"
            order_id = self.bitso_api.place_order(book=self.pair(),
                                                 side=side,
                                                 price=float_price,
                                                 amount=float_amount)

            return Order(str(order_id), int(time.time()), self.pair(), new_order_to_be_placed.is_sell, new_order_to_be_placed.price, amount)
예제 #6
0
        def place_order_function(new_order_to_be_placed):
            amount = new_order_to_be_placed.pay_amount if new_order_to_be_placed.is_sell else new_order_to_be_placed.buy_amount
            # automatically retrive qty precision
            round_lot = str(self.market_info[self.pair()]["RoundLot"])
            price_increment = str(self.market_info[self.pair()]["MinPriceIncrement"])
            order_qty_precision = abs(Decimal(round_lot).as_tuple().exponent)
            price_precision = abs(Decimal(price_increment).as_tuple().exponent)

            order_id = self.erisx_api.place_order(pair=self.pair().upper(),
                                                  is_sell=new_order_to_be_placed.is_sell,
                                                  price=round(Wad.__float__(new_order_to_be_placed.price), price_precision),
                                                  amount=round(Wad.__float__(amount), order_qty_precision))

            return Order(str(order_id), int(time.time()), self.pair(), new_order_to_be_placed.is_sell,
                         new_order_to_be_placed.price, amount)