--外汇即期、外汇远期 and 买入
update t_tm_trade_f f
set fbuy_currency_id = (select t.fcurrencyid from t_tm_trade t where t.fid = f.fid ),
    fbuy_amount = (select t.famount from t_tm_trade t where t.fid = f.fid ),
    fsell_currency_id = fsellcurrencyid,
    fsell_amount = fsellamount
where exists (
    select t.fid from t_tm_trade t where t.fid = f.fid and t.fprotecttypeid in (937486862912605184,937487193708953600) and t.ftradedirect = 'buy'
);
--外汇即期、外汇远期 and 卖出
update t_tm_trade_f f
set fbuy_currency_id = fsellcurrencyid,
    fbuy_amount = fsellamount,
    fsell_currency_id = (select t.fcurrencyid from t_tm_trade t where t.fid = f.fid ),
    fsell_amount = (select t.famount from t_tm_trade t where t.fid = f.fid )
where exists (
    select t.fid from t_tm_trade t where t.fid = f.fid and t.fprotecttypeid in (937486862912605184,937487193708953600) and t.ftradedirect = 'sell'
);

--外汇掉期 and 买入
update t_tm_trade_f f
set fbuy_currency_id = (select t.fcurrencyid from t_tm_trade t where t.fid = f.fid ),
    fbuy_amount = (select t.famount from t_tm_trade t where t.fid = f.fid ),
    fsell_currency_id = fsellcurrencyid,
    fsell_amount = fsellamount,
    ffar_buy_currency_id = fsellcurrencyid,
    ffar_buy_amount = fsellamount_far,
    ffar_sell_currency_id = (select t.fcurrencyid from t_tm_trade t where t.fid = f.fid ),
    ffar_sell_amount = fbuyamount_far
where exists (
    select t.fid from t_tm_trade t where t.fid = f.fid and t.fprotecttypeid = 937487388609891328 and t.ftradedirect = 'buy'
);
--外汇掉期 and 卖出
update t_tm_trade_f f
set fbuy_currency_id = fsellcurrencyid,
    fbuy_amount = fsellamount,
    fsell_currency_id = (select t.fcurrencyid from t_tm_trade t where t.fid = f.fid ),
    fsell_amount = (select t.famount from t_tm_trade t where t.fid = f.fid ),
    ffar_buy_currency_id = (select t.fcurrencyid from t_tm_trade t where t.fid = f.fid ),
    ffar_buy_amount = fbuyamount_far,
    ffar_sell_currency_id = fsellcurrencyid,
    ffar_sell_amount = fsellamount_far
where exists (
    select t.fid from t_tm_trade t where t.fid = f.fid and t.fprotecttypeid = 937487388609891328 and t.ftradedirect = 'sell'
);

--外汇期权 and (看涨&&买入 or 看跌&&卖出)
update t_tm_trade_f f
set fbuy_currency_id = (select t.fcurrencyid from t_tm_trade t where t.fid = f.fid ),
    fbuy_amount = (select t.famount from t_tm_trade t where t.fid = f.fid ),
    fsell_currency_id = fsellcurrencyid,
    fsell_amount = fsellamount
where exists (
    select t.fid from t_tm_trade t where t.fid = f.fid and t.fprotecttypeid = 941773368233832448 and ( (f.ftradetype = 'call' and t.ftradedirect = 'buy') or (f.ftradetype = 'put' and t.ftradedirect = 'sell') )
);
--外汇期权 and (看涨&&卖出 or 看跌&&买入)
update t_tm_trade_f f
set fbuy_currency_id = fsellcurrencyid,
    fbuy_amount = fsellamount,
    fsell_currency_id = (select t.fcurrencyid from t_tm_trade t where t.fid = f.fid ),
    fsell_amount = (select t.famount from t_tm_trade t where t.fid = f.fid )
where exists (
    select t.fid from t_tm_trade t where t.fid = f.fid and t.fprotecttypeid = 941773368233832448 and ( (f.ftradetype = 'call' and t.ftradedirect = 'sell') or (f.ftradetype = 'put' and t.ftradedirect = 'buy') )
);
