quadriga_trader.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:cryptocurrency-trader 作者: TobCar 项目源码 文件源码
def __init__(self, options, percentage_to_trade=1, start_by_buying=True, starting_amount=100):
        '''
        Pre: options is an instance of QuadrigaOptions and must have pair and ticker set.
        Post: self.is_test = True until authenticate() is called
        '''

        # Trader is in test mode by default.
        # minimum_trade is the minimum amount of assets that can be sold on a trade.
        Trader.__init__(self, True, options.minimum_trade, options.ticker)

        # Will be set to a number (order ID) when an order is placed.
        self._waiting_for_order_to_fill = None

        # In test mode: Is used to prevent the same transaction from being counted twice.
        self._last_simulation_transaction_check = 0

        # In test mode: tracks how much the trader's order has been filled.
        self._expecting_simulation_balance = 0
        self._expecting_simulation_assets = 0
        self._filled_simulation_balance = 0
        self._filled_simulation_assets = 0

        # Used when aborting to determine if any positions need to be closed.
        self._active_buy_order = False
        self._active_sell_order = False

        self.major_currency = options.major_currency
        self.minor_currency = options.minor_currency
        self.percentage_to_trade = Decimal(percentage_to_trade)
        self.amount_precision = options.amount_precision
        self.price_precision = options.price_precision
        self.start_by_buying = start_by_buying

        with localcontext() as context:
            context.prec = 8

            if self.start_by_buying:
                self.balance = Decimal(starting_amount)
                self.assets = Decimal(0)
            else:
                self.balance = Decimal(0)
                self.assets = Decimal(starting_amount)
            self.post_fee = Decimal(1) - Decimal(options.fee)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号