Advertisement
Guest User

Untitled

a guest
Nov 14th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.92 KB | None | 0 0
  1.     public function importTradesB($userid)
  2.     {
  3.       // User Variables
  4.       $user = User::where('id', $userid)->first();
  5.       $key = Key::where([['userid', '=', $userid], ['exchange', '=', 'Bittrex']])->first();
  6.       $apikey = decrypt($key->public);
  7.       $apisecret = decrypt($key->private);
  8.       $client = new \GuzzleHttp\Client();
  9.       try{
  10.       $nonce=time();
  11.       $uri='https://bittrex.com/api/v1.1/account/getorderhistory?apikey='.$apikey.'&nonce='.$nonce;
  12.       $sign=hash_hmac('sha512',$uri,$apisecret);
  13.       $res = $client->request('GET', $uri, [
  14.       'headers' => [
  15.       'apisign' => $sign,
  16.       ]]);
  17.       $response = $res->getBody();
  18.       $trades = json_decode($response, true);
  19.       }  catch (\GuzzleHttp\Exception\ClientException $e) {
  20.       }
  21.  
  22.  
  23.  
  24.       foreach($trades['result'] as $trade)
  25.       {
  26.         if(!BittrexTrade::where('tradeid', $userid . $trade['OrderUuid'])->exists())
  27.         {
  28.           $currencies = explode("-", $trade['Exchange']);
  29.  
  30.           $ddate = strtotime($trade['TimeStamp']);
  31.           $newformat = date('Y-m-d H:i:s', $ddate);
  32.  
  33.           $t = new BittrexTrade;
  34.           $t->userid = $userid;
  35.           $t->tradeid = $userid . $trade['OrderUuid'];
  36.           $t->date = $newformat;
  37.           $t->type = $trade['OrderType'];
  38.           $t->market = $currencies[0];
  39.           if($currencies[1] == "ANS")
  40.           {
  41.             $t->currency = "NEO";
  42.           } elseif($currencies[1] == "BCC") {
  43.             $t->currency = "BCH";
  44.           } elseif($currencies[1] == "SEC")
  45.           {
  46.             $t->currency = "SAFEX";
  47.           }
  48.            else {
  49.             $t->currency = $currencies[1];
  50.           }
  51.           $t->price = $trade['PricePerUnit'];
  52.           $t->amount = $trade['Quantity'] - $trade['QuantityRemaining'];
  53.           $t->fee = $trade['Commission'];
  54.           $t->total = $trade['Price'];
  55.           $t->save();
  56.  
  57.         }
  58.  
  59.       }
  60.  
  61.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement