-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOrders_Bot.py
101 lines (80 loc) · 3.12 KB
/
Orders_Bot.py
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#SETUP
import pip
import discord
import discord.ext
from discord.ext import commands, tasks
# pip.main(['install', 'alpaca_trade_api'])
from alpaca_trade_api.rest import REST, TimeFrame
API_KEY = '***'
SECRET_KEY = '***'
rest_api = REST(API_KEY, SECRET_KEY, 'https://paper-api.alpaca.markets')
TOKEN = '***'
intents = discord.Intents.default()
client = discord.Client(Intents=intents)
client = commands.Bot(command_prefix='!', case_insensitive=True)
#to get the console to tell you when the bot is ready to use
@client.event
async def on_ready():
print('TA Plotter is ready')
#commands to place orders
@client.command()
async def market_buy_by_quantity(ctx, ticker, qty):
rest_api.submit_order(symbol=ticker,
qty=qty,
type="market",
side="buy",
time_in_force="day")
@client.command()
async def market_buy_by_price(ctx, ticker, price):
rest_api.submit_order(symbol=ticker,
notional=price,
type="market",
side="buy",
time_in_force="day")
@client.command()
async def limit_buy_by_quantity(ctx, ticker, qty, limitprice):
rest_api.submit_order(symbol=ticker,
qty=qty,
type="limit",
side="buy",
time_in_force="day",
limit_price = limitprice)
@client.command()
async def limit_buy_by_price(ctx, ticker, price, limitprice):
rest_api.submit_order(symbol=ticker,
notional=price,
type="limit",
side="buy",
time_in_force="day",
limit_price = limitprice)
@client.command()
async def sell_by_price(ctx, ticker, price):
rest_api.submit_order(symbol=ticker,
notional=price,
type="market",
side="sell",
time_in_force="day")
@client.command()
async def sell_by_quantity(ctx, ticker, qty):
rest_api.submit_order(symbol=ticker,
qty=qty,
type="market",
side="sell",
time_in_force="day")
@client.command()
async def limit_sell_by_quantity(ctx, ticker, qty, limitprice):
rest_api.submit_order(symbol=ticker,
qty=qty,
type="limit",
side="sell",
time_in_force="day",
limit_price = limitprice)
@client.command()
async def limit_sell_by_price(ctx, ticker, price, limitprice):
rest_api.submit_order(symbol=ticker,
notional=price,
type="limit",
side="sell",
time_in_force="day",
limit_price = limitprice)
client.run(TOKEN)