示例#1
0
def get_position(session, position_status):
    position = BitflyerEmaTradeHistory.get_record_filter_status(session, position_status)

    ### ポジションが1つ以上存在する
    if len(position) > 1:
        raise Exception("Hold multiple position")

    return position
示例#2
0
def insert_trade_history(session, request_nonce, amount, order_id):
    session.add(
        BitflyerEmaTradeHistory(
            order_request_nonce=request_nonce,
            amount=amount,
            status="request",
            open_order_id=order_id,
            created_at=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
            updated_at=datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
    session.commit()
sys.path.append(os.path.join(app_home, "models"))
sys.path.append(os.path.join(app_home, "setting"))

# モジュール、設定系の読み込み
from bitflyer_ema_trade_history import BitflyerEmaTradeHistory
from db_setting import session
from logger import logger
from bitflyer_ccxt import bitflyer

if __name__ == "__main__":

    logger.info("=== aggregate_batch start ===")

    try:
        #statusがcloseのレコードを取得する
        gcross_close_positions = BitflyerEmaTradeHistory.get_record_filter_status(
            session, "gcross_close")

        if gcross_close_positions is not None:

            # 直近の取引履歴25件をcoincheckから取得する
            my_trades = bitflyer.fetch_my_trades(symbol="FX_BTC_JPY")

            # 1件ずつ、order_idをキーに突合し、抜けているデータを保存する
            for trade_history in gcross_close_positions:
                # 変数初期化
                open_time = None
                open_rate = None
                close_time = None
                close_rate = None

                for my_trade in my_trades: