-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstockfighter
executable file
·78 lines (62 loc) · 2.01 KB
/
stockfighter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env php
<?php
// Composer autoload.
require __DIR__ . '/vendor/autoload.php';
use Dotenv\Dotenv;
use DirkOlbrich\Stockfighter\Stockfighter;
// load .env
$dotenv = new Dotenv(__DIR__);
$dotenv->load();
// load the stockfighter app
$sf = new Stockfighter($_ENV['API_KEY']);
// $level = 'first_steps';
$level = 'chock_a_block';
// var_dump($sf->heartbeat());
echo "Starting Game\n";
$sf->gameStart($level);
usleep(4000000);
echo "Buying Order \n";
$sf->buy(10000, 10000, 'limit');
echo "Selling Order \n";
$sf->sell(10000, 10000, 'limit');
$orderbook = $sf->orderbook;
echo "Orders:\n";
foreach ($orderbook->orders as $order) {
echo $order->direction . " | Price " . $order->price;
echo " | Qty " . $order->originalQty . " | Fiiled " . $order->totalFilled . "\n";
}
$openOrders = $sf->orderbook->open();
usleep(10000000);
echo "Canceling Order \n";
foreach ($openOrders as $order) {
$sf->cancelOrder($order->orderId);
}
$account = $sf->account;
echo "Balance: " . $account->balance. "\n";
foreach ($account->inventory as $pos) {
echo "Stock " . $pos->stock . " | Qty " . $pos->qty . " | Avg Price " . $pos->avgPrice . "\n";
}
foreach ($account->transactions as $trans) {
echo $trans->direction . " | Qty " . $trans->qty . " | Price " . $trans->price . "\n";
}
// for ($i=0; $i<100; $i++) {
// // $quote = $sf->venue()->stock()->quote();
// $orderbook = $sf->venue()->stock()->orderbook();
// // var_dump($orderbook);
// $bids = isset($orderbook->bids) ? $orderbook->bids : null;
// $asks = isset($orderbook->asks) ? $orderbook->asks : null;
// if ($bids) {
// array_reverse($bids);
// foreach ($bids as $bid) {
// echo "Bid: " . $bid->price . " | Qty: " . $bid->qty . "\n";
// }
// $highestBid = $bids[0]->price;
// var_dump($sf->venue()->stock()->buy(
// $highestBid + floor($highestBid * 0.01),
// rand(9000, 11000),
// 'immediate-or-cancel'
// ));
// }
// usleep(2000000);
// }
?>