cryptopia_trader.py 文件源码

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

项目:cryptocurrency-trader 作者: TobCar 项目源码 文件源码
def __init__(self, trading_pair, percentage_to_trade=1, start_by_buying=True, starting_amount=1):
        '''
        Post: self.is_test = True until authenticate() is called
        '''

        # Split up the trading pair for currency specific options and for console output.
        self.market_ticker = trading_pair
        split_pair = trading_pair.split("_")
        self.major_currency = split_pair[0]
        self.minor_currency = split_pair[1]

        # 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, minimum_trade_for[self.minor_currency])

        # 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

        # Needs to be None or the program will crash in simulation mode when it
        # checks if the bot was shut off manually (a live-only feature)
        self.emergency_shutdown_id = None

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

        self.percentage_to_trade = Decimal(percentage_to_trade)
        self.amount_precision = 8
        self.price_precision = 8
        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) - cryptopia_fee
评论列表


问题


面经


文章

微信
公众号

扫码关注公众号