Beispiel #1
0
 public function showEventDiary($eventId, $page = 1)
 {
     $pageSize = 10;
     $accountArray = Cache::get('accountList');
     if (!Cache::has('tradeList-' . $eventId . '-' . $page)) {
         Cache::put('tradeList-' . $eventId . '-' . $page, Trade::where('event_id', '=', $eventId)->orderBy('trade_at', 'asc')->skip(($page - 1) * $pageSize)->take($pageSize)->get(), 10);
     }
     return view('event.diary')->with(['eventList' => Cache::get('events'), 'eventInfo' => Event::find($eventId), 'tradeList' => Cache::get('tradeList-' . $eventId . '-' . $page), 'accountList' => json_encode($accountArray), 'fileLinkList' => DiaryAttachedFiles::where('event_id', '=', $eventId)->get(), 'totalPageNumber' => ceil(Trade::where('event_id', '=', $eventId)->count() / $pageSize), 'currentPageNumber' => $page]);
 }
 /**
  * Display search
  *
  * @return Response
  */
 public function search(Request $request)
 {
     $id = $request->input('id');
     $site_id = 0;
     $trade_id = 0;
     if (Site::where('code', 'LIKE', '%' . $id . '%')->orWhere('name', 'LIKE', '%' . $id . '%')->first() != null) {
         $site_id = Site::where('code', 'LIKE', '%' . $id . '%')->orWhere('name', 'LIKE', '%' . $id . '%')->first()->id;
     }
     if (Trade::where('name', 'LIKE', '%' . $id . '%')->first() != null) {
         $trade_id = Trade::where('name', 'LIKE', '%' . $id . '%')->first()->id;
     }
     $labors = Labor::where('employee_no', '=', $id)->orWhere('name', 'LIKE', '%' . $id . '%')->orWhere('site_id', '=', $site_id)->orWhere('trade_id', '=', $trade_id)->where('deleted', '=', 'false')->paginate(20);
     //dd($labors->toArray()['total']);
     return view('pages.index_labor', compact('labors'));
 }
 public function GetActiveProfileTrades($profile_id)
 {
     return Trade::where('profile_id', $profile_id)->where('is_active', true)->get();
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $trade = Trade::where('name', '=', $id)->first();
     if ($trade == null) {
         return redirect('trades');
     }
     $trade->delete();
     return redirect('trades');
 }
 public function findOpenPosition($comparable, $compare_string)
 {
     $trades = Trade::where($compare_string, $comparable)->get(array('id', 'price', 'symbol', 'contract', 'lots', 'order_type'));
     $trades_1 = $trades;
     foreach ($trades as $trade) {
         $total_lots = abs($trade->lots);
         $open_lots = $trade->lots;
         $avg_price = null;
         $avg_buy = null;
         $avg_sell = null;
         $sum_buy_trades = array();
         $sum_sell_trades = array();
         $sum_abs_lots_price = array();
         $sum_buy_lots_price = array();
         $sum_sell_lots_price = array();
         if ($trade->lots < '0') {
             array_push($sum_sell_trades, $trade->lots);
             array_push($sum_sell_lots_price, $trade->lots * $trade->price);
         } elseif ($trade->lots > '0') {
             array_push($sum_buy_trades, $trade->lots);
             array_push($sum_buy_lots_price, $trade->lots * $trade->price);
         }
         array_push($sum_abs_lots_price, abs($trade->lots) * $trade->price);
         //loop through rest of trades and store key numbers for trades with same contract as $trade
         foreach ($trades_1 as $trade_1) {
             if ($trade->contract === $trade_1->contract && $trade->id !== $trade_1->id) {
                 $total_lots = $total_lots + abs($trade_1->lots);
                 $open_lots = $open_lots + $trade_1->lots;
                 if ($trade_1->lots < '0') {
                     array_push($sum_sell_trades, $trade_1->lots);
                     array_push($sum_sell_lots_price, $trade_1->lots * $trade_1->price);
                 } elseif ($trade_1->lots > '0') {
                     array_push($sum_buy_trades, $trade_1->lots);
                     array_push($sum_buy_lots_price, $trade_1->lots * $trade_1->price);
                 }
                 array_push($sum_abs_lots_price, abs($trade_1->lots) * $trade_1->price);
             }
         }
         $closed_lots = $total_lots - $open_lots;
         foreach ($sum_abs_lots_price as $abs_profit) {
             $avg_price = $abs_profit + $avg_price;
         }
         $avg_price = $avg_price / $total_lots;
         ///////BUY SIDE //////
         $buyside_profits = null;
         foreach ($sum_buy_lots_price as $buy_profit) {
             $buyside_profits = $buyside_profits + $buy_profit;
         }
         $buyside_lots = null;
         foreach ($sum_buy_trades as $buy_lots) {
             $buyside_lots = $buyside_lots + $buy_lots;
         }
         if ($buyside_lots != 0) {
             $avg_buy = $buyside_profits / $buyside_lots;
         }
         ///////SELL SIDE /////
         $sellside_profits = null;
         foreach ($sum_sell_lots_price as $sell_profit) {
             $sellside_profits = $sellside_profits + $sell_profit;
         }
         $sellside_lots = null;
         foreach ($sum_sell_trades as $sell_lots) {
             $sellside_lots = $sellside_lots + $sell_lots;
         }
         if ($sellside_lots != 0) {
             $avg_sell = $sellside_profits / $sellside_lots;
         }
         $market_price = $avg_price + rand(-100, 100) / 100;
         $trade['total_lots'] = $total_lots;
         $trade['open_lots'] = $open_lots;
         $trade['closed_lots'] = $closed_lots;
         $trade['avg_sell'] = $avg_sell;
         $trade['avg_buy'] = $avg_buy;
         $trade['avg_price'] = $avg_price;
         $trade['market_price'] = $market_price;
         unset($trade['id']);
         unset($trade['price']);
         unset($trade['lots']);
         unset($trade['symbol']);
         unset($trade['order_type']);
     }
     return $trades;
 }