-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
4,987 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .mongo_ticks import MongoTicks | ||
from .mongo_tags import MongoTags | ||
from .mongo_fund import MongoFund | ||
from .mongo_fund import MongoFund | ||
from .mongo_client_factory import ticks_client, tags_client, fund_client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import pymongo | ||
from .mongo_ticks import MongoTicks | ||
from .mongo_tags import MongoTags | ||
from .mongo_fund import MongoFund | ||
default_mongo_client = pymongo.MongoClient( | ||
"mongodb://localhost:27017/", username='a1chemy', password='1B2C9046-E3CC-447F-9961-E125759BA44F') | ||
|
||
|
||
def mongo_client_factory(): | ||
return default_mongo_client | ||
|
||
def tags_client(): | ||
return MongoTags(mongo_client=mongo_client_factory()) | ||
|
||
def fund_client(): | ||
return MongoFund(mongo_client=mongo_client_factory()) | ||
|
||
def ticks_client(): | ||
return MongoTicks(mongo_client=mongo_client_factory()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import a1chemy.data_source as data_source | ||
from a1chemy.common import Tag | ||
|
||
import pandas as pd | ||
|
||
|
||
class TradingViewClient(object): | ||
|
||
def __init__(self) -> None: | ||
super().__init__() | ||
self.mongo_ticks_client = data_source.ticks_client() | ||
self.mongo_tag_client = data_source.tags_client() | ||
|
||
def update_sectors(self, path): | ||
sector_data_frame = pd.read_csv(path) | ||
sectors_root_tag = Tag(id='tradingview_sectors', | ||
parent=None, values={}) | ||
self.mongo_tag_client.delete_by_parent(parent=sectors_root_tag.id) | ||
trading_view_tree = self.mongo_tag_client.tree(id=sectors_root_tag.id) | ||
for sectors, stocks in trading_view_tree.root.children.items(): | ||
for key, value in stocks.children.items(): | ||
self.mongo_tag_client.delete_by_parent(key) | ||
self.mongo_tag_client.insert(tag=sectors_root_tag) | ||
for index, row in sector_data_frame.iterrows(): | ||
exchange = 'SZ' if row['Exchange'] == 'SZSE' else 'SH' | ||
symbol = exchange + '{:06d}'.format(row['Ticker']) | ||
sector = row['Sector'] | ||
|
||
sector_tag = Tag(id=sector, parent=sectors_root_tag.id, values={}) | ||
self.mongo_tag_client.insert(tag=sector_tag) | ||
|
||
id = exchange + '_' + symbol | ||
parent = sector_tag.id | ||
values = {'exchange': exchange, 'symbol': symbol} | ||
stock_tag = Tag(id=id, parent=parent, values=values) | ||
self.mongo_tag_client.insert(tag=stock_tag) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.