예제 #1
0
 def get_pending_orders(api_key):
     log.info("Get pending orders.")
     time_stamp = get_current_time()
     pending_orders = lykkex.get_pending_orders(api_key)
     if not pending_orders:
         log.info("No pending orders")
     return time_stamp, pending_orders
예제 #2
0
    def get_price(asset_pair_id, side='BUY'):
        log.info("Retrieve price: {}".format(side))
        time_stamp = get_current_time()
        order_book = lykkex.get_order_book(asset_pair_id)
        price = LykkexService.get_asset_price(order_book, side)
        volume = LykkexService.get_asset_trading_volume(order_book, side)

        log.info("Timestamp: {}".format(time_stamp))
        log.info("Price: {}".format(price))
        return time_stamp, price, volume
예제 #3
0
 def get_balance(api_key):
     log.info("Retrieve current balance.")
     time_stamp = get_current_time()
     balance = lykkex.get_balance(api_key)
     log.info("Number of assets: {}".format(len(balance)))
     for x in range(0, len(balance)):
         log.info(
             format('Current wealth ' + balance[x]['AssetId'].encode() +
                    ': ' + str(balance[x]['Balance'])))
     return time_stamp, balance
예제 #4
0
 def send_limit_order(api_key,
                      asset_pair,
                      asset,
                      price,
                      order_action='BUY',
                      volume='0.1'):
     log.info("Send market order - {}".format(asset))
     time_stamp = get_current_time()
     response = lykkex.send_limit_order(api_key, asset_pair, asset, price,
                                        order_action, volume)
     log.info("Limit order placed")
     order_id = str(response)
     return time_stamp, order_id
예제 #5
0
 def send_market_order(api_key, asset_pair, asset, order_action, volume):
     log.info("Send market order - {}".format(asset))
     time_stamp = get_current_time()
     response = lykkex.send_market_order(api_key, asset_pair, asset,
                                         order_action, volume)
     if response['Error']:
         log.info("Error: Market order not successful")
         raise RuntimeError(
             "Error in sending market order. Check response {}".format(
                 response))
     final_price = response['Result']
     log.info("Trade successful at price {}".format(final_price))
     return time_stamp, final_price
예제 #6
0
    def calculate_trading_signal(self, ):
        log.info("Calculate trading signal.")
        window_length = 1. / self.trading_frequency * self.momentum_accumulator
        start_date = get_current_time() - datetime.timedelta(
            seconds=window_length)
        price_data = self.db_service.get_price_data(after=start_date)
        enough_price_points_available = price_data.shape[0] >= 2
        if enough_price_points_available:
            trading_signal = momentum_strategy(price_data)
        else:
            log.info("Need to accumulate more price data points.")
            trading_signal = 0

        log.info("Trading signal: {}".format(trading_signal))
        return trading_signal
예제 #7
0
 def get_latency(self, asset_pair_id):
     time_stamp = get_current_time()
     order_book = lykkex.get_order_book(asset_pair_id)
     time_ob = self.get_time_stamp_from_order_books(order_book)
     time_delta = (time_stamp - time_ob).total_seconds()
     log.info("System latency: {} secs".format(time_delta))
예제 #8
0
 def control_limit_order(api_key, order_id):
     log.info("Check status of limit order {}", order_id)
     time_stamp = get_current_time()
     content = lykkex.get_order_status(api_key, order_id)
     status = content['Status']
     return time_stamp, status