Example ALGO2 Python Code
Saturday, October 26, 2019 5:58 PM
import requests
from time import sleep
#import time
import numpy as np
s = [Link]()
[Link]({'X-API-key': 'V4PYCGCW'})
MAX_LONG_EXPOSURE = 25000
MAX_SHORT_EXPOSURE = -25000
ORDER_LIMIT = 5000
ticker = 'ALGO'
def get_tick():
resp = [Link]('[Link]
m
er as
if [Link]:
case = [Link]()
co
eH w
return case['tick'], case['status']
o.
def get_bid_ask(ticker):
payload = {'ticker': ticker}
rs e
ou urc
resp = [Link] ('[Link] params = payload)
if [Link]:
book = [Link]()
o
# separate bids and asks
aC s
bid_side_book = book['bids']
vi y re
ask_side_book = book['asks']
# pull out the bid and ask prices
bid_prices_book = [item["price"] for item in bid_side_book]
ask_prices_book = [item['price'] for item in ask_side_book]
ed d
return bid_prices_book, ask_prices_book
stu
def get_time_sales(ticker):
payload = {'ticker': ticker}
resp = [Link] ('[Link] params = payload)
is
if [Link]:
Th
book = [Link]()
time_sales_book = [item["quantity"] for item in book]
ar
return time_sales_book
sh
def get_position(ticker):
payload = {'ticker': ticker}
resp = [Link] ('[Link] params = payload)
if [Link]:
book = [Link]()
return book[0]['position']
def get_open_orders(ticker):
payload = {'ticker': ticker}
resp
This study source was = [Link] ('[Link]
downloaded params
by 100000766463634 from [Link] on = payload)
06-17-2021 00:36:43 GMT -05:00
[Link]
434 Page 1
resp = [Link] ('[Link] params = payload)
if [Link]:
orders = [Link]()
buy_orders = [item for item in orders if item["action"] == "BUY"]
sell_orders = [item for item in orders if item["action"] == "SELL"]
return buy_orders, sell_orders
def get_order_status(order_id):
resp = [Link] ('[Link] + '/' + str(order_id))
if [Link]:
order = [Link]()
return order
def get_news():
resp = [Link]('[Link]
if [Link]:
news = [Link]()
return news
m
er as
def main():
co
bid_price = 15.00
eH w
resp = [Link]('[Link] params = {'ticker': 'ALGO', 'type': 'LIMIT', 'quantity': ORDER_LIMIT,
o.
'price': bid_price, 'action': 'BUY'})
resp_parse = [Link]()
rs e
ou urc
if __name__ == '__main__':
main()
o
aC s
vi y re
ed d
stu
is
news
Th
Out[50]:
[{'news_id': 0,
ar
'period': 1,
'tick': 0,
sh
'ticker': '',
'headline': 'Welcome to the Alogithmic Trading 2a Case!',
'body': ''}]
news[0]['headline'].find('red')
Out[51]: -1
news[0]['headline'].find('to')
Out[52]: 8
This study source was downloaded by 100000766463634 from [Link] on 06-17-2021 00:36:43 GMT -05:00
[Link]
434 Page 2
news[0]['headline'][8:10]
Out[53]: 'to'
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
stu
is
Th
ar
sh
This study source was downloaded by 100000766463634 from [Link] on 06-17-2021 00:36:43 GMT -05:00
[Link]
434 Page 3
Powered by TCPDF ([Link])